[PATCH 3/3] eeprom: at24: make device name setup more robust

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox




[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux