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

leds: core: avoid error message when a USB LED device is unplugged

When a USB LED device is unplugged the remove call chain calls
led_classdev_unregister which tries to switch the LED off.
As the device has been removed already this results in a ENODEV
error message in dmesg.
Avoid this error message by ignoring ENODEV in calls from
led_classdev_unregister if the LED device is flagged as pluggable.

Therefore a new flag LED_HW_PLUGGABLE was introduced which should be set by
all LED drivers handling pluggable LED devices (mainly USB LED devices).

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>

authored by

Heiner Kallweit and committed by
Jacek Anaszewski
d84d80f3 70b2563b

+8 -1
+2
drivers/leds/led-class.c
··· 245 245 up_write(&led_cdev->trigger_lock); 246 246 #endif 247 247 248 + led_cdev->flags |= LED_UNREGISTERING; 249 + 248 250 /* Stop blinking */ 249 251 led_stop_software_blink(led_cdev); 250 252
+4 -1
drivers/leds/led-core.c
··· 98 98 led_cdev->delayed_set_value); 99 99 else 100 100 ret = -ENOTSUPP; 101 - if (ret < 0) 101 + if (ret < 0 && 102 + /* LED HW might have been unplugged, therefore don't warn */ 103 + !(ret == -ENODEV && (led_cdev->flags & LED_UNREGISTERING) && 104 + (led_cdev->flags & LED_HW_PLUGGABLE))) 102 105 dev_err(led_cdev->dev, 103 106 "Setting an LED's brightness failed (%d)\n", ret); 104 107 }
+2
include/linux/leds.h
··· 39 39 40 40 /* Lower 16 bits reflect status */ 41 41 #define LED_SUSPENDED (1 << 0) 42 + #define LED_UNREGISTERING (1 << 1) 42 43 /* Upper 16 bits reflect control information */ 43 44 #define LED_CORE_SUSPENDRESUME (1 << 16) 44 45 #define LED_BLINK_ONESHOT (1 << 17) ··· 49 48 #define LED_BLINK_DISABLE (1 << 21) 50 49 #define LED_SYSFS_DISABLE (1 << 22) 51 50 #define LED_DEV_CAP_FLASH (1 << 23) 51 + #define LED_HW_PLUGGABLE (1 << 24) 52 52 53 53 /* Set LED brightness level 54 54 * Must not sleep. Use brightness_set_blocking for drivers