Skip to content

Commit 982e0f0

Browse files
glneolag-linaro
authored andcommitted
leds: lp8860: Disable GPIO with devm action
This helps prevent mistakes like disable out of order in cleanup functions and forgetting to free on error paths (as was done here). This was the last thing the .remove() function did, so remove that too. Signed-off-by: Andrew Davis <afd@ti.com> Link: https://lore.kernel.org/r/20250407183555.409687-6-afd@ti.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent e0b95ba commit 982e0f0

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

drivers/leds/leds-lp8860.c

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,13 @@
9090
* @led_dev: led class device pointer
9191
* @regmap: Devices register map
9292
* @eeprom_regmap: EEPROM register map
93-
* @enable_gpio: VDDIO/EN gpio to enable communication interface
9493
*/
9594
struct lp8860_led {
9695
struct mutex lock;
9796
struct i2c_client *client;
9897
struct led_classdev led_dev;
9998
struct regmap *regmap;
10099
struct regmap *eeprom_regmap;
101-
struct gpio_desc *enable_gpio;
102100
};
103101

104102
static const struct reg_sequence lp8860_eeprom_disp_regs[] = {
@@ -218,8 +216,6 @@ static int lp8860_init(struct lp8860_led *led)
218216
unsigned int read_buf;
219217
int ret, reg_count;
220218

221-
gpiod_direction_output(led->enable_gpio, 1);
222-
223219
ret = lp8860_fault_check(led);
224220
if (ret)
225221
goto out;
@@ -256,9 +252,6 @@ static int lp8860_init(struct lp8860_led *led)
256252
return ret;
257253

258254
out:
259-
if (ret)
260-
gpiod_direction_output(led->enable_gpio, 0);
261-
262255
return ret;
263256
}
264257

@@ -276,13 +269,21 @@ static const struct regmap_config lp8860_eeprom_regmap_config = {
276269
.max_register = LP8860_EEPROM_REG_24,
277270
};
278271

272+
static void lp8860_disable_gpio(void *data)
273+
{
274+
struct gpio_desc *gpio = data;
275+
276+
gpiod_set_value(gpio, 0);
277+
}
278+
279279
static int lp8860_probe(struct i2c_client *client)
280280
{
281281
int ret;
282282
struct lp8860_led *led;
283283
struct device_node *np = dev_of_node(&client->dev);
284284
struct device_node *child_node;
285285
struct led_init_data init_data = {};
286+
struct gpio_desc *enable_gpio;
286287

287288
led = devm_kzalloc(&client->dev, sizeof(*led), GFP_KERNEL);
288289
if (!led)
@@ -292,13 +293,11 @@ static int lp8860_probe(struct i2c_client *client)
292293
if (!child_node)
293294
return -EINVAL;
294295

295-
led->enable_gpio = devm_gpiod_get_optional(&client->dev,
296-
"enable", GPIOD_OUT_LOW);
297-
if (IS_ERR(led->enable_gpio)) {
298-
ret = PTR_ERR(led->enable_gpio);
299-
dev_err(&client->dev, "Failed to get enable gpio: %d\n", ret);
300-
return ret;
301-
}
296+
enable_gpio = devm_gpiod_get_optional(&client->dev, "enable", GPIOD_OUT_LOW);
297+
if (IS_ERR(enable_gpio))
298+
return dev_err_probe(&client->dev, PTR_ERR(enable_gpio),
299+
"Failed to get enable GPIO\n");
300+
devm_add_action_or_reset(&client->dev, lp8860_disable_gpio, enable_gpio);
302301

303302
ret = devm_regulator_get_enable_optional(&client->dev, "vled");
304303
if (ret && ret != -ENODEV)
@@ -310,8 +309,6 @@ static int lp8860_probe(struct i2c_client *client)
310309

311310
devm_mutex_init(&client->dev, &led->lock);
312311

313-
i2c_set_clientdata(client, led);
314-
315312
led->regmap = devm_regmap_init_i2c(client, &lp8860_regmap_config);
316313
if (IS_ERR(led->regmap)) {
317314
ret = PTR_ERR(led->regmap);
@@ -346,14 +343,6 @@ static int lp8860_probe(struct i2c_client *client)
346343
return 0;
347344
}
348345

349-
static void lp8860_remove(struct i2c_client *client)
350-
{
351-
struct lp8860_led *led = i2c_get_clientdata(client);
352-
int ret;
353-
354-
gpiod_direction_output(led->enable_gpio, 0);
355-
}
356-
357346
static const struct i2c_device_id lp8860_id[] = {
358347
{ "lp8860" },
359348
{ }
@@ -372,7 +361,6 @@ static struct i2c_driver lp8860_driver = {
372361
.of_match_table = of_lp8860_leds_match,
373362
},
374363
.probe = lp8860_probe,
375-
.remove = lp8860_remove,
376364
.id_table = lp8860_id,
377365
};
378366
module_i2c_driver(lp8860_driver);

0 commit comments

Comments
 (0)