platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rong Zhang <i@rong.moe>
To: "Armin Wolf" <W_Armin@gmx.de>,
	"Mark Pearson" <mpearson-lenovo@squebb.ca>,
	"Derek J. Clark" <derekjohn.clark@gmail.com>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: Guenter Roeck <linux@roeck-us.net>,
	platform-driver-x86@vger.kernel.org,
		linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org
Subject: Re: [PATCH v3 1/6] platform/x86: lenovo-wmi-helpers: Convert returned 4B buffer into u32
Date: Wed, 05 Nov 2025 04:27:14 +0800	[thread overview]
Message-ID: <615beafaf18edfcf441d62a81c847f7624eef13c.camel@rong.moe> (raw)
In-Reply-To: <a0b6d30b-3cba-4760-81dc-099e8fada7c0@gmx.de>

Hi Armin,

On Tue, 2025-11-04 at 21:13 +0100, Armin Wolf wrote:
> Am 31.10.25 um 16:51 schrieb Rong Zhang:
> 
> > 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 4-byte 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>
> > ---
> > 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 f6fef6296251..f3bc92ac505a 100644
> > --- a/drivers/platform/x86/lenovo/wmi-helpers.c
> > +++ b/drivers/platform/x86/lenovo/wmi-helpers.c
> > @@ -59,10 +59,25 @@ 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 4-byte buffer when a u32
> > +		 * integer 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 != 4)
> > +				return -ENXIO;
> 
> The Windows driver also accepts oversized buffers. I suggest that you follow this behavior
> for the sake of compatibility.
> 
> >   
> > -		*retval = (u32)ret_obj->integer.value;
> > +			*retval = *((u32 *)ret_obj->buffer.pointer);
> 
> The buffer can be unaligned. Better use get_unaligned_le32() from linux/unaligned.h.

Thanks for your review and information. Will do in v4.

> Thanks,
> Armin Wolf

Thanks,
Rong

> > +			return 0;
> > +		}
> > +		case ACPI_TYPE_INTEGER:
> > +			*retval = (u32)ret_obj->integer.value;
> > +			return 0;
> > +		default:
> > +			return -ENXIO;
> > +		}
> >   	}
> >   
> >   	return 0;

  reply	other threads:[~2025-11-04 20:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-31 15:51 [PATCH v3 0/6] platform/x86: lenovo-wmi-{capdata,other}: Add HWMON for fan speed Rong Zhang
2025-10-31 15:51 ` [PATCH v3 1/6] platform/x86: lenovo-wmi-helpers: Convert returned 4B buffer into u32 Rong Zhang
2025-11-04 20:13   ` Armin Wolf
2025-11-04 20:27     ` Rong Zhang [this message]
2025-10-31 15:51 ` [PATCH v3 2/6] platform/x86: Rename lenovo-wmi-capdata01 to lenovo-wmi-capdata Rong Zhang
2025-10-31 15:51 ` [PATCH v3 3/6] platform/x86: lenovo-wmi-{capdata,other}: Support multiple Capability Data Rong Zhang
2025-11-04 20:20   ` Armin Wolf
2025-11-04 20:43     ` Rong Zhang
2025-11-06 12:36     ` Rong Zhang
2025-11-10  0:02       ` Armin Wolf
2025-11-10 17:40         ` Rong Zhang
2025-10-31 15:51 ` [PATCH v3 4/6] platform/x86: lenovo-wmi-capdata: Add support for Capability Data 00 Rong Zhang
2025-10-31 15:51 ` [PATCH v3 5/6] platform/x86: lenovo-wmi-capdata: Add support for Fan Test Data Rong Zhang
2025-10-31 15:51 ` [PATCH v3 6/6] platform/x86: lenovo-wmi-other: Add HWMON for fan speed RPM Rong Zhang

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=615beafaf18edfcf441d62a81c847f7624eef13c.camel@rong.moe \
    --to=i@rong.moe \
    --cc=W_Armin@gmx.de \
    --cc=derekjohn.clark@gmail.com \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=mpearson-lenovo@squebb.ca \
    --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;
as well as URLs for NNTP newsgroup(s).