@@ -535,16 +535,28 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
at24_get_pdata(dev, &chip);
}
+ if ((chip.flags & AT24_FLAG_SERIAL) && (chip.flags & AT24_FLAG_MAC)) {
+ dev_err(dev, "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC.");
+ return -EINVAL;
+ }
+
/* both flags imply read-only */
if (chip.flags & AT24_FLAG_SERIAL || chip.flags & AT24_FLAG_MAC)
chip.flags |= AT24_FLAG_READONLY;
- if (!chip.page_size) {
- dev_err(dev, "page_size must not be 0!\n");
- return -EINVAL;
+ writable = !(chip.flags & AT24_FLAG_READONLY);
+ if (writable) {
+ if (!chip.page_size) {
+ dev_err(dev, "page_size must not be 0!\n");
+ return -EINVAL;
+ }
+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) &&
+ !i2c_check_functionality(client->adapter,
+ I2C_FUNC_SMBUS_WRITE_I2C_BLOCK))
+ chip.page_size = 1;
+ if (!is_power_of_2(chip.page_size))
+ dev_warn(dev, "page_size looks suspicious (no power of 2)!\n");
}
- if (!is_power_of_2(chip.page_size))
- dev_warn(dev, "page_size looks suspicious (no power of 2)!\n");
/*
* REVISIT: the size of the EUI-48 byte array is 6 in at24mac402, while
@@ -556,11 +568,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
if (chip.flags & AT24_FLAG_MAC && chip.byte_len == 4)
chip.byte_len = 6;
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) &&
- !i2c_check_functionality(client->adapter,
- I2C_FUNC_SMBUS_WRITE_I2C_BLOCK))
- chip.page_size = 1;
-
if (chip.flags & AT24_FLAG_TAKE8ADDR)
num_addresses = 8;
else
@@ -587,12 +594,6 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
if (IS_ERR(at24->client[0].regmap))
return PTR_ERR(at24->client[0].regmap);
- if ((chip.flags & AT24_FLAG_SERIAL) && (chip.flags & AT24_FLAG_MAC)) {
- dev_err(dev, "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC.");
- return -EINVAL;
- }
-
- writable = !(chip.flags & AT24_FLAG_READONLY);
if (writable) {
at24->write_max = min_t(unsigned int, chip.page_size, io_limit);
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) &&
Currently we check for a proper page_size value also for read-only chips where this value isn't used. Therefore remove these checks for read-only chips. In addition reorder checks to do sanity checking first. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> --- drivers/misc/eeprom/at24.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-)