Re: [PATCH 2/3] platform/asus: asus-wmi: Use __free(kfree) in asus_wmi_evaluate_method_buf()

From: Denis Benato

Date: Tue Dec 01 2026 - 21:46:02 EST



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@xxxxxxxxx>
> ---
> 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);
>