eeprom: at24: make device name setup more robust
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> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
3982f4ad8a
commit
17f77702e5
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue