Skip to contentSkip to conversation

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

PATCH In review Lee Jones 2 participants 4 messages Jun 13, 2024 – Jun 26, 2024 LED

lore
Share & tools
lore

Lee Jones

author maintainer
#0 lore raw

PATCH 1/1 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:

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

---
 drivers/leds/led-core.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/leds/led-core.c +13 -6
index ef7d1c6767ca..3b4db39f2326 100644
@@ -123,15 +123,22 @@ static void led_timer_function(struct timer_list *t)
 static void set_brightness_delayed_set_brightness(struct led_classdev *led_cdev,
 						  unsigned int value)
 {
-	int ret = 0;
+	int ret;
 
 	ret = __led_set_brightness(led_cdev, value);
-	if (ret == -ENOTSUPP)
+	if (ret == -ENOTSUPP) {
 		ret = __led_set_brightness_blocking(led_cdev, value);
-	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)))
+		if (ret == -ENOTSUPP)
+			/* No back-end support to set a fixed brightness value */
+			return;
+	}
+
+	/* 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,
 			"Setting an LED's brightness failed (%d)\n", ret);
 }
Signature · 1 line
2.45.2.505.gda0bf45e8d-goog
author maintainer
#1 lore raw
Quoted 6 lines · Lee Jones

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:

Quoted 8 lines

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

Heiner, you good with this solution?

A Tested-by or Reviewed-by would be good if you have the time.

Quoted 41 lines
---
 drivers/leds/led-core.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/leds/led-core.c +13 -6
index ef7d1c6767ca..3b4db39f2326 100644
@@ -123,15 +123,22 @@ static void led_timer_function(struct timer_list *t)
 static void set_brightness_delayed_set_brightness(struct led_classdev *led_cdev,
 						  unsigned int value)
 {
-	int ret = 0;
+	int ret;
 
 	ret = __led_set_brightness(led_cdev, value);
-	if (ret == -ENOTSUPP)
+	if (ret == -ENOTSUPP) {
 		ret = __led_set_brightness_blocking(led_cdev, value);
-	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)))
+		if (ret == -ENOTSUPP)
+			/* No back-end support to set a fixed brightness value */
+			return;
+	}
+
+	/* 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,
 			"Setting an LED's brightness failed (%d)\n", ret);
 }
Signature · 1 line
2.45.2.505.gda0bf45e8d-goog
Signature · 1 line
Lee Jones [李琼斯]
Reviewed-by
#2 lore raw
Quoted 13 lines · Lee Jones
Quoted 11 lines · Lee Jones

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:

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

Quoted 9 lines
Quoted 3 lines

Heiner, you good with this solution?

A Tested-by or Reviewed-by would be good if you have the time.

Quoted 1 line
author maintainer
#3 lore raw
Quoted 18 lines · Heiner Kallweit
Quoted 17 lines · Lee Jones
Quoted 14 lines · Lee Jones

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:

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

Quoted 7 lines
Quoted 5 lines

Heiner, you good with this solution?

A Tested-by or Reviewed-by would be good if you have the time.

Quoted 1 line

Added, thank you.

Signature · 1 line
Lee Jones [李琼斯]