From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=192.198.163.9 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796123372; b=z4diYjCQQfTcjrvxHkQk/e1U0Q0vX/aXnRH+E+VQxYtJUZrqLZkBL40RYXgJOJyC8dDo iGtiG2Oi8DSjq8GZceutS+lc76U70RfOwm0mY5YKKsAnwuCxFuPC2sRD+/S/H3is4zvdJ 0AnHSGPB0H4sNFn2bb7dMxCkGr3mYgdAd89z6Tgqf8HTtGGf2yqkG77NqWqd2u2J2Hkzd GThrzHCRiN2Xzlg/L3nx9KR3Xjhmc4NccHJfRE1T72elehKDYymuMYRczlZzD6HjnuvkT vEvLacCie2JbixNQ7yrUOHdX7tHGVDkGQjGwqA61V70FzQRqS9fTWdRtA5t3Mk/nSMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796123372; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:Date:To:cc: Subject:In-Reply-To:Message-ID:References:MIME-Version:Content-Type; bh=Yk2Z8+UXzga9y8J8fNrKPahGBSrd35HqHsNWB0FgDbk=; b=lmSK7I/z+tCVnqeHnI7+sI598lccpNiGkFC1qHTPop4Cs9DXID/lFXU6csVJbNIvpWkc FZIZJI558pzTu/Pw8oxA1dFCd2IbXGcTkQT49/54Q439EllZ9J5Mte+fGTWhyOTqJ2rEH kSjtJCtknmafn1Howc6QuKCMZyADB9rgDf1bPodeAKERRXL8KESDlg1TISMY8bi1Tall+ W0RH/uQgD1suePlZ9plg8NESaBEa7uFve7GHtHo8SExOKTXLBqn5mOJtCC2cJbriWIL99 7mOuCJi+YIABJvVVw7FnHVdisw4cXAXdeKlMZw1DZHJpFWfziJbmRKaeQKfi6uNpefg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=a5+G49Ux; arc=none smtp.remote-ip=192.198.163.9 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 617FC606A31A; Tue, 1 Dec 2026 11:09:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 617FC606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=a5+G49Ux DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796123371; x=1827659371; h=from:date:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=Yk2Z8+UXzga9y8J8fNrKPahGBSrd35HqHsNWB0FgDbk=; b=a5+G49UxW0gWZeUkw9vevvodsOtW9Mq3a3naRx6MGCGvlLlvZahuClqX YU694DmhhQwkeorjeVBFgZ4c3rxb24s8UsGBraMz7i0BuvW4hdKYoE3qQ 80tsNZ9mtXYDWE7QM5E5V7vwwbs42swXnqv5lhrOZ0ZLr8/FO/yse3z/N 8JMi9bCJiSAfLaoCiGjtRFX0GIamDN2eKdr/6VLfXIMCfIQ3c8/+cAHiU JCxGdko1zgJHQhr3PSNqDgCxuas6mKD67TbJ0WxlFIgxUccCjZwzj/ETY X4PRSar0ewnCKKthojLL52H6jItsr2feIG6Cp/OV5I1BVYL5cYVztj5LA Q==; X-CSE-ConnectionGUID: lgVXM/OcRBWEzKVwJnAT2g== X-CSE-MsgGUID: O5A4Z6ijQYOE6J1jgeKcHw== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4847391" X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="4847391" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 03:09:31 -0800 X-CSE-ConnectionGUID: p3BAjkGcSuWv24up0Mxxuw== X-CSE-MsgGUID: zSlXboiaSiCfrRjDZZi4nQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,244,1787036400"; d="scan'208";a="13615301" Received: from pgcooper-mobl3.ger.corp.intel.com (HELO localhost) ([10.245.245.21]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 03:09:29 -0800 From: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= Date: Tue, 1 Dec 2026 13:09:25 +0200 (EET) To: Fuwei Xie <12313607@mail.sustech.edu.cn> cc: Hans de Goede , platform-driver-x86@vger.kernel.org, LKML , =?ISO-8859-15?Q?Eren_=D6zen?= , Zheng Shuyang Subject: Re: [PATCH v4 3/5] platform/x86: huawei-wmi: use the sized WMI method interface In-Reply-To: <067B78B9700CD975+20261130101218.243426-4-12313607@mail.sustech.edu.cn> Message-ID: <7973c2e9-19c3-9a70-c337-b9136e356175@linux.intel.com> References: <20261130101218.243426-1-12313607@mail.sustech.edu.cn> <067B78B9700CD975+20261130101218.243426-4-12313607@mail.sustech.edu.cn> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII On Mon, 30 Nov 2026, Fuwei Xie wrote: > Let the WMI core unpack method replies and require enough bytes for > the common header. Hold the mutex across both attempts. A retry status > may arrive without any command data, so validate each successful query > against the fields its caller needs. Scan only bytes actually returned. > > Keep the raw debugfs dump on the device-based ACPI interface so it can > display the original object types. > > Signed-off-by: Fuwei Xie <12313607@mail.sustech.edu.cn> > --- > drivers/platform/x86/huawei-wmi.c | 170 +++++++++++------------------- > 1 file changed, 59 insertions(+), 111 deletions(-) > > diff --git a/drivers/platform/x86/huawei-wmi.c b/drivers/platform/x86/huawei-wmi.c > index 690bd0abc..209066260 100644 > --- a/drivers/platform/x86/huawei-wmi.c > +++ b/drivers/platform/x86/huawei-wmi.c > @@ -151,101 +151,42 @@ static const struct dmi_system_id huawei_quirks[] = { > > /* Utils */ > > -static int huawei_wmi_call(struct huawei_wmi *huawei, > - struct acpi_buffer *in, struct acpi_buffer *out) > -{ > - acpi_status status; > - > - mutex_lock(&huawei->wmi_lock); > - status = wmidev_evaluate_method(huawei->wdev, 0, 1, in, out); > - mutex_unlock(&huawei->wmi_lock); > - if (ACPI_FAILURE(status)) { > - dev_err(huawei->dev, "Failed to evaluate wmi method\n"); > - return -ENODEV; > - } > - > - return 0; > -} > +/* Both HWMI reply formats start with four reserved bytes and a status. */ > +struct hwmi_reply { > + u8 reserved[4]; > + u8 status; > + u8 data[]; > +}; > > -/* HWMI takes a 64 bit input and returns either a package with 2 buffers, one of > - * 4 bytes and the other of 256 bytes, or one buffer of size 0x104 (260) bytes. > - * The first 4 bytes are ignored, we ignore the first 4 bytes buffer if we got a > - * package, or skip the first 4 if a buffer of 0x104 is used. The first byte of > - * the remaining 0x100 sized buffer has the return status of every call. In case > - * the return status is non-zero, we return -ENODEV but still copy the returned > - * buffer to the given buffer parameter (buf). > - */ > +/* Return the number of command data bytes copied, or a negative errno. */ > static int huawei_wmi_cmd(u64 arg, u8 *buf, size_t buflen) > { > struct huawei_wmi *huawei = huawei_wmi; > - struct acpi_buffer in; > - size_t len; > - int err, i; > - > - in.length = sizeof(arg); > - in.pointer = &arg; > + struct wmi_buffer in = { .length = sizeof(arg), .data = &arg }; > + int i; > > - /* Some models require calling HWMI twice to execute a command. We evaluate > - * HWMI and if we get a non-zero return status we evaluate it again. > - */ > + guard(mutex)(&huawei->wmi_lock); > for (i = 0; i < 2; i++) { > - struct acpi_buffer out = { ACPI_ALLOCATE_BUFFER, NULL }; > + struct wmi_buffer out; > + size_t len; > + int err; > > - err = huawei_wmi_call(huawei, &in, &out); > + err = wmidev_invoke_method(huawei->wdev, 0, 1, &in, &out, > + sizeof(struct hwmi_reply)); > if (err) > return err; > > - union acpi_object *allocation __free(kfree) = out.pointer; > - union acpi_object *obj = allocation; > - > - if (!obj) > - return -EIO; > - > - switch (obj->type) { > - /* Models that implement both "legacy" and HWMI tend to return a 0x104 > - * sized buffer instead of a package of 0x4 and 0x100 buffers. > - */ > - case ACPI_TYPE_BUFFER: > - if (obj->buffer.length == 0x104) { > - // Skip the first 4 bytes. > - obj->buffer.pointer += 4; > - len = 0x100; > - } else { > - dev_err(huawei->dev, "Bad buffer length, got %d\n", obj->buffer.length); > - return -EIO; > - } > - > - break; > - /* HWMI returns a package with 2 buffer elements, one of 4 bytes and the > - * other is 256 bytes. > - */ > - case ACPI_TYPE_PACKAGE: > - if (obj->package.count != 2) { > - dev_err(huawei->dev, "Bad package count, got %d\n", obj->package.count); > - 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); > - return -EIO; > - } > - len = obj->buffer.length; > - > - break; > - /* Shouldn't get here! */ > - default: > - dev_err(huawei->dev, "Unexpected obj type, got: %d\n", obj->type); > - return -EIO; > - } > + struct hwmi_reply *reply __free(kfree) = out.data; > > - if (*obj->buffer.pointer && !i) > + /* Some machines require a second call after a nonzero status. */ > + if (reply->status) > continue; > > - if (buf) > - memcpy(buf, obj->buffer.pointer, min(buflen, len)); > + len = min(buflen, out.length - sizeof(*reply)); > + if (len) > + memcpy(buf, reply->data, len); > > - return *obj->buffer.pointer ? -ENODEV : 0; > + return len; > } > > return -ENODEV; > @@ -319,21 +260,22 @@ static void huawei_wmi_leds_setup(struct device *dev) > > static int huawei_wmi_battery_get(int *start, int *end) > { > - u8 ret[0x100]; > - int err, i; > + u8 data[0xff]; Now this was interesting change, I've no idea what's going on. ...Piling up unexplained changes does not get you anywhere. ...Also, it would be nice to name magic numbers with defines. > + int len; > > - err = huawei_wmi_cmd(BATTERY_THRESH_GET, ret, sizeof(ret)); > - if (err) > - return err; > + len = huawei_wmi_cmd(BATTERY_THRESH_GET, data, sizeof(data)); > + if (len < 0) > + return len; > + if (len < 2) > + return -ENODATA; > > - /* Find the last two non-zero values. Return status is ignored. */ > - i = ARRAY_SIZE(ret) - 1; > - do { > - if (start) > - *start = ret[i-1]; > - if (end) > - *end = ret[i]; > - } while (i > 2 && !ret[i--]); > + /* The threshold pair can be followed by zero padding. */ > + while (len > 2 && !data[len - 1]) > + len--; > + if (start) > + *start = data[len - 2]; > + if (end) > + *end = data[len - 1]; > > return 0; > } > @@ -612,24 +554,24 @@ static int huawei_acpi_fn_lock_set(int on) > > static int huawei_wmi_fn_lock_get(int *on) > { > - u8 ret[0x100] = { 0 }; > - int err, i; > + u8 data[0xff]; > + int len; > > - /* Newer models: use direct ACPI \GFRS method */ > if (acpi_has_method(NULL, "\\GFRS")) > return huawei_acpi_fn_lock_get(on); > > - /* WMI fallback */ > - err = huawei_wmi_cmd(FN_LOCK_GET, ret, 0x100); > - if (err) > - return err; > + len = huawei_wmi_cmd(FN_LOCK_GET, data, sizeof(data)); > + if (len < 0) > + return len; > + if (!len) > + return -ENODATA; > > - /* Find the first non-zero value. Return status is ignored. */ > - i = 1; > - do { > - if (on) > - *on = ret[i] - 1; // -1 undefined, 0 off, 1 on. > - } while (i < 0xff && !ret[i++]); > + if (on) { > + const u8 *state = memchr_inv(data, 0, len); > + > + /* -1 undefined, 0 off, 1 on. */ > + *on = state ? *state - 1 : -1; It apparently was like this earlier, but this should be cleaned up with named defines and switch/case. Is this even equivalent to the old code? Is *on written at all if there's 0 (= off as per the comment)? > + } > > return 0; > } > @@ -741,19 +683,25 @@ static void huawei_wmi_debugfs_call_dump(struct seq_file *m, void *data, > } > } > > +/* The raw debugfs dump also prints the original ACPI object types. */ > +static acpi_status huawei_wmi_debugfs_call(struct huawei_wmi *huawei, > + struct acpi_buffer *in, struct acpi_buffer *out) > +{ > + guard(mutex)(&huawei->wmi_lock); > + return wmidev_evaluate_method(huawei->wdev, 0, 1, in, out); > +} > + > 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; > - int err; > > in.length = sizeof(u64); > in.pointer = &huawei->debug.arg; > > - err = huawei_wmi_call(huawei, &in, &out); > - if (err) > - return err; > + if (ACPI_FAILURE(huawei_wmi_debugfs_call(huawei, &in, &out))) > + return -ENODEV; > > union acpi_object *obj __free(kfree) = out.pointer; > > -- i.