Skip to contentSkip to conversation

platform/x86: asus-wmi: Clean up asus_wmi_set_devstate()

PATCH In review Ethan Tidmore 2 participants 6 messages Mar 26 – Mar 31

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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

Fixes 034f5efd362fb ("platform/x86: asus-wmi: adjust screenpad power/brightness handling")
---
 drivers/platform/x86/asus-wmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/asus-wmi.c +1 -1
index 0b87214ddd1b..80144c412b90 100644
@@ -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
maintainer
#2 lore raw

Re: [PATCH 1/2] platform/x86: asus-wmi: Remove redundant condition

Quoted 21 lines · Ethan Tidmore

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

Fixes 034f5efd362fb ("platform/x86: asus-wmi: adjust screenpad power/brightness handling")
---
 drivers/platform/x86/asus-wmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/asus-wmi.c +0 -0
index 0b87214ddd1b..80144c412b90 100644

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.
#3 lore raw

PATCH 2/2 platform/x86: asus-wmi: Refactor control flow

In reply to Ethan Tidmore

Refactor 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
index 80144c412b90..f8e389c54fe4 100644
@@ -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
maintainer
#4 lore raw

Re: [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.

---
 drivers/platform/x86/asus-wmi.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
drivers/platform/x86/asus-wmi.c +3 -6
index 80144c412b90..f8e389c54fe4 100644
@@ -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.
#5 lore raw
In reply to Ethan Tidmore
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 flow

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