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

leds: spi-byte: Use devm_mutex_init() for mutex initialization

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 mutex which was destroyed already
in module's remove() so use devm API instead.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20240606173037.3091598-6-andriy.shevchenko@linux.intel.com
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Andy Shevchenko and committed by
Lee Jones
133f941f 9ed388d1

+6 -20
+6 -20
drivers/leds/leds-spi-byte.c
··· 31 31 #include <linux/leds.h> 32 32 #include <linux/mod_devicetable.h> 33 33 #include <linux/module.h> 34 + #include <linux/mutex.h> 34 35 #include <linux/property.h> 35 36 #include <linux/spi/spi.h> 36 - #include <linux/mutex.h> 37 37 #include <uapi/linux/uleds.h> 38 38 39 39 struct spi_byte_chipdef { ··· 97 97 if (!led) 98 98 return -ENOMEM; 99 99 100 + ret = devm_mutex_init(dev, &led->mutex); 101 + if (ret) 102 + return ret; 103 + 100 104 led->spi = spi; 101 - mutex_init(&led->mutex); 102 105 led->cdef = device_get_match_data(dev); 103 106 led->ldev.brightness = LED_OFF; 104 107 led->ldev.max_brightness = led->cdef->max_value - led->cdef->off_value; ··· 119 116 init_data.devicename = "leds-spi-byte"; 120 117 init_data.default_label = ":"; 121 118 122 - ret = devm_led_classdev_register_ext(dev, &led->ldev, &init_data); 123 - if (ret) { 124 - mutex_destroy(&led->mutex); 125 - return ret; 126 - } 127 - 128 - spi_set_drvdata(spi, led); 129 - 130 - return 0; 131 - } 132 - 133 - static void spi_byte_remove(struct spi_device *spi) 134 - { 135 - struct spi_byte_led *led = spi_get_drvdata(spi); 136 - 137 - mutex_destroy(&led->mutex); 119 + return devm_led_classdev_register_ext(dev, &led->ldev, &init_data); 138 120 } 139 121 140 122 static struct spi_driver spi_byte_driver = { 141 123 .probe = spi_byte_probe, 142 - .remove = spi_byte_remove, 143 124 .driver = { 144 125 .name = KBUILD_MODNAME, 145 126 .of_match_table = spi_byte_dt_ids, 146 127 }, 147 128 }; 148 - 149 129 module_spi_driver(spi_byte_driver); 150 130 151 131 MODULE_AUTHOR("Christian Mauderer <oss@c-mauderer.de>");