* [PATCH 0/3] platform/asus: asus-wmi: harden asus_wmi_evaluate_method_buf()
@ 2026-12-01 23:31 Bartu Alev
2026-12-01 23:31 ` [PATCH 1/3] platform/asus: asus-wmi: Fix NULL deref and integer handling in asus_wmi_evaluate_method_buf() Bartu Alev
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Bartu Alev @ 2026-12-01 23:31 UTC (permalink / raw)
To: Corentin Chary, Luke D. Jones, Denis Benato, Hans de Goede,
Ilpo Järvinen
Cc: platform-driver-x86, linux-kernel, Bartu Alev, stable
During review of the TUF keyboard RGB readback series [1] (and earlier
noted in the fan floor series [2]), two defects and follow-up cleanup
opportunities were identified in asus_wmi_evaluate_method_buf():
1. It dereferences output.pointer in switch (obj->type) without checking
for NULL, even though acpi_evaluate_object() returns AE_OK with
output.pointer == NULL when a method returns no object.
2. In the ACPI_TYPE_INTEGER case, it assigns the u32 firmware value
directly to signed int err. Values with bit 31 set alias negative
errnos (e.g., 0xffffffff becomes -EPERM), while positive integers
(such as ASUS_WMI_DSTS_UNKNOWN_BIT, 0x2, seen on ASUS hardware)
can propagate to sysfs/kernfs via fan_curve_enable_store() as a
positive byte count instead of an error.
This series separates those fixes from the TUF RGB readback feature and
splits the changes into three logical patches:
1. Fix the NULL dereference and integer decoding in plain C, using
manual kfree() and top-of-block declarations without touching the
asus_wmi_evaluate_method_locked() call site. Keeping this patch
free of cleanup.h (__free) dependencies allows it to apply cleanly
to active -stable trees down to 6.1 LTS.
2. Convert the helper to __free(kfree) and take ownership of
output.pointer immediately after asus_wmi_evaluate_method_locked().
This removes the out_free goto and also frees return_buffer->pointer
if ACPICA fails in acpi_ut_copy_iobject_to_eobject() after
acpi_ut_initialize_buffer() has already allocated it.
3. Add kernel-doc for asus_wmi_evaluate_method_buf(), documenting its
parameters, partial-copy behavior when replies are shorter than
@size, and all error returns as a ReST list.
[1] https://lore.kernel.org/all/20261029-asus-tuf-rgb-v4-v4-0-0d3b877d2c30@gmail.com/
[2] https://lore.kernel.org/all/20261101-asus-fan-floors-v4-v1-0-b8d1c31a99a9@gmail.com/
Signed-off-by: Bartu Alev <bartualev@gmail.com>
---
Bartu Alev (3):
platform/asus: asus-wmi: Fix NULL deref and integer handling in asus_wmi_evaluate_method_buf()
platform/asus: asus-wmi: Use __free(kfree) in asus_wmi_evaluate_method_buf()
platform/asus: asus-wmi: Document asus_wmi_evaluate_method_buf()
drivers/platform/asus/asus-wmi.c | 63 +++++++++++++++++++++++++++++++---------
1 file changed, 49 insertions(+), 14 deletions(-)
---
base-commit: f09fec5a32d43dd3f9e32d531d05422a9f6191d0
change-id: 20261202-asus-wmi-eval-buf-d97eb912c6d2
Best regards,
--
Bartu Alev <bartualev@gmail.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/3] platform/asus: asus-wmi: Fix NULL deref and integer handling in asus_wmi_evaluate_method_buf()
2026-12-01 23:31 [PATCH 0/3] platform/asus: asus-wmi: harden asus_wmi_evaluate_method_buf() Bartu Alev
@ 2026-12-01 23:31 ` Bartu Alev
2026-12-02 2:40 ` Denis Benato
2026-12-01 23:31 ` [PATCH 2/3] platform/asus: asus-wmi: Use __free(kfree) " Bartu Alev
2026-12-01 23:31 ` [PATCH 3/3] platform/asus: asus-wmi: Document asus_wmi_evaluate_method_buf() Bartu Alev
2 siblings, 1 reply; 10+ messages in thread
From: Bartu Alev @ 2026-12-01 23:31 UTC (permalink / raw)
To: Corentin Chary, Luke D. Jones, Denis Benato, Hans de Goede,
Ilpo Järvinen
Cc: platform-driver-x86, linux-kernel, Bartu Alev, stable
acpi_evaluate_object() reports AE_OK and leaves output.pointer NULL when
the evaluated WMI method returns no object at all, but
asus_wmi_evaluate_method_buf() dereferenced the pointer in
switch (obj->type) unconditionally, causing an oops during probe via
asus_wmi_custom_fan_curve_init() -> fan_curve_check_present() and on
writes to pwmN_enable via fan_curve_enable_store().
The ACPI_TYPE_INTEGER case also stored the firmware's u32 reply in the
signed int err. A value with bit 31 set therefore aliased a negative
errno (0xffffffff became -EPERM) and any other value leaked out as a
positive number: a DSTS reply carrying only ASUS_WMI_DSTS_UNKNOWN_BIT
(0x2), seen on ASUS hardware for unsupported device IDs, was returned as
+2 through fan_curve_enable_store() on writes of 2 and 3 to pwmN_enable,
which sysfs treats as a successful write. fan_curve_check_present()
swallows the error at probe, so only the NULL dereference is fatal
there.
Treat a missing object as -ENODATA, decode integer replies via u32 and
map ASUS_WMI_UNSUPPORTED_METHOD and 0xffffffff to -ENODEV, matching
asus_wmi_get_devstate(), and any other integer to -ENODATA. A survey of
102 ASUS DSDTs and the SMM path of a recent model found unsupported
methods answering 0xfffffffe or 0 rather than no object or 0xffffffff,
so both defects are latent rather than observed in the field.
Fixes: 0f0ac158d28ff ("platform/x86: asus-wmi: Add support for custom fan curves")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/228df241-da5e-49cb-b29f-6b9158557f55@gmail.com/
Signed-off-by: Bartu Alev <bartualev@gmail.com>
---
drivers/platform/asus/asus-wmi.c | 26 +++++++++++++++++++-------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git a/drivers/platform/asus/asus-wmi.c b/drivers/platform/asus/asus-wmi.c
index 552080ff5be25..4f74fdfd7a0c2 100644
--- a/drivers/platform/asus/asus-wmi.c
+++ b/drivers/platform/asus/asus-wmi.c
@@ -478,6 +478,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);
@@ -492,6 +493,15 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
obj = (union acpi_object *)output.pointer;
+ /*
+ * acpi_evaluate_object() reports AE_OK with a NULL buffer when the
+ * method returned no object at all.
+ */
+ if (!obj) {
+ err = -ENODATA;
+ goto out_free;
+ }
+
switch (obj->type) {
case ACPI_TYPE_BUFFER:
if (obj->buffer.length > size) {
@@ -506,15 +516,16 @@ 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;
-
- if (err == ASUS_WMI_UNSUPPORTED_METHOD)
- err = -ENODEV;
+ retval = (u32)obj->integer.value;
/*
- * At least one method returns a 0 with no buffer if no arg
- * is provided, such as ASUS_WMI_DEVID_CPU_FAN_CURVE
+ * ASUS_WMI_UNSUPPORTED_METHOD (0xfffffffe) and 0xffffffff
+ * mean the device or method is not implemented. Any other
+ * integer, such as the 0 some methods return when called
+ * without an argument, is not usable data either.
*/
- if (err == 0)
+ if (retval == ASUS_WMI_UNSUPPORTED_METHOD || retval == ~0U)
+ err = -ENODEV;
+ else
err = -ENODATA;
break;
default:
@@ -522,6 +533,7 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
break;
}
+out_free:
kfree(obj);
if (err) {
--
2.56.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/3] platform/asus: asus-wmi: Use __free(kfree) in asus_wmi_evaluate_method_buf()
2026-12-01 23:31 [PATCH 0/3] platform/asus: asus-wmi: harden asus_wmi_evaluate_method_buf() Bartu Alev
2026-12-01 23:31 ` [PATCH 1/3] platform/asus: asus-wmi: Fix NULL deref and integer handling in asus_wmi_evaluate_method_buf() Bartu Alev
@ 2026-12-01 23:31 ` Bartu Alev
2026-12-02 2:45 ` Denis Benato
2026-12-01 23:31 ` [PATCH 3/3] platform/asus: asus-wmi: Document asus_wmi_evaluate_method_buf() Bartu Alev
2 siblings, 1 reply; 10+ messages in thread
From: Bartu Alev @ 2026-12-01 23:31 UTC (permalink / raw)
To: Corentin Chary, Luke D. Jones, Denis Benato, Hans de Goede,
Ilpo Järvinen
Cc: platform-driver-x86, linux-kernel, Bartu Alev
Replace the manual kfree(obj) and the out_free: goto with a __free(kfree)
cleanup attribute, as include/linux/cleanup.h asks not to mix goto with
scope-based cleanup in the same routine.
Declare the buffer right after the evaluation and before the
ACPI_FAILURE(status) check, so that ownership is taken on every path.
This also covers a leak inside ACPICA: acpi_evaluate_object() in
nsxfeval.c allocates return_buffer->pointer through
acpi_ut_initialize_buffer() and, if acpi_ut_copy_iobject_to_eobject()
then fails with AE_TYPE or AE_SUPPORT (utcopy.c), returns without
freeing it. The ACPI_FAILURE path now releases that buffer as well.
Signed-off-by: Bartu Alev <bartualev@gmail.com>
---
drivers/platform/asus/asus-wmi.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/platform/asus/asus-wmi.c b/drivers/platform/asus/asus-wmi.c
index 4f74fdfd7a0c2..015e207e840e6 100644
--- a/drivers/platform/asus/asus-wmi.c
+++ b/drivers/platform/asus/asus-wmi.c
@@ -477,11 +477,15 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
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);
+ /*
+ * Take ownership of the reply buffer right away: ACPICA may leave it
+ * allocated even when reporting a failure.
+ */
+ union acpi_object *obj __free(kfree) = output.pointer;
pr_debug("%s called (0x%08x) with args: 0x%08x, 0x%08x\n",
__func__, method_id, arg0, arg1);
@@ -491,15 +495,14 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
return -EIO;
}
- obj = (union acpi_object *)output.pointer;
-
/*
* acpi_evaluate_object() reports AE_OK with a NULL buffer when the
* method returned no object at all.
*/
if (!obj) {
- err = -ENODATA;
- goto out_free;
+ pr_debug("%s, (0x%08x), arg 0x%08x failed: %d\n",
+ __func__, method_id, arg0, -ENODATA);
+ return -ENODATA;
}
switch (obj->type) {
@@ -533,9 +536,6 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
break;
}
-out_free:
- kfree(obj);
-
if (err) {
pr_debug("%s, (0x%08x), arg 0x%08x failed: %d\n",
__func__, method_id, arg0, err);
--
2.56.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/3] platform/asus: asus-wmi: Document asus_wmi_evaluate_method_buf()
2026-12-01 23:31 [PATCH 0/3] platform/asus: asus-wmi: harden asus_wmi_evaluate_method_buf() Bartu Alev
2026-12-01 23:31 ` [PATCH 1/3] platform/asus: asus-wmi: Fix NULL deref and integer handling in asus_wmi_evaluate_method_buf() Bartu Alev
2026-12-01 23:31 ` [PATCH 2/3] platform/asus: asus-wmi: Use __free(kfree) " Bartu Alev
@ 2026-12-01 23:31 ` Bartu Alev
2026-12-02 2:50 ` Denis Benato
2 siblings, 1 reply; 10+ messages in thread
From: Bartu Alev @ 2026-12-01 23:31 UTC (permalink / raw)
To: Corentin Chary, Luke D. Jones, Denis Benato, Hans de Goede,
Ilpo Järvinen
Cc: platform-driver-x86, linux-kernel, Bartu Alev
Add kernel-doc for the helper: its parameters, the fact that only
obj->buffer.length bytes are copied and the tail of ret_buffer is left
untouched on short replies, and the meaning of every error return, i.e.
-EIO when the evaluation fails, -ENODEV for the 0xfffffffe and 0xffffffff
sentinels, -ENOSPC when the reply does not fit and -ENODATA for any other
integer, a missing object or an unexpected type. The return values are
listed as a ReST list as Documentation/doc-guide/kernel-doc.rst asks.
Suggested-by: Denis Benato <denis.benato@linux.dev>
Signed-off-by: Bartu Alev <bartualev@gmail.com>
---
drivers/platform/asus/asus-wmi.c | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/drivers/platform/asus/asus-wmi.c b/drivers/platform/asus/asus-wmi.c
index 015e207e840e6..4627ef0cad0c4 100644
--- a/drivers/platform/asus/asus-wmi.c
+++ b/drivers/platform/asus/asus-wmi.c
@@ -462,9 +462,32 @@ 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 returning a buffer
+ * @method_id: WMI method ID to evaluate, such as ASUS_WMI_METHODID_DSTS
+ * @arg0: First method argument, usually the device ID
+ * @arg1: Second method argument
+ * @ret_buffer: Buffer to copy the reply into
+ * @size: Size of @ret_buffer
+ *
+ * Evaluate the method and copy the reply into @ret_buffer. The reply must
+ * be a non-empty ACPI buffer; only obj->buffer.length bytes are copied and
+ * the rest of @ret_buffer is left untouched, so callers that need the
+ * whole buffer must initialise it themselves. Anything other than a
+ * buffer is reported as an error. The firmware answers with an integer
+ * instead, %ASUS_WMI_UNSUPPORTED_METHOD (0xfffffffe) when it does not
+ * implement the device or method. That value and 0xffffffff, which
+ * asus_wmi_get_devstate() treats the same way, are reported as -ENODEV.
+ * No object at all, an empty buffer, an unexpected object type and any
+ * other integer, including the 0 some methods return when called without
+ * an argument, are reported as -ENODATA.
+ *
+ * Return:
+ * * %0 - reply copied into @ret_buffer
+ * * %-EIO - the WMI evaluation failed
+ * * %-ENODEV - the firmware does not implement the device or method
+ * * %-ENOSPC - the reply does not fit into @ret_buffer
+ * * %-ENODATA - no object, an empty buffer, an unexpected type or another integer
*/
static int asus_wmi_evaluate_method_buf(u32 method_id,
u32 arg0, u32 arg1, u8 *ret_buffer, size_t size)
--
2.56.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] platform/asus: asus-wmi: Fix NULL deref and integer handling in asus_wmi_evaluate_method_buf()
2026-12-01 23:31 ` [PATCH 1/3] platform/asus: asus-wmi: Fix NULL deref and integer handling in asus_wmi_evaluate_method_buf() Bartu Alev
@ 2026-12-02 2:40 ` Denis Benato
2026-12-02 14:52 ` bartu alev
0 siblings, 1 reply; 10+ messages in thread
From: Denis Benato @ 2026-12-02 2:40 UTC (permalink / raw)
To: Bartu Alev, Corentin Chary, Luke D. Jones, Hans de Goede,
Ilpo Järvinen
Cc: platform-driver-x86, linux-kernel, stable
On 12/2/26 00:31, Bartu Alev wrote:
> acpi_evaluate_object() reports AE_OK and leaves output.pointer NULL when
> the evaluated WMI method returns no object at all, but
> asus_wmi_evaluate_method_buf() dereferenced the pointer in
> switch (obj->type) unconditionally, causing an oops during probe via
> asus_wmi_custom_fan_curve_init() -> fan_curve_check_present() and on
> writes to pwmN_enable via fan_curve_enable_store().
>
> The ACPI_TYPE_INTEGER case also stored the firmware's u32 reply in the
> signed int err. A value with bit 31 set therefore aliased a negative
> errno (0xffffffff became -EPERM) and any other value leaked out as a
> positive number: a DSTS reply carrying only ASUS_WMI_DSTS_UNKNOWN_BIT
> (0x2), seen on ASUS hardware for unsupported device IDs, was returned as
> +2 through fan_curve_enable_store() on writes of 2 and 3 to pwmN_enable,
> which sysfs treats as a successful write. fan_curve_check_present()
> swallows the error at probe, so only the NULL dereference is fatal
> there.
>
> Treat a missing object as -ENODATA, decode integer replies via u32 and
> map ASUS_WMI_UNSUPPORTED_METHOD and 0xffffffff to -ENODEV, matching
> asus_wmi_get_devstate(), and any other integer to -ENODATA. A survey of
> 102 ASUS DSDTs and the SMM path of a recent model found unsupported
> methods answering 0xfffffffe or 0 rather than no object or 0xffffffff,
> so both defects are latent rather than observed in the field.
>
> Fixes: 0f0ac158d28ff ("platform/x86: asus-wmi: Add support for custom fan curves")
> Cc: stable@vger.kernel.org
> Link: https://lore.kernel.org/all/228df241-da5e-49cb-b29f-6b9158557f55@gmail.com/
> Signed-off-by: Bartu Alev <bartualev@gmail.com>
> ---
> drivers/platform/asus/asus-wmi.c | 26 +++++++++++++++++++-------
> 1 file changed, 19 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/platform/asus/asus-wmi.c b/drivers/platform/asus/asus-wmi.c
> index 552080ff5be25..4f74fdfd7a0c2 100644
> --- a/drivers/platform/asus/asus-wmi.c
> +++ b/drivers/platform/asus/asus-wmi.c
> @@ -478,6 +478,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);
> @@ -492,6 +493,15 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
>
> obj = (union acpi_object *)output.pointer;
>
> + /*
> + * acpi_evaluate_object() reports AE_OK with a NULL buffer when the
> + * method returned no object at all.
> + */
> + if (!obj) {
> + err = -ENODATA;
> + goto out_free;
> + }
Hi and thanks for improving this code! I leave my review below.
This code, after applying the patch reads as this:
if obj is null and no memory is allocated go to deallocate memory of obj.
I understand that you are preparing for patch 2 and the __free conversion
here... but probably converting it into __free right away would have been
better.
You can still split it up, but patches need to have coherent code, if you
really think the dual patch is the way to go rename out_free into
asus_wmi_evaluate_method_err and move it below the kfree and
that way the will be coherent again.
> +
> switch (obj->type) {
> case ACPI_TYPE_BUFFER:
> if (obj->buffer.length > size) {
> @@ -506,15 +516,16 @@ 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;
> -
> - if (err == ASUS_WMI_UNSUPPORTED_METHOD)
> - err = -ENODEV;
> + retval = (u32)obj->integer.value;
> /*
> - * At least one method returns a 0 with no buffer if no arg
> - * is provided, such as ASUS_WMI_DEVID_CPU_FAN_CURVE
> + * ASUS_WMI_UNSUPPORTED_METHOD (0xfffffffe) and 0xffffffff
> + * mean the device or method is not implemented. Any other
> + * integer, such as the 0 some methods return when called
> + * without an argument, is not usable data either.
> */
> - if (err == 0)
> + if (retval == ASUS_WMI_UNSUPPORTED_METHOD || retval == ~0U)
> + err = -ENODEV;
> + else
> err = -ENODATA;
> break;
> default:
> @@ -522,6 +533,7 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
> break;
> }
>
> +out_free:
> kfree(obj);
>
> if (err) {
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] platform/asus: asus-wmi: Use __free(kfree) in asus_wmi_evaluate_method_buf()
2026-12-01 23:31 ` [PATCH 2/3] platform/asus: asus-wmi: Use __free(kfree) " Bartu Alev
@ 2026-12-02 2:45 ` Denis Benato
2026-12-02 15:13 ` Bartu Alev
0 siblings, 1 reply; 10+ messages in thread
From: Denis Benato @ 2026-12-02 2:45 UTC (permalink / raw)
To: Bartu Alev, Corentin Chary, Luke D. Jones, Hans de Goede,
Ilpo Järvinen
Cc: platform-driver-x86, linux-kernel
On 12/2/26 00:31, Bartu Alev wrote:
> Replace the manual kfree(obj) and the out_free: goto with a __free(kfree)
> cleanup attribute, as include/linux/cleanup.h asks not to mix goto with
> scope-based cleanup in the same routine.
>
> Declare the buffer right after the evaluation and before the
> ACPI_FAILURE(status) check, so that ownership is taken on every path.
> This also covers a leak inside ACPICA: acpi_evaluate_object() in
> nsxfeval.c allocates return_buffer->pointer through
> acpi_ut_initialize_buffer() and, if acpi_ut_copy_iobject_to_eobject()
> then fails with AE_TYPE or AE_SUPPORT (utcopy.c), returns without
> freeing it. The ACPI_FAILURE path now releases that buffer as well.
>
> Signed-off-by: Bartu Alev <bartualev@gmail.com>
> ---
> drivers/platform/asus/asus-wmi.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/platform/asus/asus-wmi.c b/drivers/platform/asus/asus-wmi.c
> index 4f74fdfd7a0c2..015e207e840e6 100644
> --- a/drivers/platform/asus/asus-wmi.c
> +++ b/drivers/platform/asus/asus-wmi.c
> @@ -477,11 +477,15 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
> struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
> 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);
> + /*
> + * Take ownership of the reply buffer right away: ACPICA may leave it
> + * allocated even when reporting a failure.
> + */
> + union acpi_object *obj __free(kfree) = output.pointer;
>
> pr_debug("%s called (0x%08x) with args: 0x%08x, 0x%08x\n",
> __func__, method_id, arg0, arg1);
> @@ -491,15 +495,14 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
> return -EIO;
> }
>
> - obj = (union acpi_object *)output.pointer;
> -
obj was assigned here, you moved it up but I can't see any reason for that,
in fact moving it up only increase the possibility of an allocation immediately
freed due to an error (like the return -EIO).
Move the obj __free line here.
> /*
> * acpi_evaluate_object() reports AE_OK with a NULL buffer when the
> * method returned no object at all.
> */
> if (!obj) {
> - err = -ENODATA;
> - goto out_free;
> + pr_debug("%s, (0x%08x), arg 0x%08x failed: %d\n",
> + __func__, method_id, arg0, -ENODATA);
> + return -ENODATA;
> }
>
> switch (obj->type) {
> @@ -533,9 +536,6 @@ static int asus_wmi_evaluate_method_buf(u32 method_id,
> break;
> }
>
> -out_free:
> - kfree(obj);
> -
Yeah... I think that this should be patch 1, but Ilpo might have
a different opinion... At the same time 8 lines changes in two
patches where half of the first patch gets dropped on the second
looks like a bit of an overkill to me.
> if (err) {
> pr_debug("%s, (0x%08x), arg 0x%08x failed: %d\n",
> __func__, method_id, arg0, err);
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/3] platform/asus: asus-wmi: Document asus_wmi_evaluate_method_buf()
2026-12-01 23:31 ` [PATCH 3/3] platform/asus: asus-wmi: Document asus_wmi_evaluate_method_buf() Bartu Alev
@ 2026-12-02 2:50 ` Denis Benato
2026-12-02 15:16 ` Bartu Alev
0 siblings, 1 reply; 10+ messages in thread
From: Denis Benato @ 2026-12-02 2:50 UTC (permalink / raw)
To: Bartu Alev, Corentin Chary, Luke D. Jones, Hans de Goede,
Ilpo Järvinen
Cc: platform-driver-x86, linux-kernel
On 12/2/26 00:31, Bartu Alev wrote:
> Add kernel-doc for the helper: its parameters, the fact that only
> obj->buffer.length bytes are copied and the tail of ret_buffer is left
> untouched on short replies, and the meaning of every error return, i.e.
> -EIO when the evaluation fails, -ENODEV for the 0xfffffffe and 0xffffffff
> sentinels, -ENOSPC when the reply does not fit and -ENODATA for any other
> integer, a missing object or an unexpected type. The return values are
> listed as a ReST list as Documentation/doc-guide/kernel-doc.rst asks.
>
> Suggested-by: Denis Benato <denis.benato@linux.dev>
> Signed-off-by: Bartu Alev <bartualev@gmail.com>
> ---
> drivers/platform/asus/asus-wmi.c | 29 ++++++++++++++++++++++++++---
> 1 file changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/platform/asus/asus-wmi.c b/drivers/platform/asus/asus-wmi.c
> index 015e207e840e6..4627ef0cad0c4 100644
> --- a/drivers/platform/asus/asus-wmi.c
> +++ b/drivers/platform/asus/asus-wmi.c
> @@ -462,9 +462,32 @@ 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 returning a buffer
> + * @method_id: WMI method ID to evaluate, such as ASUS_WMI_METHODID_DSTS
> + * @arg0: First method argument, usually the device ID
> + * @arg1: Second method argument
> + * @ret_buffer: Buffer to copy the reply into
> + * @size: Size of @ret_buffer
> + *
> + * Evaluate the method and copy the reply into @ret_buffer. The reply must
> + * be a non-empty ACPI buffer; only obj->buffer.length bytes are copied and
> + * the rest of @ret_buffer is left untouched, so callers that need the
> + * whole buffer must initialise it themselves. Anything other than a
> + * buffer is reported as an error. The firmware answers with an integer
> + * instead, %ASUS_WMI_UNSUPPORTED_METHOD (0xfffffffe) when it does not
> + * implement the device or method. That value and 0xffffffff, which
> + * asus_wmi_get_devstate() treats the same way, are reported as -ENODEV.
> + * No object at all, an empty buffer, an unexpected object type and any
> + * other integer, including the 0 some methods return when called without
> + * an argument, are reported as -ENODATA.
> + *
This is confusing to me, can you make it shorter?
"Anything other than a buffer is reported as an error"... anything what?
The answer?
The sentence "The firmware answers with an integer instead" doesn't
make sense to me, probably because it's too convoluted and mixing
implementation details, ACPI asus methods and function inner working.
> + * Return:
> + * * %0 - reply copied into @ret_buffer
> + * * %-EIO - the WMI evaluation failed
> + * * %-ENODEV - the firmware does not implement the device or method
> + * * %-ENOSPC - the reply does not fit into @ret_buffer
> + * * %-ENODATA - no object, an empty buffer, an unexpected type or another integer
> */
> static int asus_wmi_evaluate_method_buf(u32 method_id,
> u32 arg0, u32 arg1, u8 *ret_buffer, size_t size)
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/3] platform/asus: asus-wmi: Fix NULL deref and integer handling in asus_wmi_evaluate_method_buf()
2026-12-02 2:40 ` Denis Benato
@ 2026-12-02 14:52 ` bartu alev
0 siblings, 0 replies; 10+ messages in thread
From: bartu alev @ 2026-12-02 14:52 UTC (permalink / raw)
To: Denis Benato, Corentin Chary, Luke D. Jones, Hans de Goede,
Ilpo Järvinen
Cc: platform-driver-x86, linux-kernel, stable
On 12/2/26 5:40 AM, Denis Benato wrote:
> Hi and thanks for improving this code! I leave my review below.
>
>
> This code, after applying the patch reads as this:
>
> if obj is null and no memory is allocated go to deallocate memory of obj.
>
> I understand that you are preparing for patch 2 and the __free conversion
> here... but probably converting it into __free right away would have been
> better.
>
> You can still split it up, but patches need to have coherent code, if you
> really think the dual patch is the way to go rename out_free into
> asus_wmi_evaluate_method_err and move it below the kfree and
> that way the will be coherent again.
|Hi Denis, thanks for the review! Good point, jumping to out_free when
obj is NULL reads oddly. Patch 1/3 is meant for -stable (back to v5.17,
where cleanup.h and the -Wdeclaration-after-statement drop from 6.5 do
not exist yet, so 6.1 LTS would fail to build with __free()), and patch
2/3 is the -next cleanup. I did spell that out in the cover letter,
though I know u rarely get read :-) Even cleaner than moving the label
below kfree(): since no cleanup is needed when obj is NULL, if (!obj)
can log and return -ENODATA directly (matching the ACPI_FAILURE check
right above it). That removes the goto entirely from 1/3 and keeps 2/3
from touching those lines again. also see Ilpo suggestion|
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/3] platform/asus: asus-wmi: Use __free(kfree) in asus_wmi_evaluate_method_buf()
2026-12-02 2:45 ` Denis Benato
@ 2026-12-02 15:13 ` Bartu Alev
0 siblings, 0 replies; 10+ messages in thread
From: Bartu Alev @ 2026-12-02 15:13 UTC (permalink / raw)
To: Denis Benato, Corentin Chary, Luke D. Jones, Hans de Goede,
Ilpo Järvinen
Cc: platform-driver-x86, linux-kernel
On 12/2/26 5:45 AM, Denis Benato wrote:
> obj was assigned here, you moved it up but I can't see any reason for that,
> in fact moving it up only increase the possibility of an allocation immediately
> freed due to an error (like the return -EIO).
>
> Move the obj __free line here.
__free(kfree) does not allocate anything and is a no-op when
output.pointer is NULL. The reason I placed it before the
ACPI_FAILURE(status) check is an ACPICA quirk in
drivers/acpi/acpica/nsxfeval.c: acpi_evaluate_object() calls
acpi_ut_initialize_buffer() (allocating return_buffer->pointer) before
acpi_ut_copy_iobject_to_eobject(). If copying fails with AE_TYPE or
AE_SUPPORT, acpi_evaluate_object() goes to cleanup_return_object without
freeing return_buffer->pointer, so output.pointer can be non-NULL on an
error return.
That said, if you and Ilpo prefer placing the __free(kfree) declaration
after the ACPI_FAILURE(status) check, i am move it down in v2.
>
> Yeah... I think that this should be patch 1, but Ilpo might have
> a different opinion... At the same time 8 lines changes in two
> patches where half of the first patch gets dropped on the second
> looks like a bit of an overkill to me.
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/3] platform/asus: asus-wmi: Document asus_wmi_evaluate_method_buf()
2026-12-02 2:50 ` Denis Benato
@ 2026-12-02 15:16 ` Bartu Alev
0 siblings, 0 replies; 10+ messages in thread
From: Bartu Alev @ 2026-12-02 15:16 UTC (permalink / raw)
To: Denis Benato, Corentin Chary, Luke D. Jones, Hans de Goede,
Ilpo Järvinen
Cc: platform-driver-x86, linux-kernel
On 12/2/26 5:50 AM, Denis Benato wrote:
> This is confusing to me, can you make it shorter?
>
> "Anything other than a buffer is reported as an error"... anything what?
> The answer?
>
> The sentence "The firmware answers with an integer instead" doesn't
> make sense to me, probably because it's too convoluted and mixing
> implementation details, ACPI asus methods and function inner working.
yes, that wording was overly convoluted and leaked internal details.
would a shorter version like this work for v2?
/**
* asus_wmi_evaluate_method_buf() - Evaluate a WMI method returning a buffer
* @method_id: WMI method ID to evaluate (e.g. %ASUS_WMI_METHODID_DSTS)
* @arg0: First method argument, usually the device ID
* @arg1: Second method argument
* @ret_buffer: Caller buffer to copy the returned ACPI buffer into
* @size: Size of @ret_buffer in bytes
*
* Evaluate @method_id and copy the returned ACPI buffer into @ret_buffer.
* If the reply is shorter than @size, only the returned bytes are copied
* and the remainder of @ret_buffer is left untouched.
*
* Non-buffer ACPI replies are treated as errors:
%ASUS_WMI_UNSUPPORTED_METHOD
* (0xfffffffe) and 0xffffffff map to -ENODEV, while any other integer
* (such as 0 when an argument is omitted) or unexpected object type maps
* to -ENODATA.
*
* Return:
* * %0 - Success, buffer copied into @ret_buffer.
* * %-EIO - WMI method evaluation failed.
* * %-ENODEV - Firmware reported the device or method as unsupported.
* * %-ENOSPC - Returned buffer is larger than @size.
* * %-ENODATA - No object returned, empty buffer, or unexpected reply.
*/
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-12-02 15:16 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 23:31 [PATCH 0/3] platform/asus: asus-wmi: harden asus_wmi_evaluate_method_buf() Bartu Alev
2026-12-01 23:31 ` [PATCH 1/3] platform/asus: asus-wmi: Fix NULL deref and integer handling in asus_wmi_evaluate_method_buf() Bartu Alev
2026-12-02 2:40 ` Denis Benato
2026-12-02 14:52 ` bartu alev
2026-12-01 23:31 ` [PATCH 2/3] platform/asus: asus-wmi: Use __free(kfree) " Bartu Alev
2026-12-02 2:45 ` Denis Benato
2026-12-02 15:13 ` Bartu Alev
2026-12-01 23:31 ` [PATCH 3/3] platform/asus: asus-wmi: Document asus_wmi_evaluate_method_buf() Bartu Alev
2026-12-02 2:50 ` Denis Benato
2026-12-02 15:16 ` Bartu Alev
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.