From: Marco Felsch <m.felsch@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 5/5] eeprom: at24: fix device name handling
Date: Fri, 22 Mar 2024 17:45:59 +0100 [thread overview]
Message-ID: <20240322164559.1768983-5-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20240322164559.1768983-1-m.felsch@pengutronix.de>
The at24 driver does not need to handle the ids by its own since the
nvmem_core does the handling too. This lead into issues where the eeprom
device is named: eeprom00.
Fix the alias handling too since the devie would never be named as
described in the alias, since we never told the nvmem-core to not add an
additional id.
Furthermore the devname can be static since the name gets later
allocated by the dev_set_name().
Fix these three issues by just using the alias or the static "eeprom"
sting and supply the correct NVMEM_DEVID_NONE or NVMEM_DEVID_AUTO to the
core.
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 23cb0e1fbbc9..a5079279af35 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.2
prev parent reply other threads:[~2024-03-22 16:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-22 16:45 [PATCH 1/5] nvmem: sync with linux code base Marco Felsch
2024-03-22 16:45 ` [PATCH 2/5] nvmem: expose nvmem cells as cdev Marco Felsch
2024-03-25 9:49 ` Sascha Hauer
2024-03-25 10:59 ` Marco Felsch
2024-03-22 16:45 ` [PATCH 3/5] nvmem: constify the write path Marco Felsch
2024-03-25 9:51 ` Sascha Hauer
2024-03-25 10:33 ` Marco Felsch
2024-03-22 16:45 ` [PATCH 4/5] nvmem: allow single and dynamic device ids Marco Felsch
2024-03-22 16:45 ` Marco Felsch [this message]
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=20240322164559.1768983-5-m.felsch@pengutronix.de \
--to=m.felsch@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