From: Marco Felsch <m.felsch@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
BAREBOX <barebox@lists.infradead.org>
Cc: Marco Felsch <m.felsch@pengutronix.de>
Subject: [PATCH v2 08/15] eeprom: at24: fix device name handling
Date: Mon, 18 Aug 2025 19:44:42 +0200 [thread overview]
Message-ID: <20250818-v2025-06-0-topic-nvmem-v2-8-b6d677f6c519@pengutronix.de> (raw)
In-Reply-To: <20250818-v2025-06-0-topic-nvmem-v2-0-b6d677f6c519@pengutronix.de>
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@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 ffd3376a156694a53c49ddd4f9a6669cccfac215..667d111b349d6941c757da3c6eb46ad7f2bb422e 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) {
@@ -423,16 +423,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);
@@ -487,6 +481,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);
@@ -503,7 +498,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
next prev parent reply other threads:[~2025-08-18 18:31 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-18 17:44 [PATCH v2 00/15] NVMEM: Add support for layout drivers Marco Felsch
2025-08-18 17:44 ` [PATCH v2 01/15] of: sync of_*_phandle_with_args with Linux Marco Felsch
2025-08-18 17:44 ` [PATCH v2 02/15] of: base: add of_parse_phandle_with_optional_args() Marco Felsch
2025-08-18 17:44 ` [PATCH v2 03/15] of: device: Export of_device_make_bus_id() Marco Felsch
2025-08-18 17:44 ` [PATCH v2 04/15] nvmem: core: fix nvmem_register error path Marco Felsch
2025-08-18 17:44 ` [PATCH v2 05/15] nvmem: core: sync with Linux Marco Felsch
2025-08-20 7:32 ` Sascha Hauer
2025-08-20 9:09 ` Marco Felsch
2025-08-18 17:44 ` [PATCH v2 06/15] nvmem: core: expose nvmem cells as cdev Marco Felsch
2025-08-20 7:33 ` Sascha Hauer
2025-08-20 9:09 ` Marco Felsch
2025-08-18 17:44 ` [PATCH v2 07/15] nvmem: core: allow single and dynamic device ids Marco Felsch
2025-08-20 7:47 ` Sascha Hauer
2025-08-20 9:13 ` Marco Felsch
2025-08-18 17:44 ` Marco Felsch [this message]
2025-08-18 17:44 ` [PATCH v2 09/15] nvmem: core: create a header for internal sharing Marco Felsch
2025-08-18 17:44 ` [PATCH v2 10/15] nvmem: core: add nvmem-layout support Marco Felsch
2025-08-19 12:46 ` Sascha Hauer
2025-08-19 14:39 ` Marco Felsch
2025-08-20 7:41 ` Sascha Hauer
2025-08-20 9:11 ` Marco Felsch
2025-08-20 9:40 ` Sascha Hauer
2025-08-20 9:55 ` Marco Felsch
2025-08-18 17:44 ` [PATCH v2 11/15] nvmem: core: add an index parameter to the cell Marco Felsch
2025-08-18 17:44 ` [PATCH v2 12/15] nvmem: core: add per-cell post processing Marco Felsch
2025-08-18 17:44 ` [PATCH v2 13/15] nvmem: core: add cell based fixup logic Marco Felsch
2025-08-18 17:44 ` [PATCH v2 14/15] nvmem: core: provide own priv pointer in post process callback Marco Felsch
2025-08-18 17:44 ` [PATCH v2 15/15] nvmem: core: drop global cell_post_process Marco Felsch
2025-08-19 7:23 ` [PATCH v2 00/15] NVMEM: Add support for layout drivers 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=20250818-v2025-06-0-topic-nvmem-v2-8-b6d677f6c519@pengutronix.de \
--to=m.felsch@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/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