Skip to content

Commit f6c64c6

Browse files
Milo(Woogyom) Kimcooloney
Milo(Woogyom) Kim
authored andcommitted
leds-lp55xx: do chip specific configuration on device init
Chip specific function is configured when the device is initialized. So _configure() is moved to each device init function. If chip configuration gets failed, the device is de-initialized in each _init_device(), not probe(). For compile error fix, function type declarations are added. Signed-off-by: Milo(Woogyom) Kim <[email protected]> Signed-off-by: Bryan Wu <[email protected]>
1 parent 86eb774 commit f6c64c6

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

drivers/leds/leds-lp5521.c

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ static void lp5521_reset_device(struct lp5521_chip *chip)
694694
lp5521_write(client, LP5521_REG_RESET, 0xff);
695695
}
696696

697+
static void lp5521_deinit_device(struct lp5521_chip *chip);
697698
static int lp5521_init_device(struct lp5521_chip *chip)
698699
{
699700
struct lp5521_platform_data *pdata = chip->pdata;
@@ -742,9 +743,22 @@ static int lp5521_init_device(struct lp5521_chip *chip)
742743
usleep_range(10000, 20000);
743744

744745
ret = lp5521_detect(client);
745-
if (ret)
746+
if (ret) {
746747
dev_err(&client->dev, "Chip not found\n");
748+
goto err;
749+
}
750+
751+
ret = lp5521_configure(client);
752+
if (ret < 0) {
753+
dev_err(&client->dev, "error configuring chip\n");
754+
goto err_config;
755+
}
747756

757+
return 0;
758+
759+
err_config:
760+
lp5521_deinit_device(chip);
761+
err:
748762
return ret;
749763
}
750764

@@ -882,16 +896,10 @@ static int lp5521_probe(struct i2c_client *client,
882896

883897
ret = lp5521_init_device(chip);
884898
if (ret)
885-
goto fail1;
899+
goto err_init;
886900

887901
dev_info(&client->dev, "%s programmable led chip found\n", id->name);
888902

889-
ret = lp5521_configure(client);
890-
if (ret < 0) {
891-
dev_err(&client->dev, "error configuring chip\n");
892-
goto fail1;
893-
}
894-
895903
ret = lp5521_register_leds(chip);
896904
if (ret)
897905
goto fail2;
@@ -904,8 +912,8 @@ static int lp5521_probe(struct i2c_client *client,
904912
return ret;
905913
fail2:
906914
lp5521_unregister_leds(chip);
907-
fail1:
908915
lp5521_deinit_device(chip);
916+
err_init:
909917
return ret;
910918
}
911919

drivers/leds/leds-lp5523.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ static void lp5523_reset_device(struct lp5523_chip *chip)
953953
lp5523_write(client, LP5523_REG_RESET, 0xff);
954954
}
955955

956+
static void lp5523_deinit_device(struct lp5523_chip *chip);
956957
static int lp5523_init_device(struct lp5523_chip *chip)
957958
{
958959
struct lp5523_platform_data *pdata = chip->pdata;
@@ -978,7 +979,22 @@ static int lp5523_init_device(struct lp5523_chip *chip)
978979
* Exact value is not available. 10 - 20ms
979980
* appears to be enough for reset.
980981
*/
981-
return lp5523_detect(client);
982+
ret = lp5523_detect(client);
983+
if (ret)
984+
goto err;
985+
986+
ret = lp5523_configure(client);
987+
if (ret < 0) {
988+
dev_err(&client->dev, "error configuring chip\n");
989+
goto err_config;
990+
}
991+
992+
return 0;
993+
994+
err_config:
995+
lp5523_deinit_device(chip);
996+
err:
997+
return ret;
982998
}
983999

9841000
static void lp5523_deinit_device(struct lp5523_chip *chip)
@@ -1018,7 +1034,7 @@ static int lp5523_probe(struct i2c_client *client,
10181034

10191035
ret = lp5523_init_device(chip);
10201036
if (ret)
1021-
goto fail1;
1037+
goto err_init;
10221038

10231039
dev_info(&client->dev, "%s Programmable led chip found\n", id->name);
10241040

@@ -1030,11 +1046,6 @@ static int lp5523_probe(struct i2c_client *client,
10301046
goto fail1;
10311047
}
10321048
}
1033-
ret = lp5523_configure(client);
1034-
if (ret < 0) {
1035-
dev_err(&client->dev, "error configuring chip\n");
1036-
goto fail1;
1037-
}
10381049

10391050
ret = lp5523_register_leds(chip, id->name);
10401051
if (ret)
@@ -1050,6 +1061,7 @@ static int lp5523_probe(struct i2c_client *client,
10501061
lp5523_unregister_leds(chip);
10511062
fail1:
10521063
lp5523_deinit_device(chip);
1064+
err_init:
10531065
return ret;
10541066
}
10551067

0 commit comments

Comments
 (0)