提交 021c7d7b 编写于 作者: B Bartosz Golaszewski 提交者: Greg Kroah-Hartman

eeprom: at24: use a helper variable for dev

We use the &client->dev construct all over in at24_probe(). Use
a helper variable which is more readable and allows to avoid a couple
unnecessary line breaks.
Signed-off-by: NBartosz Golaszewski <brgl@bgdev.pl>
Tested-by: NAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 f2adff66
...@@ -520,29 +520,29 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -520,29 +520,29 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
struct nvmem_config nvmem_config = { }; struct nvmem_config nvmem_config = { };
const struct at24_chip_data *cd = NULL; const struct at24_chip_data *cd = NULL;
struct at24_platform_data pdata = { }; struct at24_platform_data pdata = { };
struct device *dev = &client->dev;
unsigned int i, num_addresses; unsigned int i, num_addresses;
struct at24_data *at24; struct at24_data *at24;
bool writable; bool writable;
u8 test_byte; u8 test_byte;
int err; int err;
if (client->dev.platform_data) { if (dev->platform_data) {
pdata = *(struct at24_platform_data *)client->dev.platform_data; pdata = *(struct at24_platform_data *)dev->platform_data;
} else { } else {
/* /*
* The I2C core allows OF nodes compatibles to match against the * The I2C core allows OF nodes compatibles to match against the
* I2C device ID table as a fallback, so check not only if an OF * I2C device ID table as a fallback, so check not only if an OF
* node is present but also if it matches an OF device ID entry. * node is present but also if it matches an OF device ID entry.
*/ */
if (client->dev.of_node && if (dev->of_node && of_match_device(at24_of_match, dev)) {
of_match_device(at24_of_match, &client->dev)) { cd = of_device_get_match_data(dev);
cd = of_device_get_match_data(&client->dev);
} else if (id) { } else if (id) {
cd = (void *)id->driver_data; cd = (void *)id->driver_data;
} else { } else {
const struct acpi_device_id *aid; const struct acpi_device_id *aid;
aid = acpi_match_device(at24_acpi_ids, &client->dev); aid = acpi_match_device(at24_acpi_ids, dev);
if (aid) if (aid)
cd = (void *)aid->driver_data; cd = (void *)aid->driver_data;
} }
...@@ -551,16 +551,15 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -551,16 +551,15 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
pdata.byte_len = cd->byte_len; pdata.byte_len = cd->byte_len;
pdata.flags = cd->flags; pdata.flags = cd->flags;
at24_properties_to_pdata(&client->dev, &pdata); at24_properties_to_pdata(dev, &pdata);
} }
if (!pdata.page_size) { if (!pdata.page_size) {
dev_err(&client->dev, "page_size must not be 0!\n"); dev_err(dev, "page_size must not be 0!\n");
return -EINVAL; return -EINVAL;
} }
if (!is_power_of_2(pdata.page_size)) if (!is_power_of_2(pdata.page_size))
dev_warn(&client->dev, dev_warn(dev, "page_size looks suspicious (no power of 2)!\n");
"page_size looks suspicious (no power of 2)!\n");
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) && if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) &&
!i2c_check_functionality(client->adapter, !i2c_check_functionality(client->adapter,
...@@ -577,8 +576,8 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -577,8 +576,8 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
regmap_config.reg_bits = (pdata.flags & AT24_FLAG_ADDR16) ? 16 : 8; regmap_config.reg_bits = (pdata.flags & AT24_FLAG_ADDR16) ? 16 : 8;
regmap_config.disable_locking = true; regmap_config.disable_locking = true;
at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) + at24 = devm_kzalloc(dev, sizeof(struct at24_data) + num_addresses *
num_addresses * sizeof(struct at24_client), GFP_KERNEL); sizeof(struct at24_client), GFP_KERNEL);
if (!at24) if (!at24)
return -ENOMEM; return -ENOMEM;
...@@ -587,8 +586,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -587,8 +586,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
at24->num_addresses = num_addresses; at24->num_addresses = num_addresses;
at24->offset_adj = at24_get_offset_adj(pdata.flags, pdata.byte_len); at24->offset_adj = at24_get_offset_adj(pdata.flags, pdata.byte_len);
at24->wp_gpio = devm_gpiod_get_optional(&client->dev, at24->wp_gpio = devm_gpiod_get_optional(dev, "wp", GPIOD_OUT_HIGH);
"wp", GPIOD_OUT_HIGH);
if (IS_ERR(at24->wp_gpio)) if (IS_ERR(at24->wp_gpio))
return PTR_ERR(at24->wp_gpio); return PTR_ERR(at24->wp_gpio);
...@@ -598,7 +596,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -598,7 +596,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
return PTR_ERR(at24->client[0].regmap); return PTR_ERR(at24->client[0].regmap);
if ((pdata.flags & AT24_FLAG_SERIAL) && (pdata.flags & AT24_FLAG_MAC)) { if ((pdata.flags & AT24_FLAG_SERIAL) && (pdata.flags & AT24_FLAG_MAC)) {
dev_err(&client->dev, dev_err(dev,
"invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC."); "invalid device data - cannot have both AT24_FLAG_SERIAL & AT24_FLAG_MAC.");
return -EINVAL; return -EINVAL;
} }
...@@ -617,7 +615,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -617,7 +615,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
at24->client[i].client = i2c_new_dummy(client->adapter, at24->client[i].client = i2c_new_dummy(client->adapter,
client->addr + i); client->addr + i);
if (!at24->client[i].client) { if (!at24->client[i].client) {
dev_err(&client->dev, "address 0x%02x unavailable\n", dev_err(dev, "address 0x%02x unavailable\n",
client->addr + i); client->addr + i);
err = -EADDRINUSE; err = -EADDRINUSE;
goto err_clients; goto err_clients;
...@@ -634,27 +632,27 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -634,27 +632,27 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
i2c_set_clientdata(client, at24); i2c_set_clientdata(client, at24);
/* enable runtime pm */ /* enable runtime pm */
pm_runtime_set_active(&client->dev); pm_runtime_set_active(dev);
pm_runtime_enable(&client->dev); pm_runtime_enable(dev);
/* /*
* Perform a one-byte test read to verify that the * Perform a one-byte test read to verify that the
* chip is functional. * chip is functional.
*/ */
err = at24_read(at24, 0, &test_byte, 1); err = at24_read(at24, 0, &test_byte, 1);
pm_runtime_idle(&client->dev); pm_runtime_idle(dev);
if (err) { if (err) {
err = -ENODEV; err = -ENODEV;
goto err_clients; goto err_clients;
} }
nvmem_config.name = dev_name(&client->dev); nvmem_config.name = dev_name(dev);
nvmem_config.dev = &client->dev; nvmem_config.dev = dev;
nvmem_config.read_only = !writable; nvmem_config.read_only = !writable;
nvmem_config.root_only = true; nvmem_config.root_only = true;
nvmem_config.owner = THIS_MODULE; nvmem_config.owner = THIS_MODULE;
nvmem_config.compat = true; nvmem_config.compat = true;
nvmem_config.base_dev = &client->dev; nvmem_config.base_dev = dev;
nvmem_config.reg_read = at24_read; nvmem_config.reg_read = at24_read;
nvmem_config.reg_write = at24_write; nvmem_config.reg_write = at24_write;
nvmem_config.priv = at24; nvmem_config.priv = at24;
...@@ -669,7 +667,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -669,7 +667,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
goto err_clients; goto err_clients;
} }
dev_info(&client->dev, "%u byte %s EEPROM, %s, %u bytes/write\n", dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/write\n",
pdata.byte_len, client->name, pdata.byte_len, client->name,
writable ? "writable" : "read-only", at24->write_max); writable ? "writable" : "read-only", at24->write_max);
...@@ -684,7 +682,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -684,7 +682,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
if (at24->client[i].client) if (at24->client[i].client)
i2c_unregister_device(at24->client[i].client); i2c_unregister_device(at24->client[i].client);
pm_runtime_disable(&client->dev); pm_runtime_disable(dev);
return err; return err;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册