All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Emre Cecanpunar <emreleno@gmail.com>
Cc: platform-driver-x86@vger.kernel.org,
	Hans de Goede <hansg@kernel.org>,
	 LKML <linux-kernel@vger.kernel.org>,
	krishna.chomal108@gmail.com,  radheykalra901@gmail.com,
	edip@medip.dev, hello@kursatabayli.dev,  mjg59@srcf.ucam.org,
	akpm@linux-foundation.org, jorge.lopez2@hp.com,  jes965@nyu.edu,
	mario.limonciello@amd.com, julien.robin28@free.fr
Subject: Re: [PATCH 2/5] platform/x86: hp-wmi: handle firmware errors in tablet mode query
Date: Tue, 21 Jul 2026 18:50:14 +0300 (EEST)	[thread overview]
Message-ID: <cd06d831-01d6-c8a2-94fc-894877f56c3d@linux.intel.com> (raw)
In-Reply-To: <ce5cd56d2ba561272770d7992e397dfbec108d4e.1784195117.git.emreleno@gmail.com>

On Thu, 16 Jul 2026, Emre Cecanpunar wrote:

> hp_wmi_get_tablet_mode() accepts any nonnegative return value from
> hp_wmi_perform_query() as success. HP firmware errors are positive, so a
> rejected query makes the zeroed response look like laptop mode.

Does this problem actually happen with some hw? Please add the info.

> Treat every nonzero result as an error and preserve negative transport
> errors. The event and resume paths pass the result directly to the input
> subsystem, where a negative errno would look like an asserted switch, so
> skip the switch update when the query fails.
>
> Fixes: 520ee4ea1cc6 ("platform/x86: hp-wmi: Fix SW_TABLET_MODE detection method")
> Signed-off-by: Emre Cecanpunar <emreleno@gmail.com>
> ---
>  drivers/platform/x86/hp/hp-wmi.c | 26 +++++++++++++++++---------
>  1 file changed, 17 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/platform/x86/hp/hp-wmi.c b/drivers/platform/x86/hp/hp-wmi.c
> index 205a6020e9c5..e226b772ef00 100644
> --- a/drivers/platform/x86/hp/hp-wmi.c
> +++ b/drivers/platform/x86/hp/hp-wmi.c
> @@ -798,8 +798,8 @@ static int hp_wmi_get_tablet_mode(void)
>  	ret = hp_wmi_perform_query(HPWMI_SYSTEM_DEVICE_MODE, HPWMI_READ,
>  				   system_device_mode, zero_if_sup(system_device_mode),
>  				   sizeof(system_device_mode));
> -	if (ret < 0)
> -		return ret;
> +	if (ret)
> +		return ret < 0 ? ret : -EINVAL;

Please use 2 separate ifs for clarity.

>  	return system_device_mode[0] == DEVICE_MODE_TABLET;
>  }
> @@ -1198,7 +1198,7 @@ static void hp_wmi_notify(union acpi_object *obj, void *context)
>  {
>  	u32 event_id, event_data;
>  	u32 *location;
> -	int key_code;
> +	int key_code, state;
>  
>  	if (!obj)
>  		return;
> @@ -1228,9 +1228,12 @@ static void hp_wmi_notify(union acpi_object *obj, void *context)
>  		if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit))
>  			input_report_switch(hp_wmi_input_dev, SW_DOCK,
>  					    hp_wmi_get_dock_state());
> -		if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit))
> -			input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
> -					    hp_wmi_get_tablet_mode());
> +		if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit)) {
> +			state = hp_wmi_get_tablet_mode();
> +			if (state >= 0)
> +				input_report_switch(hp_wmi_input_dev,
> +						    SW_TABLET_MODE, state);

Braces are needed for multiline constructs...

...BUT, it looks there's some copy pasting going on so moving these into a 
helper both this and hp_wmi_resume_handler() could use would seem useful 
(in a preparatory patch). It would help with the line length so this may 
no longer require multiple lines with less indent.

> +		}
>  		input_sync(hp_wmi_input_dev);
>  		break;
>  	case HPWMI_PARK_HDD:
> @@ -2431,6 +2434,8 @@ static void __exit hp_wmi_bios_remove(struct platform_device *device)
>  
>  static int hp_wmi_resume_handler(struct device *device)
>  {
> +	int state;
> +
>  	/*
>  	 * Hardware state may have changed while suspended, so trigger
>  	 * input events for the current state. As this is a switch,
> @@ -2441,9 +2446,12 @@ static int hp_wmi_resume_handler(struct device *device)
>  		if (test_bit(SW_DOCK, hp_wmi_input_dev->swbit))
>  			input_report_switch(hp_wmi_input_dev, SW_DOCK,
>  					    hp_wmi_get_dock_state());
> -		if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit))
> -			input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
> -					    hp_wmi_get_tablet_mode());
> +		if (test_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit)) {
> +			state = hp_wmi_get_tablet_mode();
> +			if (state >= 0)
> +				input_report_switch(hp_wmi_input_dev,
> +						    SW_TABLET_MODE, state);
> +		}
>  		input_sync(hp_wmi_input_dev);
>  	}
>  
> 

-- 
 i.


  reply	other threads:[~2026-07-21 15:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-16  9:54 [PATCH 0/5] platform/x86: hp-wmi: Fix WMI error handling Emre Cecanpunar
2026-07-16  9:54 ` [PATCH 1/5] platform/x86: hp-wmi: validate WMI response header size Emre Cecanpunar
2026-07-21 15:42   ` Ilpo Järvinen
2026-07-16  9:54 ` [PATCH 2/5] platform/x86: hp-wmi: handle firmware errors in tablet mode query Emre Cecanpunar
2026-07-21 15:50   ` Ilpo Järvinen [this message]
2026-07-16  9:54 ` [PATCH 3/5] platform/x86: hp-wmi: handle errors in the OMEN key event Emre Cecanpunar
2026-07-21 15:52   ` Ilpo Järvinen
2026-07-16  9:54 ` [PATCH 4/5] platform/x86: hp-wmi: normalize GPU thermal mode errors Emre Cecanpunar
2026-07-21 15:57   ` Ilpo Järvinen
2026-07-16  9:54 ` [PATCH 5/5] platform/x86: hp-wmi: report fan speed command failures Emre Cecanpunar
2026-07-21 15:58   ` Ilpo Järvinen
2026-07-21 16:14 ` [PATCH 0/5] platform/x86: hp-wmi: Fix WMI error handling Emre Cecanpunar
2026-07-21 16:15 ` Emre Cecanpunar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cd06d831-01d6-c8a2-94fc-894877f56c3d@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=edip@medip.dev \
    --cc=emreleno@gmail.com \
    --cc=hansg@kernel.org \
    --cc=hello@kursatabayli.dev \
    --cc=jes965@nyu.edu \
    --cc=jorge.lopez2@hp.com \
    --cc=julien.robin28@free.fr \
    --cc=krishna.chomal108@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=mjg59@srcf.ucam.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=radheykalra901@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.