Skip to content

Commit fb74e4f

Browse files
geo-starklag-linaro
authored andcommitted
leds: aw2013: 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(). Signed-off-by: George Stark <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Tested-by: Nikita Travkin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 4cd4722 commit fb74e4f

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

drivers/leds/leds-aw2013.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ static int aw2013_probe_dt(struct aw2013 *chip)
320320
return 0;
321321
}
322322

323+
static void aw2013_chip_disable_action(void *data)
324+
{
325+
aw2013_chip_disable(data);
326+
}
327+
323328
static const struct regmap_config aw2013_regmap_config = {
324329
.reg_bits = 8,
325330
.val_bits = 8,
@@ -336,7 +341,10 @@ static int aw2013_probe(struct i2c_client *client)
336341
if (!chip)
337342
return -ENOMEM;
338343

339-
mutex_init(&chip->mutex);
344+
ret = devm_mutex_init(&client->dev, &chip->mutex);
345+
if (ret)
346+
return ret;
347+
340348
mutex_lock(&chip->mutex);
341349

342350
chip->client = client;
@@ -384,6 +392,10 @@ static int aw2013_probe(struct i2c_client *client)
384392
goto error_reg;
385393
}
386394

395+
ret = devm_add_action(&client->dev, aw2013_chip_disable_action, chip);
396+
if (ret)
397+
goto error_reg;
398+
387399
ret = aw2013_probe_dt(chip);
388400
if (ret < 0)
389401
goto error_reg;
@@ -406,19 +418,9 @@ static int aw2013_probe(struct i2c_client *client)
406418

407419
error:
408420
mutex_unlock(&chip->mutex);
409-
mutex_destroy(&chip->mutex);
410421
return ret;
411422
}
412423

413-
static void aw2013_remove(struct i2c_client *client)
414-
{
415-
struct aw2013 *chip = i2c_get_clientdata(client);
416-
417-
aw2013_chip_disable(chip);
418-
419-
mutex_destroy(&chip->mutex);
420-
}
421-
422424
static const struct of_device_id aw2013_match_table[] = {
423425
{ .compatible = "awinic,aw2013", },
424426
{ /* sentinel */ },
@@ -432,7 +434,6 @@ static struct i2c_driver aw2013_driver = {
432434
.of_match_table = aw2013_match_table,
433435
},
434436
.probe = aw2013_probe,
435-
.remove = aw2013_remove,
436437
};
437438

438439
module_i2c_driver(aw2013_driver);

0 commit comments

Comments
 (0)