From: Denis Benato <denis.benato@linux.dev>
To: "Bartu Alev" <bartualev@gmail.com>,
"Corentin Chary" <corentin.chary@gmail.com>,
"Luke D. Jones" <luke@ljones.dev>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] platform/asus: asus-wmi: Use __free(kfree) in asus_wmi_evaluate_method_buf()
Date: Wed, 2 Dec 2026 03:45:56 +0100 [thread overview]
Message-ID: <e15170ea-7eaa-4389-b2c2-f7d47af13999@linux.dev> (raw)
In-Reply-To: <20261202-asus-wmi-eval-buf-v1-2-640c12d437dc@gmail.com>
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);
>
next prev parent reply other threads:[~2026-12-02 2:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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-01 23:31 ` [PATCH 2/3] platform/asus: asus-wmi: Use __free(kfree) " Bartu Alev
2026-12-02 2:45 ` Denis Benato [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e15170ea-7eaa-4389-b2c2-f7d47af13999@linux.dev \
--to=denis.benato@linux.dev \
--cc=bartualev@gmail.com \
--cc=corentin.chary@gmail.com \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=luke@ljones.dev \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.