mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Armin Wolf <W_Armin@gmx.de>
To: "Rong Zhang" <i@rong.moe>,
	"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: Charles <hanker007@gmail.com>,
	Navon John Lukose <navonjohnlukose@gmail.com>,
	platform-driver-x86@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 11/12] platform/x86: lenovo-wmi-helpers: Adopt new WMI API
Date: Sat, 10 Oct 2026 03:19:45 +0200	[thread overview]
Message-ID: <bb1e3abe-5dac-4f91-b5bf-0aac276ec68e@gmx.de> (raw)
In-Reply-To: <20261009-lwmi-wmi-new-api-v2-11-402828382679@rong.moe>

Am 09.10.26 um 14:53 schrieb Rong Zhang:

> The new WMI API supports multiple ACPI types by converting them into a
> unified buffer that satisfies alignment and size requirements.
>
> Adopt it to make our life easier.
>
> Note that the Windows WMI-ACPI driver converts all ACPI objects into a
> common buffer format, so adopting the new API intentionally accepts more
> ACPI types as a followup of commit 465dc9da8ff6 ("platform/x86:
> lenovo-wmi-helpers: Convert returned buffer into u32").

Reviewed-by: Armin Wolf <W_Armin@gmx.de>

> 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>
> ---
>   drivers/platform/x86/lenovo/wmi-helpers.c | 61 ++++++++++++-------------------
>   1 file changed, 23 insertions(+), 38 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/wmi-helpers.c b/drivers/platform/x86/lenovo/wmi-helpers.c
> index 8f5766c391eb..687caa226263 100644
> --- a/drivers/platform/x86/lenovo/wmi-helpers.c
> +++ b/drivers/platform/x86/lenovo/wmi-helpers.c
> @@ -24,9 +24,10 @@
>   #include <linux/export.h>
>   #include <linux/module.h>
>   #include <linux/notifier.h>
> -#include <linux/unaligned.h>
>   #include <linux/wmi.h>
>   
> +#include <asm/byteorder.h>
> +
>   #include "wmi-helpers.h"
>   
>   /* Thermal mode notifier chain. */
> @@ -42,49 +43,33 @@ static BLOCKING_NOTIFIER_HEAD(tm_chain_head);
>    * @size: Length of the buffer.
>    * @retval: Pointer for the return value to be assigned.
>    *
> - * Calls wmidev_evaluate_method for Lenovo WMI devices that return an ACPI
> - * integer. Validates the return value type and assigns the value to the
> - * retval pointer.
> + * Calls the specified WMI method for Lenovo WMI devices that return a WMI
> + * integer. Validates the return value and assigns it to @retval when it's not
> + * NULL, otherwise the return value is not validated.
>    *
>    * Return: 0 on success, or an error code.
>    */
>   int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method_id,
>   			  unsigned char *buf, size_t size, u32 *retval)
>   {
> -	struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
> -	struct acpi_buffer input = { size, buf };
> -	acpi_status status;
> -
> -	status = wmidev_evaluate_method(wdev, instance, method_id, &input,
> -					&output);
> -	if (ACPI_FAILURE(status))
> -		return -EIO;
> -
> -	union acpi_object *ret_obj __free(kfree) = output.pointer;
> -
> -	if (retval) {
> -		if (!ret_obj)
> -			return -ENODATA;
> -
> -		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 = get_unaligned_le32(ret_obj->buffer.pointer);
> -			return 0;
> -		case ACPI_TYPE_INTEGER:
> -			*retval = (u32)ret_obj->integer.value;
> -			return 0;
> -		default:
> -			return -ENXIO;
> -		}
> -	}
> +	struct wmi_buffer input = {
> +		.length = size,
> +		.data = buf,
> +	};
> +	struct wmi_buffer output;
> +	int ret;
> +
> +	if (!retval)
> +		return wmidev_invoke_procedure(wdev, instance, method_id, &input);
> +
> +	ret = wmidev_invoke_method(wdev, instance, method_id, &input,
> +				   &output, sizeof(__le32));
> +	if (ret)
> +		return ret;
> +
> +	__le32 *valp __free(kfree) = output.data;
> +
> +	*retval = le32_to_cpu(*valp);
>   
>   	return 0;
>   };
>

  reply	other threads:[~2026-10-10  1:19 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-09 12:53 [PATCH v2 00/12] platform/x86: lenovo-wmi-{other,capdata,helpers}: Improve robustness on faulty firmware Rong Zhang
2026-10-09 12:53 ` [PATCH v2 01/12] platform/wmi: Introduce wmidev_exists() Rong Zhang
2026-10-09 20:25   ` Mark Pearson
2026-10-09 12:53 ` [PATCH v2 02/12] platform/x86: lenovo-wmi-capdata: Do not stop the AC notifier chain on error Rong Zhang
2026-10-09 12:53 ` [PATCH v2 03/12] platform/x86: lenovo-wmi-capdata: Only allocate sub-master info when necessary Rong Zhang
2026-10-09 15:15   ` Derek J. Clark
2026-10-09 15:45     ` Rong Zhang
2026-10-09 12:53 ` [PATCH v2 04/12] platform/x86: lenovo-wmi-capdata: Store a pointer to component info Rong Zhang
2026-10-09 12:53 ` [PATCH v2 05/12] platform/x86: lenovo-wmi-capdata: Defer mutex initialization Rong Zhang
2026-10-09 12:53 ` [PATCH v2 06/12] platform/x86: lenovo-wmi-{capdata,other}: Only allocate capdata list when necessary Rong Zhang
2026-10-09 12:53 ` [PATCH v2 07/12] platform/x86: lenovo-wmi-capdata: Adopt new WMI API Rong Zhang
2026-10-10  1:16   ` Armin Wolf
2026-10-10  1:51     ` Rong Zhang
2026-10-09 12:53 ` [PATCH v2 08/12] platform/x86: lenovo-wmi-capdata: Register component even on WMI error Rong Zhang
2026-10-09 12:53 ` [PATCH v2 09/12] platform/x86: lenovo-wmi-capdata: Detect stubbed capdata device Rong Zhang
2026-10-09 12:53 ` [PATCH v2 10/12] platform/x86: lenovo-wmi-capdata: Do not match missing components Rong Zhang
2026-10-09 12:53 ` [PATCH v2 11/12] platform/x86: lenovo-wmi-helpers: Adopt new WMI API Rong Zhang
2026-10-10  1:19   ` Armin Wolf [this message]
2026-10-09 12:53 ` [PATCH v2 12/12] MAINTAINERS: Add myself as a LENOVO drivers co-maintainer Rong Zhang
2026-10-09 20:26   ` Mark Pearson
2026-10-09 23:01 ` [PATCH v2 00/12] platform/x86: lenovo-wmi-{other,capdata,helpers}: Improve robustness on faulty firmware Derek J. Clark

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=bb1e3abe-5dac-4f91-b5bf-0aac276ec68e@gmx.de \
    --to=w_armin@gmx.de \
    --cc=derekjohn.clark@gmail.com \
    --cc=hanker007@gmail.com \
    --cc=hansg@kernel.org \
    --cc=i@rong.moe \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mpearson-lenovo@squebb.ca \
    --cc=navonjohnlukose@gmail.com \
    --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®