From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 3/4] driver: fix device name clashes
Date: Mon, 08 Dec 2025 13:00:53 +0100 [thread overview]
Message-ID: <20251208-nvmem-eeprom-v1-3-41ba588e2f3a@pengutronix.de> (raw)
In-Reply-To: <20251208-nvmem-eeprom-v1-0-41ba588e2f3a@pengutronix.de>
It can happen that we end up with two devices having the same name.
This happens when one device is registered with
dev->name "foo0";
dev->id = DEVICE_ID_SINGLE;
and another one with
dev->name "foo";
dev->id = 0;
Fix this by not comparing both dev->name and dev->id when testing if a
device already exists, but instead by comparing the resulting device
name.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/base/driver.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 1a5a3598be5d4b2c6ce8558b1ac8c3cba4d59485..c417e945ee0308028fc885101de18bd4a2adfe93 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -86,13 +86,18 @@ struct device *get_device_by_name(const char *name)
static struct device *get_device_by_name_id(const char *name, int id)
{
struct device *dev;
+ char *str = NULL;
- for_each_device(dev) {
- if(!strcmp(dev->name, name) && id == dev->id)
- return dev;
- }
+ if (id == DEVICE_ID_SINGLE)
+ return get_device_by_name(name);
- return NULL;
+ str = basprintf("%s%u", name, id);
+
+ dev = get_device_by_name(str);
+
+ free(str);
+
+ return dev;
}
int get_free_deviceid_from(const char *name_template, int id_from)
--
2.47.3
next prev parent reply other threads:[~2025-12-08 12:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-08 12:00 [PATCH 0/4] driver name fixes Sascha Hauer
2025-12-08 12:00 ` [PATCH 1/4] driver: implement get_free_deviceid_from() Sascha Hauer
2025-12-08 12:00 ` [PATCH 2/4] nvmem: fix device name setting Sascha Hauer
2025-12-08 12:00 ` Sascha Hauer [this message]
2025-12-08 12:00 ` [PATCH 4/4] eeprom: at24: reserve EEPROM names which have an alias Sascha Hauer
2025-12-10 7:09 ` [PATCH 0/4] driver name fixes 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=20251208-nvmem-eeprom-v1-3-41ba588e2f3a@pengutronix.de \
--to=s.hauer@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