mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] eeprom: at25: check return value of devfs_create
@ 2016-05-30  9:39 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
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2016-05-30  9:39 UTC (permalink / raw)
  To: barebox

Also only emit the message that the device was probed when it
actually was.

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

diff --git a/drivers/eeprom/at25.c b/drivers/eeprom/at25.c
index 9f054d00b459..f7f8368c4b45 100644
--- a/drivers/eeprom/at25.c
+++ b/drivers/eeprom/at25.c
@@ -354,8 +354,11 @@ static int at25_probe(struct device_d *dev)
 		goto fail;
 	}
 
+	err = devfs_create(&at25->cdev);
+	if (err)
+		goto fail;
+
 	dev_dbg(dev, "%s probed\n", at25->cdev.name);
-	devfs_create(&at25->cdev);
 	of_parse_partitions(&at25->cdev, dev->device_node);
 	return 0;
 
-- 
2.8.1


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] eeprom: at24: check return value of devfs_create and fix error path
  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 ` Uwe Kleine-König
  2016-05-30  9:39 ` [PATCH 3/3] eeprom: at24: make device name setup more robust Uwe Kleine-König
  2016-05-31  6:58 ` [PATCH 1/3] eeprom: at25: check return value of devfs_create Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2016-05-30  9:39 UTC (permalink / raw)
  To: barebox

if devfs_create failed because "eeprom0" already exists
of_parse_partitions must not be called, otherwise the already existing
eeprom gets assigned partitions that don't belog there.

Also free dummy clients in the error path and the write protect gpio
only if it is actually valid.

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

diff --git a/drivers/eeprom/at24.c b/drivers/eeprom/at24.c
index a323d25dd494..0f54d1b6de50 100644
--- a/drivers/eeprom/at24.c
+++ b/drivers/eeprom/at24.c
@@ -480,14 +480,21 @@ static int at24_probe(struct device_d *dev)
 		}
 	}
 
-	devfs_create(&at24->cdev);
+	err = devfs_create(&at24->cdev);
+	if (err)
+		goto err_devfs_create;
 
 	of_parse_partitions(&at24->cdev, dev->device_node);
 
 	return 0;
 
+err_devfs_create:
 err_clients:
-	gpio_free(at24->wp_gpio);
+	for (i = 1; i < num_addresses; i++)
+		kfree(at24->client[i]);
+
+	if (gpio_is_valid(at24->wp_gpio))
+		gpio_free(at24->wp_gpio);
 	kfree(at24->writebuf);
 	kfree(at24);
 err_out:
-- 
2.8.1


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] eeprom: at24: make device name setup more robust
  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
  2016-05-31  6:58 ` [PATCH 1/3] eeprom: at25: check return value of devfs_create Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Uwe Kleine-König @ 2016-05-30  9:39 UTC (permalink / raw)
  To: barebox

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] eeprom: at25: check return value of devfs_create
  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 ` [PATCH 3/3] eeprom: at24: make device name setup more robust Uwe Kleine-König
@ 2016-05-31  6:58 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2016-05-31  6:58 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: barebox

On Mon, May 30, 2016 at 11:39:51AM +0200, Uwe Kleine-König wrote:
> Also only emit the message that the device was probed when it
> actually was.
> 
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---

Applied, thanks

Sascha

>  drivers/eeprom/at25.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/eeprom/at25.c b/drivers/eeprom/at25.c
> index 9f054d00b459..f7f8368c4b45 100644
> --- a/drivers/eeprom/at25.c
> +++ b/drivers/eeprom/at25.c
> @@ -354,8 +354,11 @@ static int at25_probe(struct device_d *dev)
>  		goto fail;
>  	}
>  
> +	err = devfs_create(&at25->cdev);
> +	if (err)
> +		goto fail;
> +
>  	dev_dbg(dev, "%s probed\n", at25->cdev.name);
> -	devfs_create(&at25->cdev);
>  	of_parse_partitions(&at25->cdev, dev->device_node);
>  	return 0;
>  
> -- 
> 2.8.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-05-31  6:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 3/3] eeprom: at24: make device name setup more robust Uwe Kleine-König
2016-05-31  6:58 ` [PATCH 1/3] eeprom: at25: check return value of devfs_create Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox