From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 4/4] eeprom: at24: reserve EEPROM names which have an alias
Date: Mon, 08 Dec 2025 13:00:54 +0100 [thread overview]
Message-ID: <20251208-nvmem-eeprom-v1-4-41ba588e2f3a@pengutronix.de> (raw)
In-Reply-To: <20251208-nvmem-eeprom-v1-0-41ba588e2f3a@pengutronix.de>
An EEPROM which doesn't have an alias will be registered as "eeprom0".
When another EEPROM is probed which has "eeprom0" as alias it will fail
to probe due to -EEXIST. Use of_alias_get_highest_id() to reserve
namespace for EEPROMs with aliases.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/eeprom/at24.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/eeprom/at24.c b/drivers/eeprom/at24.c
index 667d111b349d6941c757da3c6eb46ad7f2bb422e..5dc19800970093fa8c95f36d58d47d8c1db6dcdc 100644
--- a/drivers/eeprom/at24.c
+++ b/drivers/eeprom/at24.c
@@ -369,7 +369,7 @@ static int at24_probe(struct device *dev)
struct at24_platform_data chip;
bool writable;
struct at24_data *at24;
- int err;
+ int devid, err;
unsigned i, num_addresses;
const char *devname;
const char *alias;
@@ -423,10 +423,14 @@ static int at24_probe(struct device *dev)
at24->num_addresses = num_addresses;
alias = of_alias_get(dev->of_node);
- if (alias)
+ if (alias) {
devname = alias;
- else
+ devid = NVMEM_DEVID_NONE;
+ } else {
devname = "eeprom";
+ devid = get_free_deviceid_from(devname,
+ of_alias_get_highest_id(devname) + 1);
+ }
writable = !(chip.flags & AT24_FLAG_READONLY);
@@ -481,7 +485,7 @@ static int at24_probe(struct device *dev)
at24->nvmem_config.stride = 1;
at24->nvmem_config.word_size = 1;
at24->nvmem_config.size = chip.byte_len;
- at24->nvmem_config.id = alias ? NVMEM_DEVID_NONE : NVMEM_DEVID_AUTO;
+ at24->nvmem_config.id = devid;
at24->nvmem = nvmem_register(&at24->nvmem_config);
err = PTR_ERR_OR_ZERO(at24->nvmem);
--
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 ` [PATCH 3/4] driver: fix device name clashes Sascha Hauer
2025-12-08 12:00 ` Sascha Hauer [this message]
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-4-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