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

Ethan Tidmore posted 2 patches 6 days, 19 hours ago
[PATCH 2/2] platform/x86: asus-wmi: Refactor control flow
Posted by Ethan Tidmore 6 days, 19 hours ago
Refactor control flow in update_screenpad_bl_status() to avoid
unnecessary if statements and error checking.

Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
---
 drivers/platform/x86/asus-wmi.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 80144c412b90..f8e389c54fe4 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -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 = {
-- 
2.53.0
Re: [PATCH 2/2] platform/x86: asus-wmi: Refactor control flow
Posted by Ilpo Järvinen 2 days, 5 hours ago
On Thu, 26 Mar 2026, Ethan Tidmore wrote:

> Refactor control flow in update_screenpad_bl_status() to avoid
> unnecessary if statements and error checking.
> 
> Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
> ---
>  drivers/platform/x86/asus-wmi.c | 22 +++++++---------------
>  1 file changed, 7 insertions(+), 15 deletions(-)
> 
> diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
> index 80144c412b90..f8e389c54fe4 100644
> --- a/drivers/platform/x86/asus-wmi.c
> +++ b/drivers/platform/x86/asus-wmi.c
> @@ -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);

Couldn't this 0 / 1 variation be handled without if?

> +	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 = {
> 

-- 
 i.