[PATCH v3 3/3] leds: Make led_set_brightness_sync() also use __led_set_brightness()

From: Jean-Jacques Hiblot
Date: Wed Jul 17 2019 - 10:00:12 EST


There are some LED drivers that do not implement brightness_set_blocking(),
for those drivers led_set_brightness_sync() cannot work.
Fixing it by calling first __led_set_brightness() and falling back to
__led_set_brightness_blocking() if it failed.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@xxxxxx>
---
drivers/leds/led-core.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index dab32cf778f2..4a0506081c0e 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -320,15 +320,19 @@ int led_set_brightness_sync(struct led_classdev *led_cdev,
if (led_cdev->blink_delay_on || led_cdev->blink_delay_off)
return -EBUSY;

- led_cdev->brightness = min(value, led_cdev->max_brightness);
+ value = min(value, led_cdev->max_brightness);

if (led_cdev->flags & LED_SUSPENDED)
return 0;

- ret = __led_set_brightness_blocking(led_cdev, led_cdev->brightness);
+ ret = __led_set_brightness(led_cdev, value);
+ if (ret == -ENOTSUPP)
+ ret = __led_set_brightness_blocking(led_cdev, value);
if (ret)
return ret;

+ led_cdev->brightness = value;
+
return __led_handle_regulator(led_cdev, led_cdev->brightness);
}
EXPORT_SYMBOL_GPL(led_set_brightness_sync);
--
2.17.1