mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/3] eeprom: at24: make device name setup more robust
Date: Mon, 30 May 2016 11:39:53 +0200	[thread overview]
Message-ID: <1464601193-20832-3-git-send-email-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <1464601193-20832-1-git-send-email-u.kleine-koenig@pengutronix.de>

With two eeproms that have a different compatible string (in my case
"at,24c64" and "at,24c32") dev->id is 0 for both which results in a
failure to bind the device that is probed later.

So pick a name more intelligently: If there is an alias defined in the
device tree, use this one, otherwise pick a free index.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 drivers/eeprom/at24.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/drivers/eeprom/at24.c b/drivers/eeprom/at24.c
index 0f54d1b6de50..49eef6a8ed4a 100644
--- a/drivers/eeprom/at24.c
+++ b/drivers/eeprom/at24.c
@@ -379,6 +379,7 @@ static int at24_probe(struct device_d *dev)
 	struct at24_data *at24;
 	int err;
 	unsigned i, num_addresses;
+	char *devname;
 
 	if (dev->platform_data) {
 		chip = *(struct at24_platform_data *)dev->platform_data;
@@ -429,7 +430,23 @@ static int at24_probe(struct device_d *dev)
 
 	at24->chip = chip;
 	at24->num_addresses = num_addresses;
-	at24->cdev.name = basprintf("eeprom%d", dev->id);
+
+	devname = of_alias_get(dev->device_node);
+	if (!devname) {
+		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 = basprintf("eeprom%d", err);
+		if (!devname) {
+			err = -ENOMEM;
+			dev_err(&client->dev, "failed to allocate space for device name\n");
+			goto err_device_name;
+		}
+	}
+
+	at24->cdev.name = devname;
 	at24->cdev.priv = at24;
 	at24->cdev.dev = dev;
 	at24->cdev.ops = &at24->fops;
@@ -496,6 +513,7 @@ err_clients:
 	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.8.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-05-30  9:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-30  9:39 [PATCH 1/3] eeprom: at25: check return value of devfs_create Uwe Kleine-König
2016-05-30  9:39 ` [PATCH 2/3] eeprom: at24: check return value of devfs_create and fix error path Uwe Kleine-König
2016-05-30  9:39 ` Uwe Kleine-König [this message]
2016-05-31  6:58 ` [PATCH 1/3] eeprom: at25: check return value of devfs_create 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=1464601193-20832-3-git-send-email-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@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