From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
To: Wolfram Sang <wsa@the-dreams.de>,
linux-i2c <linux-i2c@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Cc: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Subject: [PATCH] eeprom: at24: check if the chip is functional in probe()
Date: Wed, 10 Aug 2016 15:54:17 +0200 [thread overview]
Message-ID: <1470837257-15521-1-git-send-email-bgolaszewski@baylibre.com> (raw)
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.
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;
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);
+ if (err) {
+ dev_err(&client->dev,
+ "error reading the test byte from EEPROM: %d\n", err);
+ nvmem_unregister(at24->nvmem);
+ err = -ENODEV;
+ goto err_clients;
+ }
+
return 0;
err_clients:
--
2.7.4
next reply other threads:[~2016-08-10 13:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-10 13:54 Bartosz Golaszewski [this message]
2016-08-10 14:07 ` [PATCH] eeprom: at24: check if the chip is functional in probe() Wolfram Sang
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=1470837257-15521-1-git-send-email-bgolaszewski@baylibre.com \
--to=bgolaszewski@baylibre.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=wsa@the-dreams.de \
/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).