mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] common: tlv: clean up device name setting
@ 2025-06-05 11:25 Ahmad Fatoum
  2025-06-05 11:25 ` [PATCH 2/3] treewide: use only string literals as format string Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2025-06-05 11:25 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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




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

end of thread, other threads:[~2025-06-05 11:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-05 11:25 [PATCH 1/3] common: tlv: clean up device name setting Ahmad Fatoum
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

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