linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] leds: core: Omit set_brightness error message for a LED supporting hw trigger only
@ 2024-06-13  7:57 Lee Jones
  2024-06-20  9:09 ` Lee Jones
  0 siblings, 1 reply; 4+ messages in thread
From: Lee Jones @ 2024-06-13  7:57 UTC (permalink / raw)
  To: lee; +Cc: linux-kernel, Pavel Machek, linux-leds, Heiner Kallweit

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>
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/leds/led-core.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index ef7d1c6767ca..3b4db39f2326 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -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);
 }
-- 
2.45.2.505.gda0bf45e8d-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] leds: core: Omit set_brightness error message for a LED supporting hw trigger only
  2024-06-13  7:57 [PATCH 1/1] leds: core: Omit set_brightness error message for a LED supporting hw trigger only Lee Jones
@ 2024-06-20  9:09 ` Lee Jones
  2024-06-24 20:21   ` Heiner Kallweit
  0 siblings, 1 reply; 4+ messages in thread
From: Lee Jones @ 2024-06-20  9:09 UTC (permalink / raw)
  To: linux-kernel, Pavel Machek, linux-leds, Heiner Kallweit

On Thu, 13 Jun 2024, Lee Jones wrote:

> 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>

Heiner, you good with this solution?

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

> Signed-off-by: Lee Jones <lee@kernel.org>
> ---
>  drivers/leds/led-core.c | 19 +++++++++++++------
>  1 file changed, 13 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
> index ef7d1c6767ca..3b4db39f2326 100644
> --- a/drivers/leds/led-core.c
> +++ b/drivers/leds/led-core.c
> @@ -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);
>  }
> -- 
> 2.45.2.505.gda0bf45e8d-goog
> 

-- 
Lee Jones [李琼斯]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] leds: core: Omit set_brightness error message for a LED supporting hw trigger only
  2024-06-20  9:09 ` Lee Jones
@ 2024-06-24 20:21   ` Heiner Kallweit
  2024-06-26 15:56     ` Lee Jones
  0 siblings, 1 reply; 4+ messages in thread
From: Heiner Kallweit @ 2024-06-24 20:21 UTC (permalink / raw)
  To: Lee Jones, linux-kernel, Pavel Machek, linux-leds

On 20.06.2024 11:09, Lee Jones wrote:
> On Thu, 13 Jun 2024, Lee Jones wrote:
> 
>> 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>
> 
> Heiner, you good with this solution?
> 
> A Tested-by or Reviewed-by would be good if you have the time.
> 
>> Signed-off-by: Lee Jones <lee@kernel.org>

Reviewed-by: Heiner Kallweit <hkallweit1@gmail.com>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/1] leds: core: Omit set_brightness error message for a LED supporting hw trigger only
  2024-06-24 20:21   ` Heiner Kallweit
@ 2024-06-26 15:56     ` Lee Jones
  0 siblings, 0 replies; 4+ messages in thread
From: Lee Jones @ 2024-06-26 15:56 UTC (permalink / raw)
  To: Heiner Kallweit; +Cc: linux-kernel, Pavel Machek, linux-leds

On Mon, 24 Jun 2024, Heiner Kallweit wrote:

> On 20.06.2024 11:09, Lee Jones wrote:
> > On Thu, 13 Jun 2024, Lee Jones wrote:
> > 
> >> 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>
> > 
> > Heiner, you good with this solution?
> > 
> > A Tested-by or Reviewed-by would be good if you have the time.
> > 
> >> Signed-off-by: Lee Jones <lee@kernel.org>
> 
> Reviewed-by: Heiner Kallweit <hkallweit1@gmail.com>

Added, thank you.

-- 
Lee Jones [李琼斯]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-26 15:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-13  7:57 [PATCH 1/1] leds: core: Omit set_brightness error message for a LED supporting hw trigger only Lee Jones
2024-06-20  9:09 ` Lee Jones
2024-06-24 20:21   ` Heiner Kallweit
2024-06-26 15:56     ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).