summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartosz Golaszewski <brgl@bgdev.pl>2018-03-19 10:17:21 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-03-23 16:25:45 +0100
commit34d43faf3aa80f72617da5f2d460262c1e0bbf48 (patch)
treeed62207be4b50e495cfb00976332389608cf453d
parentdf3da615e3f020d4b689eb23d33d10f285db2fb6 (diff)
downloadlinux-34d43faf3aa80f72617da5f2d460262c1e0bbf48.tar.gz
linux-34d43faf3aa80f72617da5f2d460262c1e0bbf48.tar.bz2
linux-34d43faf3aa80f72617da5f2d460262c1e0bbf48.zip
eeprom: at24: simplify the i2c functionality checking
Save one call and make code prettier by checking the i2c functionality in the beginning of at24_probe(), saving the relevant values and reusing them later. Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl> Tested-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/misc/eeprom/at24.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index ef937390af13..49b7831c238a 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -564,6 +564,7 @@ static int at24_probe(struct i2c_client *client)
struct nvmem_config nvmem_config = { };
struct at24_platform_data pdata = { };
struct device *dev = &client->dev;
+ bool i2c_fn_i2c, i2c_fn_block;
unsigned int i, num_addresses;
struct at24_data *at24;
struct regmap *regmap;
@@ -572,13 +573,15 @@ static int at24_probe(struct i2c_client *client)
u8 test_byte;
int err;
+ i2c_fn_i2c = i2c_check_functionality(client->adapter, I2C_FUNC_I2C);
+ i2c_fn_block = i2c_check_functionality(client->adapter,
+ I2C_FUNC_SMBUS_WRITE_I2C_BLOCK);
+
err = at24_get_pdata(dev, &pdata);
if (err)
return err;
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) &&
- !i2c_check_functionality(client->adapter,
- I2C_FUNC_SMBUS_WRITE_I2C_BLOCK))
+ if (!i2c_fn_i2c && !i2c_fn_block)
pdata.page_size = 1;
if (!pdata.page_size) {
@@ -631,8 +634,7 @@ static int at24_probe(struct i2c_client *client)
if (writable) {
at24->write_max = min_t(unsigned int,
pdata.page_size, at24_io_limit);
- if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) &&
- at24->write_max > I2C_SMBUS_BLOCK_MAX)
+ if (!i2c_fn_i2c && at24->write_max > I2C_SMBUS_BLOCK_MAX)
at24->write_max = I2C_SMBUS_BLOCK_MAX;
}