leds: core: Omit set_brightness error message for a LED supporting hw trigger only

If both set_brightness functions return -ENOTSUPP, then the LED doesn't
support setting a fixed brightness value, and the error message isn't
helpful. This can be the case e.g. for LEDs supporting a specific hw
trigger only.

Pinched the subject line and commit message from Heiner:
Link: https://lore.kernel.org/all/44177e37-9512-4044-8991-bb23b184bf37@gmail.com/

Reworked the function to provide Heiner's required semantics whilst
simultaneously increasing readability and flow.

Cc: Pavel Machek <pavel@ucw.cz>
Cc: linux-leds@vger.kernel.org
Suggested-by: Heiner Kallweit <hkallweit1@gmail.com>
Reviewed-by: Heiner Kallweit <hkallweit1@gmail.com>
Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
Lee Jones 2024-06-12 16:36:40 +01:00
parent 6f963a20ee
commit d33d1214a1

View File

@ -122,15 +122,22 @@ static void led_timer_function(struct timer_list *t)
static void set_brightness_delayed_set_brightness(struct led_classdev *led_cdev, static void set_brightness_delayed_set_brightness(struct led_classdev *led_cdev,
unsigned int value) unsigned int value)
{ {
int ret = 0; int ret;
ret = __led_set_brightness(led_cdev, value); ret = __led_set_brightness(led_cdev, value);
if (ret == -ENOTSUPP) if (ret == -ENOTSUPP) {
ret = __led_set_brightness_blocking(led_cdev, value); ret = __led_set_brightness_blocking(led_cdev, value);
if (ret < 0 && if (ret == -ENOTSUPP)
/* LED HW might have been unplugged, therefore don't warn */ /* No back-end support to set a fixed brightness value */
!(ret == -ENODEV && (led_cdev->flags & LED_UNREGISTERING) && return;
(led_cdev->flags & LED_HW_PLUGGABLE))) }
/* LED HW might have been unplugged, therefore don't warn */
if (ret == -ENODEV && led_cdev->flags & LED_UNREGISTERING &&
led_cdev->flags & LED_HW_PLUGGABLE)
return;
if (ret < 0)
dev_err(led_cdev->dev, dev_err(led_cdev->dev,
"Setting an LED's brightness failed (%d)\n", ret); "Setting an LED's brightness failed (%d)\n", ret);
} }