[PATCH 08/15] eeprom: at24: fix device name handling
Marco Felsch
m.felsch at pengutronix.de
Mon Aug 4 07:36:54 PDT 2025
The nvmem_core already handles the ids/numbering, there is no need for
the driver to do it too. Furthermore it's wrong because the final device
would be: eeprom00 instead of eeprom0.
While on it fix the alias name handlng too since the device is never
named as described by the alias, but 'alias<ID>'. Since the
nvmem_core supports NVMEM_DEVID_{NONE,AUTO}, pass this information to
the core so the name would be: 'alias'.
Also while on it, make devname a 'const char *' pointer since the name is
allocated later on by the dev_set_name() during the nvmem_register()
call.
Signed-off-by: Marco Felsch <m.felsch at pengutronix.de>
---
drivers/eeprom/at24.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/drivers/eeprom/at24.c b/drivers/eeprom/at24.c
index 3054709ec055665a82b22c1b210a2bfc0910ca94..0a9aa75cf1dd63f6f97e90509b76e25d04ec361d 100644
--- a/drivers/eeprom/at24.c
+++ b/drivers/eeprom/at24.c
@@ -371,7 +371,7 @@ static int at24_probe(struct device *dev)
struct at24_data *at24;
int err;
unsigned i, num_addresses;
- char *devname;
+ const char *devname;
const char *alias;
if (dev->platform_data) {
@@ -425,16 +425,10 @@ static int at24_probe(struct device *dev)
at24->num_addresses = num_addresses;
alias = of_alias_get(dev->of_node);
- if (alias) {
- devname = xstrdup(alias);
- } else {
- err = cdev_find_free_index("eeprom");
- if (err < 0) {
- dev_err(&client->dev, "no index found to name device\n");
- goto err_device_name;
- }
- devname = xasprintf("eeprom%d", err);
- }
+ if (alias)
+ devname = alias;
+ else
+ devname = "eeprom";
writable = !(chip.flags & AT24_FLAG_READONLY);
@@ -489,6 +483,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 = nvmem_register(&at24->nvmem_config);
err = PTR_ERR_OR_ZERO(at24->nvmem);
@@ -505,7 +500,6 @@ static int at24_probe(struct device *dev)
if (gpio_is_valid(at24->wp_gpio))
gpio_free(at24->wp_gpio);
kfree(at24->writebuf);
-err_device_name:
kfree(at24);
err_out:
dev_dbg(&client->dev, "probe error %d\n", err);
--
2.39.5
More information about the barebox
mailing list