Skip to content

Commit a59d882

Browse files
geo-starklag-linaro
authored andcommitted
leds: aw200xx: 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]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent fb74e4f commit a59d882

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

drivers/leds/leds-aw200xx.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,16 @@ static const struct regmap_config aw200xx_regmap_config = {
530530
.disable_locking = true,
531531
};
532532

533+
static void aw200xx_chip_reset_action(void *data)
534+
{
535+
aw200xx_chip_reset(data);
536+
}
537+
538+
static void aw200xx_disable_action(void *data)
539+
{
540+
aw200xx_disable(data);
541+
}
542+
533543
static int aw200xx_probe(struct i2c_client *client)
534544
{
535545
const struct aw200xx_chipdef *cdef;
@@ -568,11 +578,17 @@ static int aw200xx_probe(struct i2c_client *client)
568578

569579
aw200xx_enable(chip);
570580

581+
ret = devm_add_action(&client->dev, aw200xx_disable_action, chip);
582+
if (ret)
583+
return ret;
584+
571585
ret = aw200xx_chip_check(chip);
572586
if (ret)
573587
return ret;
574588

575-
mutex_init(&chip->mutex);
589+
ret = devm_mutex_init(&client->dev, &chip->mutex);
590+
if (ret)
591+
return ret;
576592

577593
/* Need a lock now since after call aw200xx_probe_fw, sysfs nodes created */
578594
mutex_lock(&chip->mutex);
@@ -581,6 +597,10 @@ static int aw200xx_probe(struct i2c_client *client)
581597
if (ret)
582598
goto out_unlock;
583599

600+
ret = devm_add_action(&client->dev, aw200xx_chip_reset_action, chip);
601+
if (ret)
602+
goto out_unlock;
603+
584604
ret = aw200xx_probe_fw(&client->dev, chip);
585605
if (ret)
586606
goto out_unlock;
@@ -595,15 +615,6 @@ static int aw200xx_probe(struct i2c_client *client)
595615
return ret;
596616
}
597617

598-
static void aw200xx_remove(struct i2c_client *client)
599-
{
600-
struct aw200xx *chip = i2c_get_clientdata(client);
601-
602-
aw200xx_chip_reset(chip);
603-
aw200xx_disable(chip);
604-
mutex_destroy(&chip->mutex);
605-
}
606-
607618
static const struct aw200xx_chipdef aw20036_cdef = {
608619
.channels = 36,
609620
.display_size_rows_max = 3,
@@ -652,7 +663,6 @@ static struct i2c_driver aw200xx_driver = {
652663
.of_match_table = aw200xx_match_table,
653664
},
654665
.probe = aw200xx_probe,
655-
.remove = aw200xx_remove,
656666
.id_table = aw200xx_id,
657667
};
658668
module_i2c_driver(aw200xx_driver);

0 commit comments

Comments
 (0)