From 87a7c09a9d4092782820d2c28c09df1d85d4cd93 Mon Sep 17 00:00:00 2001 From: Rong Zhang Date: Mon, 19 Oct 2026 23:02:33 +0800 Subject: [PATCH] platform/x86: lenovo-wmi-helpers: Adopt new WMI API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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"). Suggested-by: Armin Wolf Link: https://lore.kernel.org/r/f1787927-b655-4321-b9d9-bc12353c72db@gmx.de/ Reviewed-by: Armin Wolf Tested-by: Navon John Lukose Reviewed-by: Derek J. Clark Reviewed-by: Mark Pearson Signed-off-by: Rong Zhang Link: https://patch.msgid.link/20261019-lwmi-wmi-new-api-v5-11-71557d28d058@rong.moe Reviewed-by: Ilpo Järvinen Signed-off-by: Ilpo Järvinen --- drivers/platform/x86/lenovo/wmi-helpers.c | 53 ++++++++--------------- 1 file changed, 19 insertions(+), 34 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 #include #include -#include #include +#include + #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; + struct wmi_buffer input = { + .length = size, + .data = buf, + }; + struct wmi_buffer output; + int ret; - status = wmidev_evaluate_method(wdev, instance, method_id, &input, - &output); - if (ACPI_FAILURE(status)) - return -EIO; + if (!retval) + return wmidev_invoke_procedure(wdev, instance, method_id, &input); - union acpi_object *ret_obj __free(kfree) = output.pointer; + ret = wmidev_invoke_method(wdev, instance, method_id, &input, + &output, sizeof(__le32)); + if (ret) + return ret; - if (retval) { - if (!ret_obj) - return -ENODATA; + __le32 *valp __free(kfree) = output.data; - 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; - } - } + *retval = le32_to_cpu(*valp); return 0; };