linux/drivers/leds
Hans de Goede d1883cefd3 leds: led-class: Only Add LED to leds_list when it is fully ready
Before this change the LED was added to leds_list before led_init_core()
gets called adding it the list before led_classdev.set_brightness_work gets
initialized.

This leaves a window where led_trigger_register() of a LED's default
trigger will call led_trigger_set() which calls led_set_brightness()
which in turn will end up queueing the *uninitialized*
led_classdev.set_brightness_work.

This race gets hit by the lenovo-thinkpad-t14s EC driver which registers
2 LEDs with a default trigger provided by snd_ctl_led.ko in quick
succession. The first led_classdev_register() causes an async modprobe of
snd_ctl_led to run and that async modprobe manages to exactly hit
the window where the second LED is on the leds_list without led_init_core()
being called for it, resulting in:

 ------------[ cut here ]------------
 WARNING: CPU: 11 PID: 5608 at kernel/workqueue.c:4234 __flush_work+0x344/0x390
 Hardware name: LENOVO 21N2S01F0B/21N2S01F0B, BIOS N42ET93W (2.23 ) 09/01/2025
 ...
 Call trace:
  __flush_work+0x344/0x390 (P)
  flush_work+0x2c/0x50
  led_trigger_set+0x1c8/0x340
  led_trigger_register+0x17c/0x1c0
  led_trigger_register_simple+0x84/0xe8
  snd_ctl_led_init+0x40/0xf88 [snd_ctl_led]
  do_one_initcall+0x5c/0x318
  do_init_module+0x9c/0x2b8
  load_module+0x7e0/0x998

Close the race window by moving the adding of the LED to leds_list to
after the led_init_core() call.

Cc: stable@vger.kernel.org
Fixes: d23a22a74f ("leds: delay led_set_brightness if stopping soft-blink")
Signed-off-by: Hans de Goede <johannes.goede@oss.qualcomm.com>
Reviewed-by: Sebastian Reichel <sre@kernel.org>
Link: https://patch.msgid.link/20251211163727.366441-1-johannes.goede@oss.qualcomm.com
Signed-off-by: Lee Jones <lee@kernel.org>
2026-01-20 16:02:01 +00:00
..
blink treewide: rename GPIO set callbacks back to their original names 2025-08-07 10:07:06 +02:00
flash leds: flash: Use fwnode_get_next_child_node() instead 2025-10-21 10:46:22 +01:00
rgb leds: rgb: leds-qcom-lpg: Don't enable TRILED when configuring PWM 2025-11-20 15:25:19 +00:00
simatic
trigger soc: driver updates for 6.19 2025-12-05 17:29:04 -08:00
.kunitconfig
Kconfig leds: Drop duplicate LEDS_EXPRESSWIRE config 2025-11-06 16:57:59 +00:00
Makefile
TODO
led-class-flash.c
led-class-multicolor.c
led-class.c leds: led-class: Only Add LED to leds_list when it is fully ready 2026-01-20 16:02:01 +00:00
led-core.c
led-test.c
led-triggers.c
leds-88pm860x.c
leds-acer-a500.c
leds-adp5520.c
leds-an30259a.c
leds-apu.c
leds-ariel.c
leds-aw200xx.c
leds-aw2013.c
leds-bcm6328.c
leds-bcm6358.c
leds-bd2606mvv.c
leds-bd2802.c
leds-blinkm.c
leds-cht-wcove.c
leds-clevo-mail.c
leds-cobalt-qube.c
leds-cobalt-raq.c
leds-cpcap.c
leds-cr0014114.c
leds-cros_ec.c leds: leds-cros_ec: Skip LEDs without color components 2025-11-06 16:52:36 +00:00
leds-da903x.c
leds-da9052.c
leds-dac124s085.c
leds-el15203000.c
leds-expresswire.c
leds-gpio-register.c
leds-gpio.c
leds-hp6xx.c
leds-ip30.c
leds-ipaq-micro.c
leds-is31fl32xx.c leds: leds-is31fl32xx: Add support for is31fl3236a 2025-08-18 09:48:11 +01:00
leds-is31fl319x.c leds: is31fl319x: Use devm_mutex_init() 2025-09-11 16:18:13 +01:00
leds-lm355x.c
leds-lm3530.c
leds-lm3532.c
leds-lm3533.c
leds-lm3642.c
leds-lm3692x.c
leds-lm3697.c
leds-lm36274.c
leds-locomo.c
leds-lp50xx.c leds: leds-lp50xx: Enable chip before any communication 2025-11-13 13:13:45 +00:00
leds-lp55xx-common.c leds: leds-lp55xx: Use correct address for memory programming 2025-09-02 13:26:25 +01:00
leds-lp55xx-common.h
leds-lp3944.c
leds-lp3952.c
leds-lp5521.c
leds-lp5523.c
leds-lp5562.c
leds-lp5569.c
leds-lp8501.c
leds-lp8788.c
leds-lp8860.c leds: lp8860: Check return value of devm_mutex_init() 2025-07-11 15:11:19 -07:00
leds-lp8864.c
leds-lt3593.c
leds-max5970.c leds: Use fwnode_for_each_child_node() instead 2025-10-21 10:46:16 +01:00
leds-max8997.c
leds-max77650.c
leds-max77705.c leds: Use fwnode_for_each_child_node() instead 2025-10-21 10:46:16 +01:00
leds-mc13783.c
leds-menf21bmc.c
leds-mlxcpld.c
leds-mlxreg.c
leds-mt6323.c
leds-net48xx.c
leds-netxbig.c leds: netxbig: Fix GPIO descriptor leak in error paths 2025-11-13 13:51:12 +00:00
leds-nic78bx.c
leds-ns2.c
leds-ot200.c
leds-pca955x.c treewide: rename GPIO set callbacks back to their original names 2025-08-07 10:07:06 +02:00
leds-pca963x.c
leds-pca995x.c
leds-pca9532.c treewide: rename GPIO set callbacks back to their original names 2025-08-07 10:07:06 +02:00
leds-pm8058.c
leds-powernv.c
leds-pwm.c leds: pwm: Reorder include files to alphabetic order 2025-11-20 12:20:24 +00:00
leds-qnap-mcu.c leds: qnap-mcu: Add support for the red and green status LEDs 2025-09-02 08:54:46 +01:00
leds-rb532.c
leds-regulator.c
leds-sc27xx-bltc.c
leds-spi-byte.c
leds-ss4200.c
leds-st1202.c
leds-sun50i-a100.c
leds-sunfire.c
leds-syscon.c
leds-tca6507.c treewide: rename GPIO set callbacks back to their original names 2025-08-07 10:07:06 +02:00
leds-ti-lmu-common.c
leds-tlc591xx.c
leds-tps6105x.c
leds-turris-omnia.c
leds-upboard.c leds: upboard: Fix module alias 2025-10-25 12:42:34 +01:00
leds-wm831x-status.c
leds-wm8350.c
leds-wrap.c
leds.h
uleds.c