[PATCH v5 1/3] platform/asus: asus-wmi: decode integer replies in buffer helper

From: Bartu Alev

Date: Tue Nov 17 2026 - 05:31:35 EST


asus_wmi_evaluate_method_buf() casts the ACPI integer it receives on a
non-buffer reply straight into its int return value. A status word
with bit 31 set therefore aliases a negative errno: 0xffffffff, for
example, reaches the caller as -EPERM.

Decode the integer through a u32 first. Map ASUS_WMI_UNSUPPORTED_METHOD
(0xfffffffe) and 0xffffffff to -ENODEV, matching what
asus_wmi_get_devstate() does for ~0, and map every other integer to
-ENODATA like the unhandled object types, since this helper is only
meant for buffer replies. Buffer replies still return 0, and a missing
ACPI output object now fails cleanly with -ENODATA instead of
dereferencing NULL.

The only current caller, fan_curve_get_factory_default(), logs and
returns non-zero errors to its callers; fan_curve_enable_store()
propagates them to sysfs, so any unexpected integer reply now
surfaces as a proper negative errno rather than a raw positive value
or -EPERM, while fan_curve_check_present() still treats any non-zero
return as unavailable.

Add kernel-doc for the parameters and error returns as well.

Link: https://lore.kernel.org/all/20261029-asus-tuf-rgb-v4-v4-0-0d3b877d2c30@xxxxxxxxx/
Suggested-by: Denis Benato <denis.benato@xxxxxxxxx>
Signed-off-by: Bartu Alev <bartualev@xxxxxxxxx>
---
drivers/platform/asus/asus-wmi.c | 40 +++++++++++++++++++++++++++++++---------
1 file changed, 31 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/asus/asus-wmi.c b/drivers/platform/asus/asus-wmi.c
index b33ebdb21aa21..4d844f914f77e 100644
--- a/drivers/platform/asus/asus-wmi.c
+++ b/drivers/platform/asus/asus-wmi.c
@@ -461,9 +461,25 @@ static int asus_wmi_evaluate_method5(u32 method_id,
return 0;
}

-/*
- * Returns as an error if the method output is not a buffer. Typically this
- * means that the method called is unsupported.
+/**
+ * asus_wmi_evaluate_method_buf() - Evaluate a WMI method with a buffer reply
+ * @method_id: The WMI method ID to evaluate
+ * @arg0: The first argument passed to the method
+ * @arg1: The second argument passed to the method
+ * @ret_buffer: Buffer to copy the returned ACPI buffer into
+ * @size: Size of @ret_buffer in bytes
+ *
+ * Evaluate a WMI method and copy its output buffer into @ret_buffer.
+ * The reply must be an ACPI buffer: a buffer larger than @size is not
+ * copied and returns %-ENOSPC, and an empty buffer returns %-ENODATA.
+ *
+ * Integer replies carry no buffer: %ASUS_WMI_UNSUPPORTED_METHOD
+ * (%0xfffffffe) and %0xffffffff map to %-ENODEV, while any other integer
+ * (such as %0 returned by %ASUS_WMI_DEVID_CPU_FAN_CURVE when no argument
+ * is provided) maps to %-ENODATA like any other non-buffer reply.
+ *
+ * Return: %0 on success, or a negative errno (%-EIO, %-ENODEV,
+ * %-ENODATA, %-ENOSPC) on failure.
*/
static int asus_wmi_evaluate_method_buf(u32 method_id,
u32 arg0, u32 arg1, u8 *ret_buffer, size_t size)
@@ -477,6 +493,7 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
acpi_status status;
union acpi_object *obj;
+ u32 retval;
int err = 0;

status = asus_wmi_evaluate_method_locked(method_id, &input, &output);
@@ -490,6 +507,8 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
}

obj = (union acpi_object *)output.pointer;
+ if (!obj)
+ return -ENODATA;

switch (obj->type) {
case ACPI_TYPE_BUFFER:
@@ -505,15 +524,18 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
memcpy(ret_buffer, obj->buffer.pointer, obj->buffer.length);
break;
case ACPI_TYPE_INTEGER:
- err = (u32)obj->integer.value;
+ retval = (u32)obj->integer.value;

- if (err == ASUS_WMI_UNSUPPORTED_METHOD)
- err = -ENODEV;
/*
- * At least one method returns a 0 with no buffer if no arg
- * is provided, such as ASUS_WMI_DEVID_CPU_FAN_CURVE
+ * Also map 0xffffffff to -ENODEV (matching
+ * asus_wmi_get_devstate()) so bit-31 values cannot alias
+ * negative errnos. Any other integer is not a buffer reply,
+ * such as the 0 returned by ASUS_WMI_DEVID_CPU_FAN_CURVE
+ * when no arg is provided.
*/
- if (err == 0)
+ if (retval == ASUS_WMI_UNSUPPORTED_METHOD || retval == ~0U)
+ err = -ENODEV;
+ else
err = -ENODATA;
break;
default:

--
2.56.0