Skip to content

Commit e730862

Browse files
committed
eeprom: at24: use devm_i2c_new_dummy_device()
Now that it's upstream, use the resource managed version of i2c_new_dummy_device(). Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Wolfram Sang <[email protected]>
1 parent a188339 commit e730862

File tree

1 file changed

+9
-29
lines changed

1 file changed

+9
-29
lines changed

drivers/misc/eeprom/at24.c

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -507,14 +507,6 @@ static const struct at24_chip_data *at24_get_chip_data(struct device *dev)
507507
return cdata;
508508
}
509509

510-
static void at24_remove_dummy_clients(struct at24_data *at24)
511-
{
512-
int i;
513-
514-
for (i = 1; i < at24->num_addresses; i++)
515-
i2c_unregister_device(at24->client[i].client);
516-
}
517-
518510
static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
519511
struct regmap_config *regmap_config)
520512
{
@@ -527,18 +519,14 @@ static int at24_make_dummy_client(struct at24_data *at24, unsigned int index,
527519
dev = &base_client->dev;
528520
addr = base_client->addr + index;
529521

530-
dummy_client = i2c_new_dummy(base_client->adapter,
531-
base_client->addr + index);
532-
if (!dummy_client) {
533-
dev_err(dev, "address 0x%02x unavailable\n", addr);
534-
return -EADDRINUSE;
535-
}
522+
dummy_client = devm_i2c_new_dummy_device(dev, base_client->adapter,
523+
base_client->addr + index);
524+
if (IS_ERR(dummy_client))
525+
return PTR_ERR(dummy_client);
536526

537527
regmap = devm_regmap_init_i2c(dummy_client, regmap_config);
538-
if (IS_ERR(regmap)) {
539-
i2c_unregister_device(dummy_client);
528+
if (IS_ERR(regmap))
540529
return PTR_ERR(regmap);
541-
}
542530

543531
at24->client[index].client = dummy_client;
544532
at24->client[index].regmap = regmap;
@@ -693,10 +681,8 @@ static int at24_probe(struct i2c_client *client)
693681
/* use dummy devices for multiple-address chips */
694682
for (i = 1; i < num_addresses; i++) {
695683
err = at24_make_dummy_client(at24, i, &regmap_config);
696-
if (err) {
697-
at24_remove_dummy_clients(at24);
684+
if (err)
698685
return err;
699-
}
700686
}
701687

702688
i2c_set_clientdata(client, at24);
@@ -713,7 +699,7 @@ static int at24_probe(struct i2c_client *client)
713699
pm_runtime_idle(dev);
714700
if (err) {
715701
err = -ENODEV;
716-
goto err_clients;
702+
goto err_runtime_pm;
717703
}
718704

719705
nvmem_config.name = dev_name(dev);
@@ -733,7 +719,7 @@ static int at24_probe(struct i2c_client *client)
733719
at24->nvmem = devm_nvmem_register(dev, &nvmem_config);
734720
if (IS_ERR(at24->nvmem)) {
735721
err = PTR_ERR(at24->nvmem);
736-
goto err_clients;
722+
goto err_runtime_pm;
737723
}
738724

739725
dev_info(dev, "%u byte %s EEPROM, %s, %u bytes/write\n",
@@ -742,20 +728,14 @@ static int at24_probe(struct i2c_client *client)
742728

743729
return 0;
744730

745-
err_clients:
746-
at24_remove_dummy_clients(at24);
731+
err_runtime_pm:
747732
pm_runtime_disable(dev);
748733

749734
return err;
750735
}
751736

752737
static int at24_remove(struct i2c_client *client)
753738
{
754-
struct at24_data *at24;
755-
756-
at24 = i2c_get_clientdata(client);
757-
758-
at24_remove_dummy_clients(at24);
759739
pm_runtime_disable(&client->dev);
760740
pm_runtime_set_suspended(&client->dev);
761741

0 commit comments

Comments
 (0)