From: "Mark Pearson" <mpearson-lenovo@squebb.ca>
To: "Rong Zhang" <i@rong.moe>,
"Derek J . Clark" <derekjohn.clark@gmail.com>,
"Armin Wolf" <W_Armin@gmx.de>, "Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: "Guenter Roeck" <linux@roeck-us.net>,
"Kurt Borja" <kuurtb@gmail.com>,
"platform-driver-x86@vger.kernel.org"
<platform-driver-x86@vger.kernel.org>,
linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v11 1/7] platform/x86: lenovo-wmi-helpers: Convert returned buffer into u32
Date: Thu, 22 Jan 2026 13:51:25 -0500 [thread overview]
Message-ID: <94a3798f-c6da-4b26-b082-d1b56d059019@app.fastmail.com> (raw)
In-Reply-To: <20260120182104.163424-2-i@rong.moe>
On Tue, Jan 20, 2026, at 1:20 PM, Rong Zhang wrote:
> The Windows WMI-ACPI driver converts all ACPI objects into a common
> buffer format, so returning a buffer with four bytes will look like an
> integer for WMI consumers under Windows.
>
> Therefore, some devices may simply implement the corresponding ACPI
> methods to always return a buffer. While lwmi_dev_evaluate_int() expects
> an integer (u32), convert returned >=4B buffer into u32 to support these
> devices.
>
> Suggested-by: Armin Wolf <W_Armin@gmx.de>
> Link: https://lore.kernel.org/r/f1787927-b655-4321-b9d9-bc12353c72db@gmx.de/
> Signed-off-by: Rong Zhang <i@rong.moe>
> Reviewed-by: Derek J. Clark <derekjohn.clark@gmail.com>
> Tested-by: Derek J. Clark <derekjohn.clark@gmail.com>
> Reviewed-by: Armin Wolf <W_Armin@gmx.de>
> ---
> Changes in v7:
> - Fix mistakenly inverted boundary check
>
> Changes in v4:
> - Accept oversized buffer (thanks Armin Wolf)
> - Use get_unaligned_le32() (ditto)
>
> Changes in v2:
> - New patch (thanks Armin Wolf)
> ---
> drivers/platform/x86/lenovo/wmi-helpers.c | 21 ++++++++++++++++++---
> 1 file changed, 18 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/wmi-helpers.c
> b/drivers/platform/x86/lenovo/wmi-helpers.c
> index f6fef6296251e..7379defac5002 100644
> --- a/drivers/platform/x86/lenovo/wmi-helpers.c
> +++ b/drivers/platform/x86/lenovo/wmi-helpers.c
> @@ -21,6 +21,7 @@
> #include <linux/errno.h>
> #include <linux/export.h>
> #include <linux/module.h>
> +#include <linux/unaligned.h>
> #include <linux/wmi.h>
>
> #include "wmi-helpers.h"
> @@ -59,10 +60,24 @@ int lwmi_dev_evaluate_int(struct wmi_device *wdev,
> u8 instance, u32 method_id,
> if (!ret_obj)
> return -ENODATA;
>
> - if (ret_obj->type != ACPI_TYPE_INTEGER)
> - return -ENXIO;
> + switch (ret_obj->type) {
> + /*
> + * The ACPI method may simply return a buffer when a u32
> + * is expected. This is valid on Windows as its WMI-ACPI
> + * driver converts everything to a common buffer.
> + */
> + case ACPI_TYPE_BUFFER:
> + if (ret_obj->buffer.length < sizeof(u32))
> + return -ENXIO;
>
> - *retval = (u32)ret_obj->integer.value;
> + *retval = get_unaligned_le32(ret_obj->buffer.pointer);
> + return 0;
> + case ACPI_TYPE_INTEGER:
> + *retval = (u32)ret_obj->integer.value;
> + return 0;
> + default:
> + return -ENXIO;
> + }
> }
>
> return 0;
> --
> 2.51.0
Looks good to me.
As an aside, you've answered a question that was puzzling me for something we're working on internally as to why the Windows dev team hadn't complained about different formats between platforms for their implementations (which was causing me a ton of pain). Now it all makes sense!
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
next prev parent reply other threads:[~2026-01-22 18:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-20 18:20 [PATCH v11 0/7] platform/x86: lenovo-wmi-{capdata,other}: Add HWMON for fan speed Rong Zhang
2026-01-20 18:20 ` [PATCH v11 1/7] platform/x86: lenovo-wmi-helpers: Convert returned buffer into u32 Rong Zhang
2026-01-22 18:51 ` Mark Pearson [this message]
2026-01-20 18:20 ` [PATCH v11 2/7] platform/x86: Rename lenovo-wmi-capdata01 to lenovo-wmi-capdata Rong Zhang
2026-01-22 18:51 ` Mark Pearson
2026-01-20 18:20 ` [PATCH v11 3/7] platform/x86: lenovo-wmi-{capdata,other}: Support multiple Capability Data Rong Zhang
2026-01-22 18:53 ` Mark Pearson
2026-01-20 18:20 ` [PATCH v11 4/7] platform/x86: lenovo-wmi-capdata: Add support for Capability Data 00 Rong Zhang
2026-01-22 18:53 ` Mark Pearson
2026-01-20 18:20 ` [PATCH v11 5/7] platform/x86: lenovo-wmi-capdata: Add support for Fan Test Data Rong Zhang
2026-01-22 18:53 ` Mark Pearson
2026-01-20 18:20 ` [PATCH v11 6/7] platform/x86: lenovo-wmi-capdata: Wire up " Rong Zhang
2026-01-20 18:20 ` [PATCH v11 7/7] platform/x86: lenovo-wmi-other: Add HWMON for fan reporting/tuning Rong Zhang
2026-01-22 14:32 ` [PATCH v11 0/7] platform/x86: lenovo-wmi-{capdata,other}: Add HWMON for fan speed Ilpo Järvinen
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=94a3798f-c6da-4b26-b082-d1b56d059019@app.fastmail.com \
--to=mpearson-lenovo@squebb.ca \
--cc=W_Armin@gmx.de \
--cc=derekjohn.clark@gmail.com \
--cc=hansg@kernel.org \
--cc=i@rong.moe \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=kuurtb@gmail.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=platform-driver-x86@vger.kernel.org \
/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
all inboxes | Powered by JetHome®