[PATCH 4/4] eeprom: at24: reserve EEPROM names which have an alias

Sascha Hauer s.hauer at pengutronix.de
Mon Dec 8 04:00:54 PST 2025


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 at 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




More information about the barebox mailing list