Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

eeprom: at24: check if the chip is functional in probe()

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>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>

authored by

Bartosz Golaszewski and committed by
Wolfram Sang
00f0ea70 56025e7b

+13 -2
+13 -2
drivers/misc/eeprom/at24.c
··· 593 593 struct at24_data *at24; 594 594 int err; 595 595 unsigned i, num_addresses; 596 + u8 test_byte; 596 597 597 598 if (client->dev.platform_data) { 598 599 chip = *(struct at24_platform_data *)client->dev.platform_data; ··· 744 743 } 745 744 } 746 745 746 + i2c_set_clientdata(client, at24); 747 + 748 + /* 749 + * Perform a one-byte test read to verify that the 750 + * chip is functional. 751 + */ 752 + err = at24_read(at24, 0, &test_byte, 1); 753 + if (err) { 754 + err = -ENODEV; 755 + goto err_clients; 756 + } 757 + 747 758 at24->nvmem_config.name = dev_name(&client->dev); 748 759 at24->nvmem_config.dev = &client->dev; 749 760 at24->nvmem_config.read_only = !writable; ··· 776 763 err = PTR_ERR(at24->nvmem); 777 764 goto err_clients; 778 765 } 779 - 780 - i2c_set_clientdata(client, at24); 781 766 782 767 dev_info(&client->dev, "%u byte %s EEPROM, %s, %u bytes/write\n", 783 768 chip.byte_len, client->name,