Skip to content

Commit b5a0b81

Browse files
geo-starklag-linaro
authored andcommitted
leds: lp3952: Use devm API to cleanup module's resources
In this driver LEDs are registered using devm_led_classdev_register() so they are automatically unregistered after module's remove() is done. led_classdev_unregister() calls module's led_set_brightness() to turn off the LEDs and that callback uses resources which were destroyed already in module's remove() so use devm API instead of remove(). Also drop explicit turning LEDs off from remove() due to they will be off anyway by led_classdev_unregister(). Signed-off-by: George Stark <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent a59d882 commit b5a0b81

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

drivers/leds/leds-lp3952.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,13 @@ static const struct regmap_config lp3952_regmap = {
207207
.cache_type = REGCACHE_MAPLE,
208208
};
209209

210+
static void gpio_set_low_action(void *data)
211+
{
212+
struct lp3952_led_array *priv = data;
213+
214+
gpiod_set_value(priv->enable_gpio, 0);
215+
}
216+
210217
static int lp3952_probe(struct i2c_client *client)
211218
{
212219
int status;
@@ -226,6 +233,10 @@ static int lp3952_probe(struct i2c_client *client)
226233
return status;
227234
}
228235

236+
status = devm_add_action(&client->dev, gpio_set_low_action, priv);
237+
if (status)
238+
return status;
239+
229240
priv->regmap = devm_regmap_init_i2c(client, &lp3952_regmap);
230241
if (IS_ERR(priv->regmap)) {
231242
int err = PTR_ERR(priv->regmap);
@@ -254,15 +265,6 @@ static int lp3952_probe(struct i2c_client *client)
254265
return 0;
255266
}
256267

257-
static void lp3952_remove(struct i2c_client *client)
258-
{
259-
struct lp3952_led_array *priv;
260-
261-
priv = i2c_get_clientdata(client);
262-
lp3952_on_off(priv, LP3952_LED_ALL, false);
263-
gpiod_set_value(priv->enable_gpio, 0);
264-
}
265-
266268
static const struct i2c_device_id lp3952_id[] = {
267269
{LP3952_NAME, 0},
268270
{}
@@ -274,7 +276,6 @@ static struct i2c_driver lp3952_i2c_driver = {
274276
.name = LP3952_NAME,
275277
},
276278
.probe = lp3952_probe,
277-
.remove = lp3952_remove,
278279
.id_table = lp3952_id,
279280
};
280281

0 commit comments

Comments
 (0)