mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected
@ 2023-01-09  8:35 Ahmad Fatoum
  2023-01-09  8:35 ` [PATCH master 2/3] efi: acpi: add SDT resource before registering device Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2023-01-09  8:35 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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@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




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-09  9:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-09  8:35 [PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected Ahmad Fatoum
2023-01-09  8:35 ` [PATCH master 2/3] efi: acpi: add SDT resource before registering device Ahmad Fatoum
2023-01-09  8:36 ` [PATCH master 3/3] reset: core: support deep probe with resets registered in CLK_OF_DECLARE Ahmad Fatoum
2023-01-09  9:12 ` [PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox