Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <gnstark@salutedevices.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Tested-by: Nikita Travkin <nikita@trvn.ru>
Link: https://lore.kernel.org/r/20240411161032.609544-3-gnstark@salutedevices.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

George Stark and committed by
Lee Jones
fb74e4fa 4cd47222

+13 -12
+13 -12
drivers/leds/leds-aw2013.c
··· 320 320 return 0; 321 321 } 322 322 323 + static void aw2013_chip_disable_action(void *data) 324 + { 325 + aw2013_chip_disable(data); 326 + } 327 + 323 328 static const struct regmap_config aw2013_regmap_config = { 324 329 .reg_bits = 8, 325 330 .val_bits = 8, ··· 341 336 if (!chip) 342 337 return -ENOMEM; 343 338 344 - mutex_init(&chip->mutex); 339 + ret = devm_mutex_init(&client->dev, &chip->mutex); 340 + if (ret) 341 + return ret; 342 + 345 343 mutex_lock(&chip->mutex); 346 344 347 345 chip->client = client; ··· 392 384 goto error_reg; 393 385 } 394 386 387 + ret = devm_add_action(&client->dev, aw2013_chip_disable_action, chip); 388 + if (ret) 389 + goto error_reg; 390 + 395 391 ret = aw2013_probe_dt(chip); 396 392 if (ret < 0) 397 393 goto error_reg; ··· 418 406 419 407 error: 420 408 mutex_unlock(&chip->mutex); 421 - mutex_destroy(&chip->mutex); 422 409 return ret; 423 - } 424 - 425 - static void aw2013_remove(struct i2c_client *client) 426 - { 427 - struct aw2013 *chip = i2c_get_clientdata(client); 428 - 429 - aw2013_chip_disable(chip); 430 - 431 - mutex_destroy(&chip->mutex); 432 410 } 433 411 434 412 static const struct of_device_id aw2013_match_table[] = { ··· 434 432 .of_match_table = aw2013_match_table, 435 433 }, 436 434 .probe = aw2013_probe, 437 - .remove = aw2013_remove, 438 435 }; 439 436 440 437 module_i2c_driver(aw2013_driver);