platform/x86: fujitsu-laptop: rework logolamp_set() to properly handle errors
Subsystems (2)
PATCH v2 1/2 platform/x86: fujitsu-laptop: rework logolamp_set() to properly handle errors
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).
---
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(-)
drivers/platform/x86/fujitsu-laptop.c +14 -9
@@ -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,
Signature · 1 line
2.11.0
PATCH v2 2/2 platform/x86: fujitsu-laptop: simplify logolamp_get()
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.
---
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(-)
drivers/platform/x86/fujitsu-laptop.c +11 -11
@@ -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)
Signature · 1 line
2.11.0
Re: [PATCH v2 2/2] platform/x86: fujitsu-laptop: simplify logolamp_get()
Quoted 6 lines · Micha?? K??pie??
Now that
call_fext_func()is invoked bylogolamp_set()for bothLOGOLAMP_POWERONandLOGOLAMP_ALWAYSfor every brightness value,logolamp_get()can be simplified to decrease indentation and number of local variables.Signed-off-by Micha?? K??pie?? <[email protected]>
Seems sensible to me.
Quoted 52 lines
---
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 returnLED_OFF, just like the original version.drivers/platform/x86/fujitsu-laptop.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)drivers/platform/x86/fujitsu-laptop.c +11
-11@@ -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)Signature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 8 lines · Micha?? K??pie??
Potential errors returned by some
call_fext_func()calls insidelogolamp_set()are currently ignored. Reworklogolamp_set()to properly handle them. This causes one morecall_fext_func()call to be made in theLED_OFFcase, 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?? <[email protected]>
Quoted 50 lines
---
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(-)drivers/platform/x86/fujitsu-laptop.c +14
-9@@ -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,Signature · 6 lines
2.11.0 -- To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 11 lines · Jonathan Woithe
Quoted 8 lines · Micha?? K??pie??
Potential errors returned by some
call_fext_func()calls insidelogolamp_set()are currently ignored. Reworklogolamp_set()to properly handle them. This causes one morecall_fext_func()call to be made in theLED_OFFcase, 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?? <[email protected]>Acked-by Jonathan Woithe <[email protected]>
Both patches pushed to testing, thanks!
Quoted 53 lines
Quoted 47 lines
---
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(-)drivers/platform/x86/fujitsu-laptop.c +14
-10@@ -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
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
Signature · 2 lines
With Best Regards, Andy Shevchenko