Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

platform/x86: lenovo-wmi-helpers: Convert returned buffer into u32

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>
Link: https://patch.msgid.link/20260120182104.163424-2-i@rong.moe
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

authored by

Rong Zhang and committed by
Ilpo Järvinen
465dc9da 2177a022

+18 -3
+18 -3
drivers/platform/x86/lenovo/wmi-helpers.c
··· 21 21 #include <linux/errno.h> 22 22 #include <linux/export.h> 23 23 #include <linux/module.h> 24 + #include <linux/unaligned.h> 24 25 #include <linux/wmi.h> 25 26 26 27 #include "wmi-helpers.h" ··· 60 59 if (!ret_obj) 61 60 return -ENODATA; 62 61 63 - if (ret_obj->type != ACPI_TYPE_INTEGER) 64 - return -ENXIO; 62 + switch (ret_obj->type) { 63 + /* 64 + * The ACPI method may simply return a buffer when a u32 65 + * is expected. This is valid on Windows as its WMI-ACPI 66 + * driver converts everything to a common buffer. 67 + */ 68 + case ACPI_TYPE_BUFFER: 69 + if (ret_obj->buffer.length < sizeof(u32)) 70 + return -ENXIO; 65 71 66 - *retval = (u32)ret_obj->integer.value; 72 + *retval = get_unaligned_le32(ret_obj->buffer.pointer); 73 + return 0; 74 + case ACPI_TYPE_INTEGER: 75 + *retval = (u32)ret_obj->integer.value; 76 + return 0; 77 + default: 78 + return -ENXIO; 79 + } 67 80 } 68 81 69 82 return 0;