mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/3] common: tlv: clean up device name setting
Date: Thu,  5 Jun 2025 13:25:31 +0200	[thread overview]
Message-ID: <20250605112533.1960069-1-a.fatoum@pengutronix.de> (raw)

Now that dev_set_name has a __printf attribute, we get a warning that we
are not using a string literal as format argument to it.

Fix this and while at it avoid a superfluous memory allocation.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/tlv/bus.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/common/tlv/bus.c b/common/tlv/bus.c
index 336415483622..0f11f2a9442b 100644
--- a/common/tlv/bus.c
+++ b/common/tlv/bus.c
@@ -19,7 +19,6 @@ struct tlv_device *tlv_register_device(struct tlv_header *header,
 {
 	struct tlv_device *tlvdev;
 	const char *name = NULL;
-	char *buf = NULL;
 	struct device *dev;
 	static int id = 0;
 
@@ -34,17 +33,19 @@ struct tlv_device *tlv_register_device(struct tlv_header *header,
 	dev->parent = parent ?: tlv_bus.dev;
 	dev->id = DEVICE_ID_SINGLE;
 
-	if (parent)
+	if (parent) {
 		name = of_alias_get(parent->device_node);
-	if (!name)
-		name = buf = basprintf("tlv%u", id++);
+		if (name)
+			dev_set_name(dev, "%s", name);
+	}
 
-	dev->device_node = of_new_node(of_new_node(NULL, NULL), name);
+	if (!name)
+		dev_set_name(dev, "tlv%u", id++);
+
+	dev->device_node = of_new_node(of_new_node(NULL, NULL), dev_name(dev));
 	dev->device_node->dev = dev;
-	dev_set_name(dev, name);
 	register_device(dev);
 
-	free(buf);
 	return tlvdev;
 }
 
-- 
2.39.5




             reply	other threads:[~2025-06-05 11:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-05 11:25 Ahmad Fatoum [this message]
2025-06-05 11:25 ` [PATCH 2/3] treewide: use only string literals as format string Ahmad Fatoum
2025-06-05 11:25 ` [PATCH 3/3] fastboot: switch to using error format specifiers Ahmad Fatoum
2025-06-05 11:55 ` [PATCH 1/3] common: tlv: clean up device name setting 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=20250605112533.1960069-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --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