platform/x86: asus-wmi: Clean up asus_wmi_set_devstate()
cover platform/x86: asus-wmi: Clean up asus_wmi_set_devstate()
Remove redundant control flow in asus_wmi_set_devstate() and refactor control flow to improve readability.
Ethan Tidmore (2):
platform/x86: asus-wmi: Remove redundant condition platform/x86: asus-wmi: Refactor control flow
drivers/platform/x86/asus-wmi.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
Signature · 1 line
2.53.0
PATCH 1/2 platform/x86: asus-wmi: Remove redundant condition
The condition (ctrl_param >= 0) is always true because ctrl_param is an unsigned integer.
Remove the redundant condition.
Detected by Smatch:drivers/platform/x86/asus-wmi.c:4427 update_screenpad_bl_status() warn:
always true condition '(ctrl_param >= 0) => (0-u32max >= 0)'
--- drivers/platform/x86/asus-wmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/asus-wmi.c +1 -1
@@ -4424,7 +4424,7 @@ static int update_screenpad_bl_status(struct backlight_device *bd)u32 ctrl_param = bd->props.brightness;int err =0 ; -if (ctrl_param >=0 && bd->props.power) { +if (bd->props.power) { err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,1 ,NULL );if (err <0 )return err;
Signature · 1 line
2.53.0
Ilpo Järvinen
maintainerRe: [PATCH 1/2] platform/x86: asus-wmi: Remove redundant condition
Quoted 21 lines · Ethan Tidmore
The condition (
ctrl_param>= 0) is always true becausectrl_paramis an unsigned integer.Remove the redundant condition.
Detected by Smatch:
drivers/platform/x86/asus-wmi.c:4427update_screenpad_bl_status()warn:
always true condition '(ctrl_param>= 0) => (0-u32max >= 0)'Fixes 034f5efd362fb ("platform/x86: asus-wmi: adjust screenpad power/brightness handling")Signed-off-by Ethan Tidmore <[email protected]>--- drivers/platform/x86/asus-wmi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/platform/x86/asus-wmi.c +0
-0
drivers/platform/x86/asus-wmi.c static int update_screenpad_bl_status(struct backlight_device *bd) · line 4430
Quoted 8 lines
drivers/platform/x86/asus-wmi.c +1
-1@@ -4424,7 +4424,7 @@ static int update_screenpad_bl_status(struct backlight_device *bd)u32 ctrl_param = bd->props.brightness;int err =0 ; -if (ctrl_param >=0 && bd->props.power) { +if (bd->props.power) { err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,1 ,NULL );if (err <0 )return err;
I've folded this into the original change.
Signature · 1 line
i.
PATCH 2/2 platform/x86: asus-wmi: Refactor control flow
In reply to Ethan TidmoreRefactor control flow in update_screenpad_bl_status() to avoid unnecessary if statements and error checking.
--- drivers/platform/x86/asus-wmi.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
drivers/platform/x86/asus-wmi.c +7 -15
@@ -4422,25 +4422,17 @@ static int read_screenpad_brightness(struct backlight_device *bd)static int update_screenpad_bl_status (struct backlight_device *bd) {u32 ctrl_param = bd->props.brightness; -int err =0 ; +int err; -if (bd->props.power) { - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,1 ,NULL ); -if (err <0 ) -return err; +if (!bd->props.power) +return asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , ctrl_param,NULL ); -if (err <0 ) -return err; - } -if (!bd->props.power) { - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); -if (err <0 ) -return err; - } + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,1 ,NULL ); +if (err <0 ) +return err; -return err; +return asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , ctrl_param,NULL ); }static const struct backlight_ops asus_screenpad_bl_ops = {
Signature · 1 line
2.53.0
Ilpo Järvinen
maintainerRe: [PATCH 2/2] platform/x86: asus-wmi: Refactor control flow
Quoted 27 lines · Ethan Tidmore
Refactor control flow in
update_screenpad_bl_status()to avoid unnecessary if statements and error checking.Signed-off-by Ethan Tidmore <[email protected]>--- drivers/platform/x86/asus-wmi.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)drivers/platform/x86/asus-wmi.c +3
-6@@ -4422,25 +4422,17 @@ static int read_screenpad_brightness(struct backlight_device *bd)static int update_screenpad_bl_status (struct backlight_device *bd) {u32 ctrl_param = bd->props.brightness; -int err =0 ; +int err; -if (bd->props.power) { - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,1 ,NULL ); -if (err <0 ) -return err; +if (!bd->props.power) +return asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , ctrl_param,NULL );
drivers/platform/x86/asus-wmi.c static int read_screenpad_brightness(struct backlight_device *bd) · line 4431
Quoted 10 lines
drivers/platform/x86/asus-wmi.c +1
-8-if (err <0 ) -return err; - } -if (!bd->props.power) { - err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,0 ,NULL ); -if (err <0 ) -return err; - } + err =asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_POWER ,1 ,NULL );
Couldn't this 0 / 1 variation be handled without if?
Quoted 9 lines
drivers/platform/x86/asus-wmi.c +3
-1+if (err <0 ) +return err; -return err; +return asus_wmi_set_devstate (ASUS_WMI_DEVID_SCREENPAD_LIGHT , ctrl_param,NULL ); }static const struct backlight_ops asus_screenpad_bl_ops = {
Signature · 1 line
i.
Quoted 9 lines · Ethan Tidmore
Remove redundant control flow in
asus_wmi_set_devstate()and refactor control flow to improve readability.Ethan Tidmore (2):
platform/x86: asus-wmi: Remove redundant condition platform/x86: asus-wmi: Refactor control flowdrivers/platform/x86/asus-wmi.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
I meant to say update_screenpad_bl_status() instead of asus_wmi_set_devstate().
Thanks,
ET