From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Fuwei Xie <12313607@mail.sustech.edu.cn>
Cc: "Hans de Goede" <hansg@kernel.org>,
platform-driver-x86@vger.kernel.org,
LKML <linux-kernel@vger.kernel.org>,
"Eren Özen" <erenozen@protonmail.com>,
"Zheng Shuyang" <yhshzh0@gmail.com>
Subject: Re: [PATCH v4 1/5] platform/x86: huawei-wmi: scope method responses to each call
Date: Tue, 1 Dec 2026 12:40:55 +0200 (EET) [thread overview]
Message-ID: <41ac343d-d7f2-9952-61a6-f3fcd0460d5e@linux.intel.com> (raw)
In-Reply-To: <DCA4A3FB5F5C7115+20261130101218.243426-2-12313607@mail.sustech.edu.cn>
On Mon, 30 Nov 2026, Fuwei Xie wrote:
> Keep each ACPI allocation alive while decoding its response and release
> it on every exit with __free(kfree). Give each handshake attempt a
> fresh output descriptor so retrying cannot reuse the first allocation.
>
> Signed-off-by: Fuwei Xie <12313607@mail.sustech.edu.cn>
> ---
> drivers/platform/x86/huawei-wmi.c | 59 ++++++++++++-------------------
> 1 file changed, 23 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c
> index 96ee9a97c..559731d15 100644
> --- a/drivers/platform/x86/huawei-wmi.c
> +++ b/drivers/platform/x86/huawei-wmi.c
> @@ -177,9 +177,7 @@ static int huawei_wmi_call(struct huawei_wmi *huawei,
> static int huawei_wmi_cmd(u64 arg, u8 *buf, size_t buflen)
> {
> struct huawei_wmi *huawei = huawei_wmi;
> - struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
> struct acpi_buffer in;
> - union acpi_object *obj;
> size_t len;
> int err, i;
>
> @@ -190,15 +188,17 @@ static int huawei_wmi_cmd(u64 arg, u8 *buf, size_t buflen)
> * HWMI and if we get a non-zero return status we evaluate it again.
> */
> for (i = 0; i < 2; i++) {
> + struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
> +
> err = huawei_wmi_call(huawei, &in, &out);
> if (err)
> - goto fail_cmd;
> + return err;
>
> - obj = out.pointer;
> - if (!obj) {
> - err = -EIO;
> - goto fail_cmd;
> - }
> + union acpi_object *allocation __free(kfree) = out.pointer;
> + union acpi_object *obj = allocation;
It's not clear to me what having allocation achieves over plain:
union acpi_object *obj __free(kfree) = out.pointer;
> +
> + if (!obj)
Don't leave a blank line between the assignment and its error handling
(analoguous to no-blank-lines between call and its error handling).
> + return -EIO;
>
> switch (obj->type) {
> /* Models that implement both "legacy" and HWMI tend to return a 0x104
> @@ -211,8 +211,7 @@ static int huawei_wmi_cmd(u64 arg, u8 *buf, size_t buflen)
> len = 0x100;
> } else {
> dev_err(huawei->dev, "Bad buffer length, got %d\n", obj->buffer.length);
> - err = -EIO;
> - goto fail_cmd;
> + return -EIO;
> }
>
> break;
> @@ -222,15 +221,13 @@ static int huawei_wmi_cmd(u64 arg, u8 *buf, size_t buflen)
> case ACPI_TYPE_PACKAGE:
> if (obj->package.count != 2) {
> dev_err(huawei->dev, "Bad package count, got %d\n", obj->package.count);
> - err = -EIO;
> - goto fail_cmd;
> + return -EIO;
> }
>
> obj = &obj->package.elements[1];
> if (obj->type != ACPI_TYPE_BUFFER) {
> dev_err(huawei->dev, "Bad package element type, got %d\n", obj->type);
> - err = -EIO;
> - goto fail_cmd;
> + return -EIO;
> }
> len = obj->buffer.length;
>
> @@ -238,24 +235,19 @@ static int huawei_wmi_cmd(u64 arg, u8 *buf, size_t buflen)
> /* Shouldn't get here! */
> default:
> dev_err(huawei->dev, "Unexpected obj type, got: %d\n", obj->type);
> - err = -EIO;
> - goto fail_cmd;
> + return -EIO;
> }
>
> - if (!*obj->buffer.pointer)
> - break;
> - }
> + if (*obj->buffer.pointer && !i)
> + continue;
>
> - err = (*obj->buffer.pointer) ? -ENODEV : 0;
> + if (buf)
> + memcpy(buf, obj->buffer.pointer, min(buflen, len));
>
> - if (buf) {
> - len = min(buflen, len);
> - memcpy(buf, obj->buffer.pointer, len);
> + return *obj->buffer.pointer ? -ENODEV : 0;
Can this refactoring be done separately. I think there's too much
unrelated stuff going on this patch which makes it hard to review.
> }
>
> -fail_cmd:
> - kfree(out.pointer);
> - return err;
> + return -ENODEV;
> }
>
> /* LEDs */
> @@ -753,7 +745,6 @@ static int huawei_wmi_debugfs_call_show(struct seq_file *m, void *data)
> struct huawei_wmi *huawei = m->private;
> struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL };
> struct acpi_buffer in;
> - union acpi_object *obj;
> int err;
>
> in.length = sizeof(u64);
> @@ -763,17 +754,13 @@ static int huawei_wmi_debugfs_call_show(struct seq_file *m, void *data)
> if (err)
> return err;
>
> - obj = out.pointer;
> - if (!obj) {
> - err = -EIO;
> - goto fail_debugfs_call;
> - }
> + union acpi_object *obj __free(kfree) = out.pointer;
>
> - huawei_wmi_debugfs_call_dump(m, huawei, obj);
> + if (!obj)
No blank line.
> + return -EIO;
>
> -fail_debugfs_call:
> - kfree(out.pointer);
> - return err;
> + huawei_wmi_debugfs_call_dump(m, huawei, obj);
> + return 0;
> }
>
> DEFINE_SHOW_ATTRIBUTE(huawei_wmi_debugfs_call);
>
This is generally moving into right direction but needs a bit more
work to make it easy to review and see everything is correctly
transformed.
--
i.
next prev parent reply other threads:[~2026-12-01 10:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261130101218.243426-1-12313607@mail.sustech.edu.cn>
2026-11-30 10:12 ` [PATCH v4 1/5] platform/x86: huawei-wmi: scope method responses to each call Fuwei Xie
2026-12-01 10:40 ` Ilpo Järvinen [this message]
2026-11-30 10:12 ` [PATCH v4 2/5] platform/x86: huawei-wmi: bind the Huawei method device Fuwei Xie
2026-12-01 10:57 ` Ilpo Järvinen
2026-11-30 10:12 ` [PATCH v4 3/5] platform/x86: huawei-wmi: use the sized WMI method interface Fuwei Xie
2026-12-01 11:09 ` Ilpo Järvinen
2026-11-30 10:12 ` [PATCH v4 4/5] platform/x86: huawei-wmi: expose native firmware power profiles Fuwei Xie
2026-11-30 10:12 ` [PATCH v4 5/5] platform/x86: huawei-wmi: bind hotkeys and key data on the WMI bus Fuwei Xie
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=41ac343d-d7f2-9952-61a6-f3fcd0460d5e@linux.intel.com \
--to=ilpo.jarvinen@linux.intel.com \
--cc=12313607@mail.sustech.edu.cn \
--cc=erenozen@protonmail.com \
--cc=hansg@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=yhshzh0@gmail.com \
/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.