The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "孙 誉铭" <wolf109909@outlook.com>
Cc: "platform-driver-x86@vger.kernel.org"
	<platform-driver-x86@vger.kernel.org>,
	 "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	 Mingyou Chen <qby140326@gmail.com>, Armin Wolf <W_Armin@gmx.de>,
	 Hans de Goede <hansg@kernel.org>,
	Nabil Danial <nabildanial.93@gmail.com>
Subject: Re: [RESEND PATCH 1/5] platform/x86: bitland-mifs-wmi: validate WMAA status, never abort suspend
Date: Mon, 24 Aug 2026 18:42:43 +0300 (EEST)	[thread overview]
Message-ID: <bc7a6576-54da-1517-5d0c-adbb3d77fa78@linux.intel.com> (raw)
In-Reply-To: <20260728180944.51356-2-wolf109909@outlook.com>

[-- Attachment #1: Type: text/plain, Size: 4081 bytes --]

On Tue, 28 Jul 2026, 孙 誉铭 wrote:

> The WMAA firmware method signals "unknown/unsupported function" with
> the status word 0xe000 in the reply. The driver never checked it, so
> calls to functions a given firmware revision does not implement
> silently returned zero-filled data instead of failing.
> 
> Worse, the platform_profile suspend hook propagated such errors: on
> firmware whose perf-mode query returns values laptop_profile_get()
> cannot map (e.g. MIFS v2 firmware reporting raw QFAN codes, seen on
> Xiaomi Book Pro 14 2026 and REDMI Book Pro 14 2025), every suspend
> attempt died with:
> 
>   dpm_run_callback(): bitland_mifs_wmi_suspend returns -22
>   PM: Some devices failed to suspend, or early wake event detected
> 
> Return -EOPNOTSUPP when the firmware reports the error status word,
> and make the suspend/resume hooks fault-tolerant: skip saving and
> restoring the profile when the query fails instead of aborting the
> whole system sleep.
> 
> Status word semantics verified against the laptop's SSDT WMAA method
> (SGER=0x8000 on success, 0xe000 in the Default branch).
> 
> Signed-off-by: Yuming Sun <wolf109909@outlook.com>
> ---
>  drivers/platform/x86/bitland-mifs-wmi.c | 31 +++++++++++++++++++++----
>  1 file changed, 27 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/platform/x86/bitland-mifs-wmi.c b/drivers/platform/x86/bitland-mifs-wmi.c
> index 3a373184..12426d11 100644
> --- a/drivers/platform/x86/bitland-mifs-wmi.c
> +++ b/drivers/platform/x86/bitland-mifs-wmi.c
> @@ -129,6 +129,18 @@ struct bitland_mifs_output {
>  	u8 data[28];
>  } __packed;
>  
> +/*
> + * The status word of a WMAA reply is formed by the first two bytes
> + * (reserved1 | operation << 8). MIFS firmware signals "unknown or
> + * unsupported function" with 0xe000 and success with 0x8000.
> + */
> +#define MIFS_STATUS_ERROR	0xe000
> +
> +static u16 mifs_status(const struct bitland_mifs_output *out)
> +{
> +	return out->reserved1 | (out->operation << 8);

How about using union inside the struct and a type that annotates the 
endianness + endianness accessor to read it here?

> +}
> +
>  struct bitland_mifs_event {
>  	u8 event_type;
>  	u8 event_id;
> @@ -159,6 +171,7 @@ struct bitland_mifs_wmi_data {
>  	struct device *hwmon_dev;
>  	struct device *pp_dev;
>  	enum platform_profile_option saved_profile;
> +	bool profile_valid;
>  };
>  
>  static int bitland_mifs_wmi_call(struct bitland_mifs_wmi_data *data,
> @@ -181,6 +194,9 @@ static int bitland_mifs_wmi_call(struct bitland_mifs_wmi_data *data,
>  	memcpy(output, out_buf.data, sizeof(*output));
>  	kfree(out_buf.data);
>  
> +	if (mifs_status(output) == MIFS_STATUS_ERROR)
> +		return -EOPNOTSUPP;
> +
>  	return 0;
>  }
>  
> @@ -298,17 +314,21 @@ static int bitland_mifs_wmi_suspend(struct device *dev)
>  {
>  	struct bitland_mifs_wmi_data *data = dev_get_drvdata(dev);
>  	enum platform_profile_option profile;
> -	int ret;
>  
>  	/* Skip event device */
>  	if (!data->pp_dev)
>  		return 0;
>  
> -	ret = laptop_profile_get(data->pp_dev, &profile);
> -	if (ret == 0)
> +	/*
> +	 * Never abort suspend: some firmware revisions answer the perf-mode
> +	 * query with values this driver cannot map, or fail the call
> +	 * entirely while the system is going down.
> +	 */
> +	data->profile_valid = laptop_profile_get(data->pp_dev, &profile) == 0;
> +	if (data->profile_valid)

This code makes no sense to me. laptop_profile_get() can return error 
codes so how come can profile be "valid" in that case?

>  		data->saved_profile = profile;
>  
> -	return ret;
> +	return 0;
>  }
>  
>  static int bitland_mifs_wmi_resume(struct device *dev)
> @@ -319,6 +339,9 @@ static int bitland_mifs_wmi_resume(struct device *dev)
>  	if (!data->pp_dev)
>  		return 0;
>  
> +	if (!data->profile_valid)
> +		return 0;
> +
>  	dev_dbg(dev, "Resuming, restoring profile %d\n", data->saved_profile);
>  	return laptop_profile_set(dev, data->saved_profile);
>  }
> 

-- 
 i.

  reply	other threads:[~2026-08-24 15:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-28 18:09 [RESEND PATCH 0/5] platform/x86: bitland-mifs-wmi: MIFS v2 firmware support (Xiaomi Book Pro 14 2026) 孙 誉铭
2026-07-28 18:09 ` [RESEND PATCH 1/5] platform/x86: bitland-mifs-wmi: validate WMAA status, never abort suspend 孙 誉铭
2026-08-24 15:42   ` Ilpo Järvinen [this message]
2026-07-28 18:09 ` [RESEND PATCH 2/5] platform/x86: bitland-mifs-wmi: support MIFS v2 perf-mode mapping 孙 誉铭
2026-07-30 10:56   ` Mingyou Chen
2026-08-16 22:18   ` kento
2026-07-28 18:10 ` [RESEND PATCH 3/5] platform/x86: bitland-mifs-wmi: read fan tach from EC window on MIFS v2 孙 誉铭
2026-08-24 15:48   ` Ilpo Järvinen
2026-07-28 18:10 ` [RESEND PATCH 4/5] platform/x86: bitland-mifs-wmi: drive lid switch via EC poll on Xiaomi Book Pro 14 孙 誉铭
2026-08-24 16:00   ` Ilpo Järvinen
2026-07-28 18:10 ` [RESEND PATCH 5/5] Documentation: wmi: bitland-mifs-wmi: document MIFS v2 firmware variant 孙 誉铭
2026-07-30  9:24 ` [RESEND PATCH 0/5] platform/x86: bitland-mifs-wmi: MIFS v2 firmware support (Xiaomi Book Pro 14 2026) Armin Wolf

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=bc7a6576-54da-1517-5d0c-adbb3d77fa78@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=W_Armin@gmx.de \
    --cc=hansg@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nabildanial.93@gmail.com \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=qby140326@gmail.com \
    --cc=wolf109909@outlook.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox