From: Bartu Alev <bartualev@gmail.com>
To: "Corentin Chary" <corentin.chary@gmail.com>,
"Luke D. Jones" <luke@ljones.dev>,
"Denis Benato" <denis.benato@linux.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, Bartu Alev <bartualev@gmail.com>
Subject: [PATCH 2/3] platform/asus: asus-wmi: Use __free(kfree) in asus_wmi_evaluate_method_buf()
Date: Wed, 02 Dec 2026 02:31:43 +0300 [thread overview]
Message-ID: <20261202-asus-wmi-eval-buf-v1-2-640c12d437dc@gmail.com> (raw)
In-Reply-To: <20261202-asus-wmi-eval-buf-v1-0-640c12d437dc@gmail.com>
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
next prev parent reply other threads:[~2026-12-01 23:32 UTC|newest]
Thread overview: 4+ 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-01 23:31 ` Bartu Alev [this message]
2026-12-01 23:31 ` [PATCH 3/3] platform/asus: asus-wmi: Document asus_wmi_evaluate_method_buf() Bartu Alev
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=20261202-asus-wmi-eval-buf-v1-2-640c12d437dc@gmail.com \
--to=bartualev@gmail.com \
--cc=corentin.chary@gmail.com \
--cc=denis.benato@linux.dev \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®