[PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected

Ahmad Fatoum ahmad at a3f.at
Mon Jan 9 00:35:58 PST 2023


For drivers that create new virtual child devices, error paths often
tend to use dev_name() on the uninitialized device via the dev_ family
of logging functions. Many such uninitialized devices have a name set
already though, but just lacks registration, which leads to dev_id
returning dev->unique_name, which may be NULL. Change dev_name to
return dev->name if dev->unique_name is NULL.

Signed-off-by: Ahmad Fatoum <ahmad at a3f.at>
---
 include/driver.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/include/driver.h b/include/driver.h
index 693d5cb3e580..4d500ed21e34 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -191,7 +191,9 @@ static inline const char *dev_id(const struct device *dev)
 
 static inline const char *dev_name(const struct device *dev)
 {
-	return dev_id(dev);
+	if (!dev)
+		return NULL;
+	return dev_id(dev) ?: dev->name;
 }
 
 int dev_set_name(struct device *dev, const char *fmt, ...);
-- 
2.38.1




More information about the barebox mailing list