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
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.
© 2016 - 2026 Red Hat, Inc.