linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Wolfram Sang <wsa@the-dreams.de>
To: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Cc: linux-i2c <linux-i2c@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] eeprom: at24: check if the chip is functional in probe()
Date: Wed, 10 Aug 2016 16:07:15 +0200	[thread overview]
Message-ID: <20160810140715.GB1607@katana> (raw)
In-Reply-To: <1470837257-15521-1-git-send-email-bgolaszewski@baylibre.com>

[-- Attachment #1: Type: text/plain, Size: 1945 bytes --]

On Wed, Aug 10, 2016 at 03:54:17PM +0200, Bartosz Golaszewski wrote:
> The at24 driver doesn't check if the chip is functional in its probe
> function. This leads to instantiating devices that are not physically
> present. For example the cape EEPROMs for BeagleBone Black are defined
> in the device tree at four addresses on i2c2, but normally only one of
> them is present.
> 
> If the userspace doesn't know the location in advance, it will need to
> check if reading the nvmem attributes fails to determine which EEPROM
> is actually there.
> 
> Try to read a single byte in probe() and bail-out with -ENODEV if the
> read fails.

That's basically OK...

> 
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
>  drivers/misc/eeprom/at24.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> index 3cdf8e1..ed1e4eb 100644
> --- a/drivers/misc/eeprom/at24.c
> +++ b/drivers/misc/eeprom/at24.c
> @@ -593,6 +593,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>  	struct at24_data *at24;
>  	int err;
>  	unsigned i, num_addresses;
> +	char c;

u8?

>  
>  	if (client->dev.platform_data) {
>  		chip = *(struct at24_platform_data *)client->dev.platform_data;
> @@ -780,6 +781,15 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>  	if (chip.setup)
>  		chip.setup(at24->nvmem, chip.context);
>  
> +	err = at24_read(at24, 0, &c, 1);

Can't we do this before registering dummy clients and nvmem registration?

> +	if (err) {
> +		dev_err(&client->dev,
> +			"error reading the test byte from EEPROM: %d\n", err);

I don't think we should print an error in case of ENODEV.

> +		nvmem_unregister(at24->nvmem);
> +		err = -ENODEV;
> +		goto err_clients;
> +	}
> +
>  	return 0;
>  
>  err_clients:
> -- 
> 2.7.4
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

  reply	other threads:[~2016-08-10 14:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-10 13:54 [PATCH] eeprom: at24: check if the chip is functional in probe() Bartosz Golaszewski
2016-08-10 14:07 ` Wolfram Sang [this message]
2016-08-11 15:09   ` Bartosz Golaszewski
2016-08-11 15:55     ` Wolfram Sang

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=20160810140715.GB1607@katana \
    --to=wsa@the-dreams.de \
    --cc=bgolaszewski@baylibre.com \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).