X86 platform drivers
 help / color / mirror / Atom feed
* [PATCH v2 1/2] platform/x86: fujitsu-laptop: rework logolamp_set() to properly handle errors
@ 2017-01-09 13:14 Michał Kępień
  2017-01-09 13:14 ` [PATCH v2 2/2] platform/x86: fujitsu-laptop: simplify logolamp_get() Michał Kępień
  2017-01-09 13:35 ` [PATCH v2 1/2] platform/x86: fujitsu-laptop: rework logolamp_set() to properly handle errors Jonathan Woithe
  0 siblings, 2 replies; 5+ messages in thread
From: Michał Kępień @ 2017-01-09 13:14 UTC (permalink / raw)
  To: Jonathan Woithe, Darren Hart
  Cc: Andy Shevchenko, platform-driver-x86, linux-kernel

Potential errors returned by some call_fext_func() calls inside
logolamp_set() are currently ignored.  Rework logolamp_set() to properly
handle them.  This causes one more call_fext_func() call to be made in
the LED_OFF case, though one could argue that this is logically the
right thing to do (even though the extra call is not needed to shut the
LED off).

Signed-off-by: Michał Kępień <kernel@kempniu.pl>
---
Changes from v1:

  - Decrease indentation by rearranging logical conditions.
  - Split variable declarations into two lines.

 drivers/platform/x86/fujitsu-laptop.c | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index b725a907a91f..34b8481fb0ed 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -271,15 +271,20 @@ static int call_fext_func(int cmd, int arg0, int arg1, int arg2)
 static int logolamp_set(struct led_classdev *cdev,
 			       enum led_brightness brightness)
 {
-	if (brightness >= LED_FULL) {
-		call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_ON);
-		return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, FUNC_LED_ON);
-	} else if (brightness >= LED_HALF) {
-		call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_ON);
-		return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, FUNC_LED_OFF);
-	} else {
-		return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_OFF);
-	}
+	int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
+	int ret;
+
+	if (brightness < LED_HALF)
+		poweron = FUNC_LED_OFF;
+
+	if (brightness < LED_FULL)
+		always = FUNC_LED_OFF;
+
+	ret = call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
+	if (ret < 0)
+		return ret;
+
+	return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
 }
 
 static int kblamps_set(struct led_classdev *cdev,
-- 
2.11.0

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

* [PATCH v2 2/2] platform/x86: fujitsu-laptop: simplify logolamp_get()
  2017-01-09 13:14 [PATCH v2 1/2] platform/x86: fujitsu-laptop: rework logolamp_set() to properly handle errors Michał Kępień
@ 2017-01-09 13:14 ` Michał Kępień
  2017-01-09 13:35   ` Jonathan Woithe
  2017-01-09 13:35 ` [PATCH v2 1/2] platform/x86: fujitsu-laptop: rework logolamp_set() to properly handle errors Jonathan Woithe
  1 sibling, 1 reply; 5+ messages in thread
From: Michał Kępień @ 2017-01-09 13:14 UTC (permalink / raw)
  To: Jonathan Woithe, Darren Hart
  Cc: Andy Shevchenko, platform-driver-x86, linux-kernel

Now that call_fext_func() is invoked by logolamp_set() for both
LOGOLAMP_POWERON and LOGOLAMP_ALWAYS for every brightness value,
logolamp_get() can be simplified to decrease indentation and number of
local variables.

Signed-off-by: Michał Kępień <kernel@kempniu.pl>
---
Changes from v1:

  - This patch was not present in v1.
    
One thing worth noting is that in case call_fext_func() returns an
error, logolamp_get() will still return LED_OFF, just like the original
version.

 drivers/platform/x86/fujitsu-laptop.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
index 34b8481fb0ed..7fa082558a42 100644
--- a/drivers/platform/x86/fujitsu-laptop.c
+++ b/drivers/platform/x86/fujitsu-laptop.c
@@ -319,17 +319,17 @@ static int eco_led_set(struct led_classdev *cdev,
 
 static enum led_brightness logolamp_get(struct led_classdev *cdev)
 {
-	enum led_brightness brightness = LED_OFF;
-	int poweron, always;
-
-	poweron = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
-	if (poweron == FUNC_LED_ON) {
-		brightness = LED_HALF;
-		always = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
-		if (always == FUNC_LED_ON)
-			brightness = LED_FULL;
-	}
-	return brightness;
+	int ret;
+
+	ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
+	if (ret == FUNC_LED_ON)
+		return LED_FULL;
+
+	ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
+	if (ret == FUNC_LED_ON)
+		return LED_HALF;
+
+	return LED_OFF;
 }
 
 static enum led_brightness kblamps_get(struct led_classdev *cdev)
-- 
2.11.0

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

* Re: [PATCH v2 1/2] platform/x86: fujitsu-laptop: rework logolamp_set() to properly handle errors
  2017-01-09 13:14 [PATCH v2 1/2] platform/x86: fujitsu-laptop: rework logolamp_set() to properly handle errors Michał Kępień
  2017-01-09 13:14 ` [PATCH v2 2/2] platform/x86: fujitsu-laptop: simplify logolamp_get() Michał Kępień
@ 2017-01-09 13:35 ` Jonathan Woithe
  2017-01-18 19:02   ` Andy Shevchenko
  1 sibling, 1 reply; 5+ messages in thread
From: Jonathan Woithe @ 2017-01-09 13:35 UTC (permalink / raw)
  To: Micha?? K??pie??
  Cc: Darren Hart, Andy Shevchenko, platform-driver-x86, linux-kernel

On Mon, Jan 09, 2017 at 02:14:16PM +0100, Micha?? K??pie?? wrote:
> Potential errors returned by some call_fext_func() calls inside
> logolamp_set() are currently ignored.  Rework logolamp_set() to properly
> handle them.  This causes one more call_fext_func() call to be made in
> the LED_OFF case, though one could argue that this is logically the
> right thing to do (even though the extra call is not needed to shut the
> LED off).
> 
> Signed-off-by: Micha?? K??pie?? <kernel@kempniu.pl>

Acked-by: Jonathan Woithe <jwoithe@just42.net>

> ---
> Changes from v1:
> 
>   - Decrease indentation by rearranging logical conditions.
>   - Split variable declarations into two lines.
> 
>  drivers/platform/x86/fujitsu-laptop.c | 23 ++++++++++++++---------
>  1 file changed, 14 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
> index b725a907a91f..34b8481fb0ed 100644
> --- a/drivers/platform/x86/fujitsu-laptop.c
> +++ b/drivers/platform/x86/fujitsu-laptop.c
> @@ -271,15 +271,20 @@ static int call_fext_func(int cmd, int arg0, int arg1, int arg2)
>  static int logolamp_set(struct led_classdev *cdev,
>  			       enum led_brightness brightness)
>  {
> -	if (brightness >= LED_FULL) {
> -		call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_ON);
> -		return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, FUNC_LED_ON);
> -	} else if (brightness >= LED_HALF) {
> -		call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_ON);
> -		return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, FUNC_LED_OFF);
> -	} else {
> -		return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_OFF);
> -	}
> +	int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
> +	int ret;
> +
> +	if (brightness < LED_HALF)
> +		poweron = FUNC_LED_OFF;
> +
> +	if (brightness < LED_FULL)
> +		always = FUNC_LED_OFF;
> +
> +	ret = call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
> +	if (ret < 0)
> +		return ret;
> +
> +	return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
>  }
>  
>  static int kblamps_set(struct led_classdev *cdev,
> -- 
> 2.11.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 

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

* Re: [PATCH v2 2/2] platform/x86: fujitsu-laptop: simplify logolamp_get()
  2017-01-09 13:14 ` [PATCH v2 2/2] platform/x86: fujitsu-laptop: simplify logolamp_get() Michał Kępień
@ 2017-01-09 13:35   ` Jonathan Woithe
  0 siblings, 0 replies; 5+ messages in thread
From: Jonathan Woithe @ 2017-01-09 13:35 UTC (permalink / raw)
  To: Micha?? K??pie??
  Cc: Darren Hart, Andy Shevchenko, platform-driver-x86, linux-kernel

On Mon, Jan 09, 2017 at 02:14:17PM +0100, Micha?? K??pie?? wrote:
> Now that call_fext_func() is invoked by logolamp_set() for both
> LOGOLAMP_POWERON and LOGOLAMP_ALWAYS for every brightness value,
> logolamp_get() can be simplified to decrease indentation and number of
> local variables.
> 
> Signed-off-by: Micha?? K??pie?? <kernel@kempniu.pl>

Seems sensible to me.

Acked-by: Jonathan Woithe <jwoithe@just42.net>

> ---
> Changes from v1:
> 
>   - This patch was not present in v1.
>     
> One thing worth noting is that in case call_fext_func() returns an
> error, logolamp_get() will still return LED_OFF, just like the original
> version.
> 
>  drivers/platform/x86/fujitsu-laptop.c | 22 +++++++++++-----------
>  1 file changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
> index 34b8481fb0ed..7fa082558a42 100644
> --- a/drivers/platform/x86/fujitsu-laptop.c
> +++ b/drivers/platform/x86/fujitsu-laptop.c
> @@ -319,17 +319,17 @@ static int eco_led_set(struct led_classdev *cdev,
>  
>  static enum led_brightness logolamp_get(struct led_classdev *cdev)
>  {
> -	enum led_brightness brightness = LED_OFF;
> -	int poweron, always;
> -
> -	poweron = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
> -	if (poweron == FUNC_LED_ON) {
> -		brightness = LED_HALF;
> -		always = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
> -		if (always == FUNC_LED_ON)
> -			brightness = LED_FULL;
> -	}
> -	return brightness;
> +	int ret;
> +
> +	ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_ALWAYS, 0x0);
> +	if (ret == FUNC_LED_ON)
> +		return LED_FULL;
> +
> +	ret = call_fext_func(FUNC_LEDS, 0x2, LOGOLAMP_POWERON, 0x0);
> +	if (ret == FUNC_LED_ON)
> +		return LED_HALF;
> +
> +	return LED_OFF;
>  }
>  
>  static enum led_brightness kblamps_get(struct led_classdev *cdev)
> -- 
> 2.11.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 

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

* Re: [PATCH v2 1/2] platform/x86: fujitsu-laptop: rework logolamp_set() to properly handle errors
  2017-01-09 13:35 ` [PATCH v2 1/2] platform/x86: fujitsu-laptop: rework logolamp_set() to properly handle errors Jonathan Woithe
@ 2017-01-18 19:02   ` Andy Shevchenko
  0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2017-01-18 19:02 UTC (permalink / raw)
  To: Jonathan Woithe
  Cc: Micha?? K??pie??, Darren Hart, Platform Driver,
	linux-kernel@vger.kernel.org

On Mon, Jan 9, 2017 at 3:35 PM, Jonathan Woithe <jwoithe@just42.net> wrote:
> On Mon, Jan 09, 2017 at 02:14:16PM +0100, Micha?? K??pie?? wrote:
>> Potential errors returned by some call_fext_func() calls inside
>> logolamp_set() are currently ignored.  Rework logolamp_set() to properly
>> handle them.  This causes one more call_fext_func() call to be made in
>> the LED_OFF case, though one could argue that this is logically the
>> right thing to do (even though the extra call is not needed to shut the
>> LED off).
>>
>> Signed-off-by: Micha?? K??pie?? <kernel@kempniu.pl>
>
> Acked-by: Jonathan Woithe <jwoithe@just42.net>

Both patches pushed to testing, thanks!

>
>> ---
>> Changes from v1:
>>
>>   - Decrease indentation by rearranging logical conditions.
>>   - Split variable declarations into two lines.
>>
>>  drivers/platform/x86/fujitsu-laptop.c | 23 ++++++++++++++---------
>>  1 file changed, 14 insertions(+), 9 deletions(-)
>>
>> diff --git a/drivers/platform/x86/fujitsu-laptop.c b/drivers/platform/x86/fujitsu-laptop.c
>> index b725a907a91f..34b8481fb0ed 100644
>> --- a/drivers/platform/x86/fujitsu-laptop.c
>> +++ b/drivers/platform/x86/fujitsu-laptop.c
>> @@ -271,15 +271,20 @@ static int call_fext_func(int cmd, int arg0, int arg1, int arg2)
>>  static int logolamp_set(struct led_classdev *cdev,
>>                              enum led_brightness brightness)
>>  {
>> -     if (brightness >= LED_FULL) {
>> -             call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_ON);
>> -             return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, FUNC_LED_ON);
>> -     } else if (brightness >= LED_HALF) {
>> -             call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_ON);
>> -             return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, FUNC_LED_OFF);
>> -     } else {
>> -             return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, FUNC_LED_OFF);
>> -     }
>> +     int poweron = FUNC_LED_ON, always = FUNC_LED_ON;
>> +     int ret;
>> +
>> +     if (brightness < LED_HALF)
>> +             poweron = FUNC_LED_OFF;
>> +
>> +     if (brightness < LED_FULL)
>> +             always = FUNC_LED_OFF;
>> +
>> +     ret = call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_POWERON, poweron);
>> +     if (ret < 0)
>> +             return ret;
>> +
>> +     return call_fext_func(FUNC_LEDS, 0x1, LOGOLAMP_ALWAYS, always);
>>  }
>>
>>  static int kblamps_set(struct led_classdev *cdev,
>> --
>> 2.11.0
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
> --



-- 
With Best Regards,
Andy Shevchenko

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

end of thread, other threads:[~2017-01-18 19:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-09 13:14 [PATCH v2 1/2] platform/x86: fujitsu-laptop: rework logolamp_set() to properly handle errors Michał Kępień
2017-01-09 13:14 ` [PATCH v2 2/2] platform/x86: fujitsu-laptop: simplify logolamp_get() Michał Kępień
2017-01-09 13:35   ` Jonathan Woithe
2017-01-09 13:35 ` [PATCH v2 1/2] platform/x86: fujitsu-laptop: rework logolamp_set() to properly handle errors Jonathan Woithe
2017-01-18 19:02   ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox