leds: core: avoid error message when a USB LED device is unplugged
PATCH v2 1/1 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).
---
v2:
- rebased
--- drivers/leds/led-class.c | 2 ++ drivers/leds/led-core.c | 5 ++++- include/linux/leds.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-)
drivers/leds/led-class.c +2 -0
@@ -245,6 +245,8 @@ void led_classdev_unregister(struct led_classdev *led_cdev)up_write (&led_cdev->trigger_lock);#endif + led_cdev->flags |=LED_UNREGISTERING ; +/* Stop blinking */ led_stop_software_blink (led_cdev);
drivers/leds/led-core.c +4 -1
@@ -98,7 +98,10 @@ static void set_brightness_delayed(struct work_struct *ws) led_cdev->delayed_set_value); else ret = -ENOTSUPP ; -if (ret <0 ) +if (ret <0 && +/* LED HW might have been unplugged, therefore don't warn */ + !(ret == -ENODEV && (led_cdev->flags &LED_UNREGISTERING ) && + (led_cdev->flags &LED_HW_PLUGGABLE )))dev_err (led_cdev->dev,"Setting an LED's brightness failed (%d)\n" , ret); }
include/linux/leds.h +2 -0
@@ -39,6 +39,7 @@ struct led_classdev {/* Lower 16 bits reflect status */ #define LED_SUSPENDED (1 << 0) +#define LED_UNREGISTERING (1 << 1)/* Upper 16 bits reflect control information */ #define LED_CORE_SUSPENDRESUME (1 << 16)#define LED_BLINK_ONESHOT (1 << 17)
@@ -48,6 +49,7 @@ struct led_classdev {#define LED_BLINK_DISABLE (1 << 21)#define LED_SYSFS_DISABLE (1 << 22)#define LED_DEV_CAP_FLASH (1 << 23) +#define LED_HW_PLUGGABLE (1 << 24)/* Set LED brightness level * Must not sleep. Use brightness_set_blocking for drivers
Signature · 1 line
2.7.0
Jacek Anaszewski
AppliedQuoted 63 lines · Heiner Kallweit
When a USB LED device is unplugged the remove call chain calls
led_classdev_unregisterwhich 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 fromled_classdev_unregisterif the LED device is flagged as pluggable.Therefore a new flag
LED_HW_PLUGGABLEwas introduced which should be set by all LED drivers handling pluggable LED devices (mainly USB LED devices).Signed-off-by Heiner Kallweit <[email protected]>---
v2:
- rebased--- drivers/leds/led-class.c | 2 ++ drivers/leds/led-core.c | 5 ++++- include/linux/leds.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-)drivers/leds/led-class.c +2
-0@@ -245,6 +245,8 @@ void led_classdev_unregister(struct led_classdev *led_cdev)up_write (&led_cdev->trigger_lock);#endif + led_cdev->flags |=LED_UNREGISTERING ; +/* Stop blinking */ led_stop_software_blink (led_cdev);drivers/leds/led-core.c +4
-1@@ -98,7 +98,10 @@ static void set_brightness_delayed(struct work_struct *ws) led_cdev->delayed_set_value); else ret = -ENOTSUPP ; -if (ret <0 ) +if (ret <0 && +/* LED HW might have been unplugged, therefore don't warn */ + !(ret == -ENODEV && (led_cdev->flags &LED_UNREGISTERING ) && + (led_cdev->flags &LED_HW_PLUGGABLE )))dev_err (led_cdev->dev,"Setting an LED's brightness failed (%d)\n" , ret); }include/linux/leds.h +1
-0@@ -39,6 +39,7 @@ struct led_classdev {/* Lower 16 bits reflect status */ #define LED_SUSPENDED (1 << 0) +#define LED_UNREGISTERING (1 << 1)/* Upper 16 bits reflect control information */ #define LED_CORE_SUSPENDRESUME (1 << 16)#define LED_BLINK_ONESHOT (1 << 17)
include/linux/leds.h struct led_classdev { · line 55
Quoted 7 lines
include/linux/leds.h +1
-0@@ -48,6 +49,7 @@ struct led_classdev {#define LED_BLINK_DISABLE (1 << 21)#define LED_SYSFS_DISABLE (1 << 22)#define LED_DEV_CAP_FLASH (1 << 23) +#define LED_HW_PLUGGABLE (1 << 24)/* Set LED brightness level * Must not sleep. Use brightness_set_blocking for drivers
Applied to devel branch, thanks.
Signature · 2 lines
Best Regards, Jacek Anaszewski