mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] platform/x86: asus-wmi: Clean up asus_wmi_set_devstate()
@ 2026-03-26 23:11 Ethan Tidmore
  2026-03-26 23:11 ` [PATCH 1/2] platform/x86: asus-wmi: Remove redundant condition Ethan Tidmore
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Ethan Tidmore @ 2026-03-26 23:11 UTC (permalink / raw)
  To: Corentin Chary, Luke D . Jones, Denis Benato, Hans de Goede,
	Ilpo Järvinen
  Cc: platform-driver-x86, linux-kernel, 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(-)

-- 
2.53.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] platform/x86: asus-wmi: Remove redundant condition
  2026-03-26 23:11 [PATCH 0/2] platform/x86: asus-wmi: Clean up asus_wmi_set_devstate() Ethan Tidmore
@ 2026-03-26 23:11 ` Ethan Tidmore
  2026-03-31 13:07   ` Ilpo Järvinen
  2026-03-26 23:11 ` [PATCH 2/2] platform/x86: asus-wmi: Refactor control flow Ethan Tidmore
  2026-03-26 23:14 ` [PATCH 0/2] platform/x86: asus-wmi: Clean up asus_wmi_set_devstate() Ethan Tidmore
  2 siblings, 1 reply; 6+ messages in thread
From: Ethan Tidmore @ 2026-03-26 23:11 UTC (permalink / raw)
  To: Corentin Chary, Luke D . Jones, Denis Benato, Hans de Goede,
	Ilpo Järvinen
  Cc: platform-driver-x86, linux-kernel, 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")
Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
---
 drivers/platform/x86/asus-wmi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
index 0b87214ddd1b..80144c412b90 100644
--- a/drivers/platform/x86/asus-wmi.c
+++ b/drivers/platform/x86/asus-wmi.c
@@ -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;
-- 
2.53.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] platform/x86: asus-wmi: Refactor control flow
  2026-03-26 23:11 [PATCH 0/2] platform/x86: asus-wmi: Clean up asus_wmi_set_devstate() Ethan Tidmore
  2026-03-26 23:11 ` [PATCH 1/2] platform/x86: asus-wmi: Remove redundant condition Ethan Tidmore
@ 2026-03-26 23:11 ` Ethan Tidmore
  2026-03-31 13:07   ` Ilpo Järvinen
  2026-03-26 23:14 ` [PATCH 0/2] platform/x86: asus-wmi: Clean up asus_wmi_set_devstate() Ethan Tidmore
  2 siblings, 1 reply; 6+ messages in thread
From: Ethan Tidmore @ 2026-03-26 23:11 UTC (permalink / raw)
  To: Corentin Chary, Luke D . Jones, Denis Benato, Hans de Goede,
	Ilpo Järvinen
  Cc: platform-driver-x86, linux-kernel, Ethan Tidmore

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] platform/x86: asus-wmi: Clean up asus_wmi_set_devstate()
  2026-03-26 23:11 [PATCH 0/2] platform/x86: asus-wmi: Clean up asus_wmi_set_devstate() Ethan Tidmore
  2026-03-26 23:11 ` [PATCH 1/2] platform/x86: asus-wmi: Remove redundant condition Ethan Tidmore
  2026-03-26 23:11 ` [PATCH 2/2] platform/x86: asus-wmi: Refactor control flow Ethan Tidmore
@ 2026-03-26 23:14 ` Ethan Tidmore
  2 siblings, 0 replies; 6+ messages in thread
From: Ethan Tidmore @ 2026-03-26 23:14 UTC (permalink / raw)
  To: Ethan Tidmore, Corentin Chary, Luke D . Jones, Denis Benato,
	Hans de Goede, Ilpo Järvinen
  Cc: platform-driver-x86, linux-kernel

On Thu Mar 26, 2026 at 6:11 PM CDT, Ethan Tidmore wrote:
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] platform/x86: asus-wmi: Refactor control flow
  2026-03-26 23:11 ` [PATCH 2/2] platform/x86: asus-wmi: Refactor control flow Ethan Tidmore
@ 2026-03-31 13:07   ` Ilpo Järvinen
  0 siblings, 0 replies; 6+ messages in thread
From: Ilpo Järvinen @ 2026-03-31 13:07 UTC (permalink / raw)
  To: Ethan Tidmore
  Cc: Corentin Chary, Luke D . Jones, Denis Benato, Hans de Goede,
	platform-driver-x86, LKML

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.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] platform/x86: asus-wmi: Remove redundant condition
  2026-03-26 23:11 ` [PATCH 1/2] platform/x86: asus-wmi: Remove redundant condition Ethan Tidmore
@ 2026-03-31 13:07   ` Ilpo Järvinen
  0 siblings, 0 replies; 6+ messages in thread
From: Ilpo Järvinen @ 2026-03-31 13:07 UTC (permalink / raw)
  To: Ethan Tidmore
  Cc: Corentin Chary, Luke D . Jones, Denis Benato, Hans de Goede,
	platform-driver-x86, LKML

On Thu, 26 Mar 2026, Ethan Tidmore wrote:

> 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")
> Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
> ---
>  drivers/platform/x86/asus-wmi.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
> index 0b87214ddd1b..80144c412b90 100644
> --- a/drivers/platform/x86/asus-wmi.c
> +++ b/drivers/platform/x86/asus-wmi.c
> @@ -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.

-- 
 i.


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-31 13:07 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-26 23:11 [PATCH 0/2] platform/x86: asus-wmi: Clean up asus_wmi_set_devstate() Ethan Tidmore
2026-03-26 23:11 ` [PATCH 1/2] platform/x86: asus-wmi: Remove redundant condition Ethan Tidmore
2026-03-31 13:07   ` Ilpo Järvinen
2026-03-26 23:11 ` [PATCH 2/2] platform/x86: asus-wmi: Refactor control flow Ethan Tidmore
2026-03-31 13:07   ` Ilpo Järvinen
2026-03-26 23:14 ` [PATCH 0/2] platform/x86: asus-wmi: Clean up asus_wmi_set_devstate() Ethan Tidmore

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®