mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <ahmad@a3f.at>
Subject: [PATCH master 1/3] driver: have dev_name(unregistered device) behave as expected
Date: Mon,  9 Jan 2023 09:35:58 +0100	[thread overview]
Message-ID: <20230109083600.1820078-1-ahmad@a3f.at> (raw)

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




             reply	other threads:[~2023-01-09  8:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-09  8:35 Ahmad Fatoum [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230109083600.1820078-1-ahmad@a3f.at \
    --to=ahmad@a3f.at \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox