[PATCH 1/3] common: tlv: clean up device name setting
Ahmad Fatoum
a.fatoum at pengutronix.de
Thu Jun 5 04:25:31 PDT 2025
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 at 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
More information about the barebox
mailing list