From nobody Sat Oct 24 13:21:58 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 798F651DE1F; Tue, 13 Oct 2026 19:27:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919631; cv=pass; b=c0ousFN/asWAejbAPEqFXP2BZY91riYjd2UaZsa6yCm+mh/JjXBjWE8UlepDWDrelVTZQZWhi7dzjNeNNe0F6sBzTUVf2wX+oO5D9HsfV+HvG4MFiZWMoEJwSgEN9iLmjI4uW0G8XIY3Z5yMJsq81rNZOOfczN+AoXjjSx6haLU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919631; c=relaxed/simple; bh=c1efmwifO1stTw131+mH0kerfKrDGSq6CCjLjls6aNc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bFzPo4SHmoIrHkQF7Y+c2vWhM91+K5QAhAhsC1dDF6wZXiKuUUDabXDfuG4p+QFqtXVjx4AspGrRjl6Y5KDT6+d4L//UG1EBX/GrGzHWwMfcs3iR2yg1dV5naFIh1kirbc2QiW9N1rgis+R+Aear7IO+Tskfte+pzK7PpyvwTy0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=a8+2RmKZ; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="a8+2RmKZ" ARC-Seal: i=1; a=rsa-sha256; t=1791919608; cv=none; d=zohomail.com; s=zohoarc; b=VoEx71ONdEQtT9PDAy2vDDfQ55Kv0+2sCj1vY1yggwYqHMHKeugtv8Y4csY0+5Wp4TsyGIeVlLhda4rCyoRd+8A6J5xPSNGWMf1Lc6y11RX/kGN4UyyxA76zAZMyKsU1LlW4VkHb0soLio88f4n89SaYwk4cE4BtVLsJpbqENWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791919608; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=ReRS4ZShNiHqof3Nd8ldDThiBg0uWWLo8oSubqtXzPw=; b=QN3MuAqT5/u06WjXioiiCuNuwt9QswoJIqPPzthOPrP962rI2/SriHDMiJCigLQipZQJNHCpqPL3dVW0a3FwzD5NOGwLi9OQfX5VkbSUz3spiuXNr+QgZhUBXKWbd/HgmqZLbJU7vMngxUkIrKQaGgfK38pyW5UAhrz8Nt2KE1w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791919608; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=ReRS4ZShNiHqof3Nd8ldDThiBg0uWWLo8oSubqtXzPw=; b=a8+2RmKZ28vtv9uTCftH9ivJRonge/EoFDGkUzxtI0eGJa1H2PFaZt0tC0vOeUTQ KDadmXyJhmObHIR4V1brFzn3h30DBiJ5l4tg/hUXaOoE1fk74cjnvebNCmHpVRecBNY Grcx4xZW6hm8l5DjjrfCoKCu1I16ijRQwkDtyAhwAqoc6+dOytY0L/WjIR0hjJJbM56 RKes86qFHF4ENlNcjhTYCsDwo/6ecrUb5TJkL8rxYVatXEAsSrcu9IZSGVB1CxVRbQL JHuWoguRsMnTpT8WrTz1mDIOwzI4tw9HLI8JSle81uKNW8IhBtlF5ebNTmEQurk+vXe m/zcxI3kGg== Received: by smtp.zohomail.com with SMTPS id 1791919603598555.5407710219861; Tue, 13 Oct 2026 12:26:43 -0700 (PDT) From: Rong Zhang Date: Wed, 14 Oct 2026 03:21:44 +0800 Subject: [PATCH v3 01/12] platform/wmi: Introduce wmidev_exists() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261014-lwmi-wmi-new-api-v3-1-e1032bed1c81@rong.moe> References: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> In-Reply-To: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> To: Mark Pearson , "Derek J. Clark" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Armin Wolf Cc: Charles , Navon John Lukose , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.17-dev-73bef X-ZohoMailClient: External From: Armin Wolf Some WMI drivers need to be able to detect the existence of WMI devices matching a given GUID in order to determine the availability of optional features. Using wmi_has_guid() for this will not work for WMI devices that cannot be used with the legacy GUID-based API (aka have WMI_GUID_DUPLICATED set). Introduce wmidev_exists() that also checks WMI devices that are only available to the bus-based API. Also mark wmi_has_guid() as deprecated because only WMI drivers using the legacy GUID-based API will continue to have use for it. Signed-off-by: Armin Wolf Tested-by: Mark Pearson Reviewed-by: Mark Pearson Tested-by: Navon John Lukose Reviewed-by: Derek J. Clark Signed-off-by: Rong Zhang Reported-by: Charles Reported-by: Navon John Lukose Suggested-by: Derek J. Clark Suggested-by: Mark Pearson --- Changes in v2: - New patch in the series as discussed at https://msgid.link/83776200-4A60-4756-A99F-D5A3BB4D834A@rong.moe --- drivers/platform/wmi/core.c | 33 +++++++++++++++++++++++++++++---- include/linux/wmi.h | 3 +++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/platform/wmi/core.c b/drivers/platform/wmi/core.c index 529825dcfbfe..a99da9b7039d 100644 --- a/drivers/platform/wmi/core.c +++ b/drivers/platform/wmi/core.c @@ -145,7 +145,7 @@ static inline void get_acpi_method_name(const struct wm= i_block *wblock, buffer[4] =3D '\0'; } =20 -static int wmidev_match_guid(struct device *dev, const void *data) +static int wmidev_match_guid_legacy(struct device *dev, const void *data) { struct wmi_block *wblock =3D dev_to_wblock(dev); const guid_t *guid =3D data; @@ -218,7 +218,7 @@ static struct wmi_device *wmi_find_device_by_guid(const= char *guid_string) if (ret < 0) return ERR_PTR(ret); =20 - dev =3D bus_find_device(&wmi_bus_type, NULL, &guid, wmidev_match_guid); + dev =3D bus_find_device(&wmi_bus_type, NULL, &guid, wmidev_match_guid_leg= acy); if (!dev) return ERR_PTR(-ENODEV); =20 @@ -800,10 +800,10 @@ acpi_status wmi_remove_notify_handler(const char *gui= d) EXPORT_SYMBOL_GPL(wmi_remove_notify_handler); =20 /** - * wmi_has_guid - Check if a GUID is available + * wmi_has_guid - Check if a GUID is available (deprecated) * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f= 2f49ba * - * Check if a given GUID is defined by _WDG. + * Check if a given GUID is available and usable with the legacy GUID-base= d API. * * Return: True if GUID is available, false otherwise. */ @@ -821,6 +821,31 @@ bool wmi_has_guid(const char *guid_string) } EXPORT_SYMBOL_GPL(wmi_has_guid); =20 +static int wmidev_match_guid(struct device *dev, void *data) +{ + struct wmi_block *wblock =3D dev_to_wblock(dev); + const guid_t *guid =3D data; + + if (guid_equal(guid, &wblock->gblock.guid)) + return 1; + + return 0; +} + +/** + * wmidev_exists - Check if a WMI device with a given GUID exists + * @guid: GUID of the WMI device to search for + * + * Check if a WMI device with a given GUID exists at the given moment. + * + * Return: True if a matching WMI device exists, false otherwise. + */ +bool wmidev_exists(const guid_t *guid) +{ + return bus_for_each_dev(&wmi_bus_type, NULL, (void *)guid, wmidev_match_g= uid) =3D=3D 1; +} +EXPORT_SYMBOL_GPL(wmidev_exists); + /** * wmi_get_acpi_device_uid() - Get _UID name of ACPI device that defines G= UID (deprecated) * @guid_string: 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f= 2f49ba diff --git a/include/linux/wmi.h b/include/linux/wmi.h index defcb624a7e2..3dd223f2ff18 100644 --- a/include/linux/wmi.h +++ b/include/linux/wmi.h @@ -13,6 +13,7 @@ #include #include #include +#include =20 /** * struct wmi_device - WMI device structure @@ -83,6 +84,8 @@ acpi_status wmidev_block_set(struct wmi_device *wdev, u8 = instance, const struct =20 u8 wmidev_instance_count(struct wmi_device *wdev); =20 +bool wmidev_exists(const guid_t *guid); + /** * struct wmi_driver - WMI driver structure * @driver: Driver model structure --=20 2.55.0 From nobody Sat Oct 24 13:21:58 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 410595293F6; Tue, 13 Oct 2026 19:27:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919641; cv=pass; b=R6TM6YGgqhnt/738yQqoBnzt2p1i8KAKiQpW8bzxMoI759yprypTvUXabACELm4yHh7CuzYOuFdKIR3k6N+Oj7xNg/jHZ8fQLsWK5poHVjixLhntTsiKY+JZO6+SAALcGbIzzmkBwK2M+7uPvWBBSYWag4o/w6ioZpdAjeI4GdI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919641; c=relaxed/simple; bh=4GzbII8sIamAYawY/o7am0vulpGG42A3euUChRalJRI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Pms8Lcv0N1dhX0A4QmD5L0nQ3Khh3dneMwPt/7U+OmyVt/RVr4gguX18xOmYUCl6KkJ7CjfB+2mBpqTtlbaF3cos+wu0JhQFnm6lHnsm6rbZJwNEkoDh34Uc8uy2P1tq5ZJRSmdf+vJg6zetAeiBqyuUrEoV+RgdRRuoZ+COL4Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=L84FIMPW; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="L84FIMPW" ARC-Seal: i=1; a=rsa-sha256; t=1791919610; cv=none; d=zohomail.com; s=zohoarc; b=W2JkJ56cjy67tYwp3zsMJ+PSF49qDrnzM9k5cJLs2GxypdZB39MT3vtDA6KW/O/P0akSHuiLTJx6ZLjszEh2hsIqEPQ1BfmBm09rzYFh0zJMkyVgTL0W6bj2sO0dqINLS9cQ0w1mDCRjzGsfZQAMdsdK5JsuXIBw8qcNTjI2xCU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791919610; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=IcPdH6CtfwpDA/3ia7xSD6GeQGC5k48vf5Dg9BV5+S4=; b=gW4QnpI1PsdXaprcdV01QY3WsioGfgQJ1UzkXEzPAhNa/A+6CYwHTsI9Gf7YG4eDR80vl8RnSHzOrdXn9H0casBmGv7FAi/V86szrzt5WUHnPUIvObnxTJhHFiDNGYsGKMc7RWXOMEj0Y6T0Mh0Y4JqwwRZpVtvnrGJppkvvsgw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791919610; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=IcPdH6CtfwpDA/3ia7xSD6GeQGC5k48vf5Dg9BV5+S4=; b=L84FIMPWqCOacNaVzjlLETjKcYZwxJmiv+VvkYzKAqXNQqK1TI0f/r9nPCQ1+DOv G47k1i4uxK0TxFMUBbxqHl78y5x4n846YySBxtXQOLcxdJd0NSlorlWdkdN2aD4vfhv kaOXl7iwo+fWf5BTSv/l7S9L7wYxtSV2HRxOiLH8Yzod4wnTnHAuiqAmc5YGX+rMVrX YeOUctW3dz3mJhSoCXq61o4w+S1YXXnK6/BsIy8EUHjrWOgqiS9o6CjHtRvRm+LrvZy DE0KhFXsi7I8Nf/BEuP4uZ7vYYFu4K2nQY2zpNkaYRBD5p84UwcVS8LN0YM8qYVh71r 9OcUec79/g== Received: by smtp.zohomail.com with SMTPS id 1791919606417978.303282065655; Tue, 13 Oct 2026 12:26:46 -0700 (PDT) From: Rong Zhang Date: Wed, 14 Oct 2026 03:21:45 +0800 Subject: [PATCH v3 02/12] platform/x86: lenovo-wmi-capdata: Do not stop the AC notifier chain on error Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261014-lwmi-wmi-new-api-v3-2-e1032bed1c81@rong.moe> References: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> In-Reply-To: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> To: Mark Pearson , "Derek J. Clark" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Armin Wolf Cc: Charles , Navon John Lukose , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang , stable@vger.kernel.org X-Mailer: b4 0.17-dev-73bef X-ZohoMailClient: External Returning NOTIFY_BAD to the AC notifier chain stops it by preventing later notifier blocks from being called, but our error is non-fatal for other AC notifier blocks, which should continue to consume the event. Return NOTIFY_DONE and add a dev_warn() on error, so that the AC notifier chain continues. This also aligns with hp-wmi. The function documentation was copied from elsewhere and makes no sense here, so correct it as well. Fixes: e1a5fe662b59 ("platform/x86: Add Lenovo Capability Data 01 WMI Drive= r") Cc: stable@vger.kernel.org Tested-by: Navon John Lukose Reviewed-by: Derek J. Clark Signed-off-by: Rong Zhang Reported-by: Charles Reported-by: Navon John Lukose Reviewed-by: Mark Pearson Suggested-by: Derek J. Clark Suggested-by: Mark Pearson --- Changes in v2: - New patch in the series --- drivers/platform/x86/lenovo/wmi-capdata.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/platform/x86/lenovo/wmi-capdata.c b/drivers/platform/x= 86/lenovo/wmi-capdata.c index d5e961566136..58787da959b4 100644 --- a/drivers/platform/x86/lenovo/wmi-capdata.c +++ b/drivers/platform/x86/lenovo/wmi-capdata.c @@ -774,13 +774,11 @@ static int lwmi_cd_setup(struct lwmi_cd_priv *priv, e= num lwmi_cd_type type) =20 /** * lwmi_cd01_notifier_call() - Call method for cd01 notifier. - * block call chain. - * @nb: The notifier_block registered to lenovo-wmi-events driver. + * @nb: The cd01 ACPI notifier_block. * @action: Unused. * @data: The ACPI event. * - * For LWMI_EVENT_THERMAL_MODE, set current_mode and notify platform_profi= le - * of a change. + * Refresh cached capdata on AC status change. * * Return: notifier_block status. */ @@ -799,8 +797,16 @@ static int lwmi_cd01_notifier_call(struct notifier_blo= ck *nb, unsigned long acti switch (event->type) { case ACPI_AC_NOTIFY_STATUS: ret =3D lwmi_cd_cache(priv); - if (ret) - return NOTIFY_BAD; + if (ret) { + dev_warn(&priv->wdev->dev, + "failed to refresh capdata on AC change: %d\n", ret); + + /* + * Our error is non-fatal for others, and we still want + * the other event consumers to process it. + */ + return NOTIFY_DONE; + } =20 return NOTIFY_OK; default: --=20 2.55.0 From nobody Sat Oct 24 13:21:58 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B42051DE1F; Tue, 13 Oct 2026 19:27:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919654; cv=pass; b=qUljQFWGYLJTq9EBEh86hyDSifx4EUPaqZzoCzNpC1cHeA160hOMp3LpYtGsumyZRJgdcyoHnSYB4UUePUAWfOSYwEqUEa8GDkl6LWgFoVfiAzxwAjQfT47Y7TsXFf/lErYZlhQ+7rW0BXdejk0rmooIX5Bo9Qz7a8ajlxV0d54= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919654; c=relaxed/simple; bh=EOnQi+nhIG6yE0e0nAB9TrTzbq3fgWh+7VtgMrlmNfE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dtIIS1TqVBulyIWK9jAWYbMVjD3CBvFan6lDzLjAvPZC+vyuG16GRhrWfPNZeefJglbiFOc3un2qhDEU4+6Q6J8OX/uW3Wzj/s/T6rBnAxAykumF8Oo+U3Ow7RmlFf0yaT7tXLZD/SGEeJbUjM4jhB9WnLj5f3tO2LeesM3WEJg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=GDES8t18; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="GDES8t18" ARC-Seal: i=1; a=rsa-sha256; t=1791919611; cv=none; d=zohomail.com; s=zohoarc; b=YLmqv3Mxz0LSwc3nLLOkO/c6Gt+5LaEf2X2h2QE7QHoooVCiYdrcZv+8p07Fx/8+0vhUWhUZBPJPrEYxzkRS5+sGYyB4aAVbLMo2sna3JKaYO+xjBE+qgWvUKXxTQEsPuU+PtUZatAtfldA038Pcr2lrAeqiwekG83tLgSLPjM4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791919611; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=HjcHdlF7khTPy4vTFsJxIbLHIBS8t2iqrK4gB/L4AdY=; b=nyGCg0Tmsb/Fhz4UK9kLSLrqRDmISH8QqHX6Dqs8vA9KxmPwFthBkQ6VaCztDtV9WC6r9FdjaOnjp+aVYABMkgUC8b+nY8Jsbicpf7KAFEnkTMuuktok38YOWPL2k6NVn35k0H3MBSr1eOt+oR5l0OAp1SMh1Jjr7BLfJXS0Szw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791919611; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=HjcHdlF7khTPy4vTFsJxIbLHIBS8t2iqrK4gB/L4AdY=; b=GDES8t18EBsjXMfTjNElsGFmPAj0RxgpD4iZohZDVNse+P7jcahRAoRWG8E2JbEQ XIX15TCWdDkWZz7qcnd2Mp4LVKWdyoghA2Apu1JqhYaRQezA/xT8V+XwEt/b1trPqzu w7Va3uDmfenSvlDF+vGiaf+qWumcOBOPkZwxrpqNKMhirRbdbiCfqNOEb4f0mFQBU3S 16jvrT5SNsO/XVrJUE8xz/cIVQTKrbweobvXLiNcDI9p0a5MJGBT+BmKPvD/1bSvSZ3 oyqQN3Y0/FQEeciZrun3mhG7Myywg8c851xzTGpa/fVrv9sH6Yr1laRkGnht7o6LGcN eLNrNB3WOQ== Received: by smtp.zohomail.com with SMTPS id 1791919609044202.73846196626505; Tue, 13 Oct 2026 12:26:49 -0700 (PDT) From: Rong Zhang Date: Wed, 14 Oct 2026 03:21:46 +0800 Subject: [PATCH v3 03/12] platform/x86: lenovo-wmi-capdata: Only allocate sub-master info when necessary Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261014-lwmi-wmi-new-api-v3-3-e1032bed1c81@rong.moe> References: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> In-Reply-To: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> To: Mark Pearson , "Derek J. Clark" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Armin Wolf Cc: Charles , Navon John Lukose , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.17-dev-73bef X-ZohoMailClient: External When capdata00 declares no fan test support, there is no need to allocate sub-master info as it's basically unused except for the priv->sub_master->sub_component_list =3D=3D ERR_PTR(-ENODEV) placeholder. Therefore, only allocate priv->sub_master when necessary, otherwise its absence implies the absence of sub-component. With that, PTR_ERR(sub_component_list) =3D=3D -ENODEV is repurposed for the following changes to represent stubbed sub-component. Tested-by: Navon John Lukose Reviewed-by: Derek J. Clark Signed-off-by: Rong Zhang Reported-by: Charles Reported-by: Navon John Lukose Reviewed-by: Mark Pearson Suggested-by: Derek J. Clark Suggested-by: Mark Pearson --- Changes in v3: - Shorten the comments of struct lwmi_cd_priv's members (thanks Derek J. Clark) --- drivers/platform/x86/lenovo/wmi-capdata.c | 34 +++++++++++++++++----------= ---- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/platform/x86/lenovo/wmi-capdata.c b/drivers/platform/x= 86/lenovo/wmi-capdata.c index 58787da959b4..fbe2ba627ff5 100644 --- a/drivers/platform/x86/lenovo/wmi-capdata.c +++ b/drivers/platform/x86/lenovo/wmi-capdata.c @@ -101,9 +101,9 @@ struct lwmi_cd_priv { struct lwmi_cd_sub_master_priv { struct device *master_dev; cd_list_cb_t master_cb; - struct cd_list *sub_component_list; /* ERR_PTR(-ENODEV) implies no sub-c= omponent. */ + struct cd_list *sub_component_list; /* ERR_PTR(-ENODEV): stubbed sub-com= ponent. */ bool registered; /* Has the sub-master been registere= d? */ - } *sub_master; + } *sub_master; /* NULL: no sub-component. */ }; =20 struct cd_list { @@ -258,6 +258,12 @@ static int lwmi_cd_component_bind(struct device *cd_de= v, case LENOVO_CAPABILITY_DATA_00: binder->cd00_list =3D priv->list; =20 + /* Missing sub-master info implies missing sub-component. */ + if (!priv->sub_master) { + binder->cd_fan_list_cb(om_dev, NULL); + break; + } + priv->sub_master->master_dev =3D om_dev; priv->sub_master->master_cb =3D binder->cd_fan_list_cb; lwmi_cd_call_master_cb(priv); @@ -288,13 +294,9 @@ static void lwmi_cd_component_unbind(struct device *cd= _dev, { struct lwmi_cd_priv *priv =3D dev_get_drvdata(cd_dev); =20 - switch (priv->list->type) { - case LENOVO_CAPABILITY_DATA_00: + if (priv->sub_master) { priv->sub_master->master_dev =3D NULL; priv->sub_master->master_cb =3D NULL; - return; - default: - return; } } =20 @@ -369,17 +371,19 @@ static int lwmi_cd_sub_master_add(struct lwmi_cd_priv= *priv, struct component_match *master_match =3D NULL; int ret; =20 + /* + * If the sub-master has no sub-component, there is no need to allocate + * or register the sub-master. The master callback will be called with + * NULL on master <-> sub-master bind to inform the master about the + * absence of sub-component. + */ + if (sub_component_type =3D=3D CD_TYPE_NONE) + return 0; + priv->sub_master =3D devm_kzalloc(&priv->wdev->dev, sizeof(*priv->sub_mas= ter), GFP_KERNEL); if (!priv->sub_master) return -ENOMEM; =20 - if (sub_component_type =3D=3D CD_TYPE_NONE) { - /* The master callback will be called with NULL on bind. */ - priv->sub_master->sub_component_list =3D ERR_PTR(-ENODEV); - priv->sub_master->registered =3D false; - return 0; - } - /* * lwmi_cd_match() needs a pointer to enum lwmi_cd_type, but on-stack * data cannot be used here. Steal one from lwmi_cd_table. @@ -404,7 +408,7 @@ static int lwmi_cd_sub_master_add(struct lwmi_cd_priv *= priv, */ static void lwmi_cd_sub_master_del(struct lwmi_cd_priv *priv) { - if (!priv->sub_master->registered) + if (!priv->sub_master || !priv->sub_master->registered) return; =20 component_master_del(&priv->wdev->dev, &lwmi_cd_sub_master_ops); --=20 2.55.0 From nobody Sat Oct 24 13:21:58 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3FE051596E; Tue, 13 Oct 2026 19:27:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919663; cv=pass; b=V9kQKw41+ksiZ+sLviAuu00RNvnaqSUv724yon+zRa5fQHHEXIctIGnxeP6AgXkQaUyH6wn8mumbbmgiYbdOH4RPIL448hraYTel4eSC7Gr9RZC7m6ACi2QCb/Sz7RzimAuU4HMJRQxNAATRrCagenE72EkjZ+ONVDp94p2syrk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919663; c=relaxed/simple; bh=vUU+EVCbVDWvFg/wDo283Lcu+aR7VUZPIsCjjtCbBiA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=smtHJ4hjSlUBHFKMPzjd485we02P1C1W13ZTmzJObM/YCA172BXmeFJrEe0Y/jjro598rpraUlSJV5HgxOG7t0lURnydDKzKn/wejZa+0c+N4R9HXTutH+YiBJ34yQw6uC6zKU/uiJMgrDZIgzgubdsf9N27nOIdecvivirpYb0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=bu7iGkYJ; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="bu7iGkYJ" ARC-Seal: i=1; a=rsa-sha256; t=1791919614; cv=none; d=zohomail.com; s=zohoarc; b=d44D6j10+yebQD4RSTmJSULTNSntWb2EmoWfBlPFatgfwy6nED2ehJpBemwElR6clRn6V00uqAaZmyIc+l94YEER+2y5J5VEyT8rwM9Yw0flIPEeAcejG4Js/SroB34Ge1QfITh13oRBzjvYUUt3If6djTy0jHWXADxnVBWsI3E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791919614; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=3qkpJcoZWHHFpEAqTLdyt1qMmFetpmA4qvJYokZciDg=; b=Iypp91TfLEIQ92lDvmuJ1Yvg7/jHrXkoZWoiEHxGhiL1GON4g7bEu7vml7Q7xhn5ZA3WVdXRnYg+170hiOklLBm8w73Bfr4vEGxTAyu/cFn1ie3IyMMElRsc9VPdIcviEHf6kWYoDLyhS6IHSlQllqXIOAMD01QfD9bAt+HhvHw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791919614; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=3qkpJcoZWHHFpEAqTLdyt1qMmFetpmA4qvJYokZciDg=; b=bu7iGkYJ0YvGswUM0lHwPyahPayOXwLHhkXsJRKCy2HnAnNPxwwtAyC18Q2spH4M UD+yJCcryYFnB7HD7Sv09kBrAte07sOpgKB0oPjGPbSoxRAYbFigi9rRghlNN6hlvU3 nsg7F6NKAj0sKB0PN8PDLNxnXQjWY+3iTaL3fhqsglmShxIHQehYQjntwZbU4DEl9p5 y0s6RjUxQbNoiXHIthfarNY0qHzKhdHTG2oTOI45sJKfujTY/FLPGxxBMmSbnRu0OuK eOw4oLrqyYJMoOuuWK0at4+lkgaSzC66XREMwCxfICY/vexM4l2O/uBAZh9JSbDGl/H 2mzHYWIcCQ== Received: by smtp.zohomail.com with SMTPS id 179191961160238.814111184771605; Tue, 13 Oct 2026 12:26:51 -0700 (PDT) From: Rong Zhang Date: Wed, 14 Oct 2026 03:21:47 +0800 Subject: [PATCH v3 04/12] platform/x86: lenovo-wmi-capdata: Store a pointer to component info Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261014-lwmi-wmi-new-api-v3-4-e1032bed1c81@rong.moe> References: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> In-Reply-To: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> To: Mark Pearson , "Derek J. Clark" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Armin Wolf Cc: Charles , Navon John Lukose , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.17-dev-73bef X-ZohoMailClient: External In the following changes, priv->list will become optional (i.e., NULLable). IOW, the type of the component cannot be reliable retrieved from priv->list->type. Store a pointer to component info so that the component type is always available. In this manner, priv->list->type can be eliminated. Note that the component type check in lwmi_cd*_get_data() must be removed due to it being called without the availability of priv. Removing it should be fine as the capdata APIs are really internal methods and their caller, i.e., lenovo-wmi-other, always passes a matched list. This also eliminates the need to pass the component type along setup functions. Tested-by: Navon John Lukose Reviewed-by: Derek J. Clark Signed-off-by: Rong Zhang Reported-by: Charles Reported-by: Navon John Lukose Reviewed-by: Mark Pearson Suggested-by: Derek J. Clark Suggested-by: Mark Pearson --- drivers/platform/x86/lenovo/wmi-capdata.c | 44 +++++++++++++--------------= ---- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/drivers/platform/x86/lenovo/wmi-capdata.c b/drivers/platform/x= 86/lenovo/wmi-capdata.c index fbe2ba627ff5..5748859f8101 100644 --- a/drivers/platform/x86/lenovo/wmi-capdata.c +++ b/drivers/platform/x86/lenovo/wmi-capdata.c @@ -87,6 +87,7 @@ static const struct lwmi_cd_info { =20 struct lwmi_cd_priv { struct notifier_block acpi_nb; /* ACPI events */ + const struct lwmi_cd_info *info; struct wmi_device *wdev; struct cd_list *list; struct dentry *debugfs_dir; @@ -108,7 +109,6 @@ struct lwmi_cd_priv { =20 struct cd_list { struct mutex list_mutex; /* list R/W mutex */ - enum lwmi_cd_type type; u8 count; =20 union { @@ -137,7 +137,7 @@ static int lwmi_cd_match(struct device *dev, void *type) return false; =20 priv =3D dev_get_drvdata(dev); - return priv->list->type =3D=3D *(enum lwmi_cd_type *)type; + return priv->info->type =3D=3D *(enum lwmi_cd_type *)type; } =20 /** @@ -254,7 +254,7 @@ static int lwmi_cd_component_bind(struct device *cd_dev, struct lwmi_cd_priv *priv =3D dev_get_drvdata(cd_dev); struct lwmi_cd_binder *binder =3D data; =20 - switch (priv->list->type) { + switch (priv->info->type) { case LENOVO_CAPABILITY_DATA_00: binder->cd00_list =3D priv->list; =20 @@ -452,14 +452,11 @@ static const struct component_ops lwmi_cd_sub_compone= nt_ops =3D { * * Return: 0 on success, or -EINVAL. */ -#define DEF_LWMI_CDXX_GET_DATA(_cdxx, _cd_type, _output_t) \ +#define DEF_LWMI_CDXX_GET_DATA(_cdxx, _output_t) \ int lwmi_##_cdxx##_get_data(struct cd_list *list, u32 attribute_id, _outp= ut_t *output) \ { \ u8 idx; \ \ - if (WARN_ON(list->type !=3D _cd_type)) \ - return -EINVAL; \ - \ guard(mutex)(&list->list_mutex); \ for (idx =3D 0; idx < list->count; idx++) { \ if (list->_cdxx[idx].id !=3D attribute_id) \ @@ -470,13 +467,13 @@ static const struct component_ops lwmi_cd_sub_compone= nt_ops =3D { return -EINVAL; \ } =20 -DEF_LWMI_CDXX_GET_DATA(cd00, LENOVO_CAPABILITY_DATA_00, struct capdata00); +DEF_LWMI_CDXX_GET_DATA(cd00, struct capdata00); EXPORT_SYMBOL_NS_GPL(lwmi_cd00_get_data, "LENOVO_WMI_CAPDATA"); =20 -DEF_LWMI_CDXX_GET_DATA(cd01, LENOVO_CAPABILITY_DATA_01, struct capdata01); +DEF_LWMI_CDXX_GET_DATA(cd01, struct capdata01); EXPORT_SYMBOL_NS_GPL(lwmi_cd01_get_data, "LENOVO_WMI_CAPDATA"); =20 -DEF_LWMI_CDXX_GET_DATA(cd_fan, LENOVO_FAN_TEST_DATA, struct capdata_fan); +DEF_LWMI_CDXX_GET_DATA(cd_fan, struct capdata_fan); EXPORT_SYMBOL_NS_GPL(lwmi_cd_fan_get_data, "LENOVO_WMI_CAPDATA"); =20 /* =3D=3D=3D=3D=3D=3D=3D=3D debugfs =3D=3D=3D=3D=3D=3D=3D=3D */ @@ -550,15 +547,14 @@ static int lwmi_cd_debugfs_show(struct seq_file *s, v= oid *data) =20 guard(mutex)(&priv->list->list_mutex); =20 - /* lwmi_cd_alloc() ensured priv->list->type must be a valid type. */ for (idx =3D 0; idx < priv->list->count; idx++) { - seq_printf(s, "%s[%u]:\n", lwmi_cd_table[priv->list->type].name, idx); + seq_printf(s, "%s[%u]:\n", priv->info->name, idx); =20 - if (priv->list->type =3D=3D LENOVO_CAPABILITY_DATA_00) + if (priv->info->type =3D=3D LENOVO_CAPABILITY_DATA_00) lwmi_cd00_show(s, &priv->list->cd00[idx]); - else if (priv->list->type =3D=3D LENOVO_CAPABILITY_DATA_01) + else if (priv->info->type =3D=3D LENOVO_CAPABILITY_DATA_01) lwmi_cd01_show(s, &priv->list->cd01[idx]); - else if (priv->list->type =3D=3D LENOVO_FAN_TEST_DATA) + else if (priv->info->type =3D=3D LENOVO_FAN_TEST_DATA) lwmi_cd_fan_show(s, &priv->list->cd_fan[idx]); } =20 @@ -603,7 +599,7 @@ static int lwmi_cd_cache(struct lwmi_cd_priv *priv) int idx; void *p; =20 - switch (priv->list->type) { + switch (priv->info->type) { case LENOVO_CAPABILITY_DATA_00: p =3D &priv->list->cd00[0]; size =3D sizeof(priv->list->cd00[0]); @@ -706,14 +702,13 @@ static int lwmi_cd_fan_list_alloc_cache(struct lwmi_c= d_priv *priv, struct cd_lis /** * lwmi_cd_alloc() - Allocate a cd_list struct in drvdata * @priv: lenovo-wmi-capdata driver data. - * @type: The type of capability data. * * Allocate a cd_list struct large enough to contain data from all WMI data * blocks provided by the interface. * * Return: 0 on success, or an error. */ -static int lwmi_cd_alloc(struct lwmi_cd_priv *priv, enum lwmi_cd_type type) +static int lwmi_cd_alloc(struct lwmi_cd_priv *priv) { struct cd_list *list; size_t list_size; @@ -721,7 +716,7 @@ static int lwmi_cd_alloc(struct lwmi_cd_priv *priv, enu= m lwmi_cd_type type) =20 count =3D wmidev_instance_count(priv->wdev); =20 - switch (type) { + switch (priv->info->type) { case LENOVO_CAPABILITY_DATA_00: list_size =3D struct_size(list, cd00, count); break; @@ -747,7 +742,6 @@ static int lwmi_cd_alloc(struct lwmi_cd_priv *priv, enu= m lwmi_cd_type type) if (ret) return ret; =20 - list->type =3D type; list->count =3D count; priv->list =3D list; =20 @@ -757,7 +751,6 @@ static int lwmi_cd_alloc(struct lwmi_cd_priv *priv, enu= m lwmi_cd_type type) /** * lwmi_cd_setup() - Cache all WMI data block information * @priv: lenovo-wmi-capdata driver data. - * @type: The type of capability data. * * Allocate a cd_list struct large enough to contain data from all WMI data * blocks provided by the interface. Then loop through each data block and @@ -765,11 +758,11 @@ static int lwmi_cd_alloc(struct lwmi_cd_priv *priv, e= num lwmi_cd_type type) * * Return: 0 on success, or an error code. */ -static int lwmi_cd_setup(struct lwmi_cd_priv *priv, enum lwmi_cd_type type) +static int lwmi_cd_setup(struct lwmi_cd_priv *priv) { int ret; =20 - ret =3D lwmi_cd_alloc(priv, type); + ret =3D lwmi_cd_alloc(priv); if (ret) return ret; =20 @@ -842,10 +835,11 @@ static int lwmi_cd_probe(struct wmi_device *wdev, con= st void *context) if (!priv) return -ENOMEM; =20 + priv->info =3D info; priv->wdev =3D wdev; dev_set_drvdata(&wdev->dev, priv); =20 - ret =3D lwmi_cd_setup(priv, info->type); + ret =3D lwmi_cd_setup(priv); if (ret) goto out; =20 @@ -911,7 +905,7 @@ static void lwmi_cd_remove(struct wmi_device *wdev) =20 lwmi_cd_debugfs_remove(priv); =20 - switch (priv->list->type) { + switch (priv->info->type) { case LENOVO_CAPABILITY_DATA_00: lwmi_cd_sub_master_del(priv); fallthrough; --=20 2.55.0 From nobody Sat Oct 24 13:21:58 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2FB9B52FE4D; Tue, 13 Oct 2026 19:27:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919674; cv=pass; b=IX7byoGi5wpG0XXTbpCmWUyCpHZ4ZtrNqT+6Lc9FWB4RIJQ25BBZAp6KY8XhzP+Sjn+dXwJ2HzbEewfYfR2SpRltJzt/m982wFu0JApYxha4832F2qb2mNShyQ2RnE9tKYmKTwKKkI+o+dbg6dDV6e9RxstjnIjJrJetlzlbW94= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919674; c=relaxed/simple; bh=RKshi51i/746iDvkAmg4QkUZnCljUvXCyJFKBgsg674=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pi/rBY1GFWmuy0mH0LD6Z73EeDtWTIzEsK0khkClYsg31sJXKZCf158W5kiBETCX0ipweaShz3fA5yj1gTA0aVI3tDBr1vk+DGYIapiX/EvWyGaINkxZidZLHFRjCWp0ug6eEU5QnsRKkZ9rgRL/NlhE0jfOVWDHufiglhm1FoI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=jA6AAb8Z; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="jA6AAb8Z" ARC-Seal: i=1; a=rsa-sha256; t=1791919616; cv=none; d=zohomail.com; s=zohoarc; b=TGSkXjwmlGkaWCIG6H6ixun8pVYwPnCBpOSPriEUEqCfsnDPtp/SBz4egZ10FHIO1WvRNMdb0M7dwL8ffQ6BZoJjsJMdvvc/QtGUr5uNBKrXDqZP79GSH5kv5R3+ApkkaQNHLdKR/b68GS8UqhXrfczf2gn4rXEOer8yQZ+mTl4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791919616; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=xBmCladIJBDvP8VZNRKiXsixskIfXVC6vct1AaMXikw=; b=gJ/V56Jb6Brf8GCQMdwIQvdSNXbSjfuFncB1Q+6uo4Ac19ZiF0mPZxpCGHJlcnRTdwbOA6t9DZFVddR8NVgfCYg6+Yv5d2QT4Y7Gjqvp1vDBaF0nAOiO9vGMV9W8mzIi9p73S0j0U4bDTX+o4IfyVPPGicnGbE31JI2xsc3AUZw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791919616; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=xBmCladIJBDvP8VZNRKiXsixskIfXVC6vct1AaMXikw=; b=jA6AAb8Zum3UkcPXguLRf9UeVg8X3OoN+6DgRt9Ut98FkB2ToVa45tKGW7kHWt+g sFnOpwrmxJU0qk8KD6DoaiCPeHJzuHLMLsJY8rc2Q1zaxbMGzUD0W38jwObdGgmEvPb hXVcV9Ma+raZmjyK+hEw+/pxiTvxeUvzIs5/BNyqD5N2Pk56VCl8fZ4iL9I/DlAFOE8 P7TrLyVGbgDcpaYafb0Z2mRvo3mgiDyN9UqmIez9jrE2JZSvczGKMLbWq26r/QARWkU kqCnzUdYZSlTU8b9CMlsNCNVSi9XNp58bHROatHbXkUbKZpcJpwM/KkRN0j/Lq41WP6 S3L9XmKUMA== Received: by smtp.zohomail.com with SMTPS id 1791919614178821.0788592501591; Tue, 13 Oct 2026 12:26:54 -0700 (PDT) From: Rong Zhang Date: Wed, 14 Oct 2026 03:21:48 +0800 Subject: [PATCH v3 05/12] platform/x86: lenovo-wmi-capdata: Defer mutex initialization Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261014-lwmi-wmi-new-api-v3-5-e1032bed1c81@rong.moe> References: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> In-Reply-To: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> To: Mark Pearson , "Derek J. Clark" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Armin Wolf Cc: Charles , Navon John Lukose , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.17-dev-73bef X-ZohoMailClient: External In the following changes, priv->list may be freed if the first call to lwmi_cd_cache() fails due to WMI/ACPI errors, so the list_mutex must be initialized after it in order not to break lockdep, as there is no devm_mutex_destroy(). Considering that the first call to lwmi_cd_cache() doesn't need serialization as there is no other reader or writer this early, the initialization of list_mutex can be deferred. Therefore, initialize list_mutex only after the first call to lwmi_cd_cache() succeeds, otherwise it remains uninitialized and can be devm_kfree()-ed. Tested-by: Navon John Lukose Reviewed-by: Derek J. Clark Signed-off-by: Rong Zhang Reported-by: Charles Reported-by: Navon John Lukose Reviewed-by: Mark Pearson Suggested-by: Derek J. Clark Suggested-by: Mark Pearson --- Changes in v2: - Synchronize the initialization with release-acquire barriers (thanks Ilpo J=C3=A4rvinen) --- drivers/platform/x86/lenovo/wmi-capdata.c | 86 +++++++++++++++++++++++----= ---- 1 file changed, 65 insertions(+), 21 deletions(-) diff --git a/drivers/platform/x86/lenovo/wmi-capdata.c b/drivers/platform/x= 86/lenovo/wmi-capdata.c index 5748859f8101..3ef8879d8587 100644 --- a/drivers/platform/x86/lenovo/wmi-capdata.c +++ b/drivers/platform/x86/lenovo/wmi-capdata.c @@ -48,6 +48,8 @@ #include #include =20 +#include + #include "wmi-capdata.h" #include "wmi-helpers.h" =20 @@ -91,6 +93,7 @@ struct lwmi_cd_priv { struct wmi_device *wdev; struct cd_list *list; struct dentry *debugfs_dir; + bool initialized; =20 /* * A capdata device may be a component master of another capdata device. @@ -586,14 +589,14 @@ static void lwmi_cd_debugfs_remove(struct lwmi_cd_pri= v *priv) /* =3D=3D=3D=3D=3D=3D=3D=3D WMI interface =3D=3D=3D=3D=3D=3D=3D=3D */ =20 /** - * lwmi_cd_cache() - Cache all WMI data block information + * __lwmi_cd_cache() - Cache all WMI data block information locklessly * @priv: lenovo-wmi-capdata driver data. * - * Loop through each WMI data block and cache the data. + * Loop through each WMI data block and cache the data locklessly. * * Return: 0 on success, or an error. */ -static int lwmi_cd_cache(struct lwmi_cd_priv *priv) +static int __lwmi_cd_cache(struct lwmi_cd_priv *priv) { size_t size; int idx; @@ -615,7 +618,6 @@ static int lwmi_cd_cache(struct lwmi_cd_priv *priv) return -EINVAL; } =20 - guard(mutex)(&priv->list->list_mutex); for (idx =3D 0; idx < priv->list->count; idx++, p +=3D size) { union acpi_object *ret_obj __free(kfree) =3D NULL; =20 @@ -633,14 +635,38 @@ static int lwmi_cd_cache(struct lwmi_cd_priv *priv) return 0; } =20 +/** + * lwmi_cd_cache() - Cache all WMI data block information + * @priv: lenovo-wmi-capdata driver data. + * + * Loop through each WMI data block and cache the data. + * + * Return: 0 on success, or an error. + */ +static int lwmi_cd_cache(struct lwmi_cd_priv *priv) +{ + /* Synchronize mutex initialization. Paired with lwmi_cd_finalize(). */ + if (!smp_load_acquire(&priv->initialized)) + return __lwmi_cd_cache(priv); + + switch (priv->info->type) { + case LENOVO_CAPABILITY_DATA_01: + break; + default: + return -EINVAL; + } + + guard(mutex)(&priv->list->list_mutex); + return __lwmi_cd_cache(priv); +} + /** * lwmi_cd_fan_list_alloc_cache() - Alloc and cache Fan Test Data list * @priv: lenovo-wmi-capdata driver data. - * @listptr: Pointer to returned cd_list pointer. * - * Return: count of fans found, or an error. + * Return: 0 on success, or an error. */ -static int lwmi_cd_fan_list_alloc_cache(struct lwmi_cd_priv *priv, struct = cd_list **listptr) +static int lwmi_cd_fan_list_alloc_cache(struct lwmi_cd_priv *priv) { struct cd_list *list; size_t size; @@ -686,6 +712,9 @@ static int lwmi_cd_fan_list_alloc_cache(struct lwmi_cd_= priv *priv, struct cd_lis if (!list) return -ENOMEM; =20 + list->count =3D count; + priv->list =3D list; + for (idx =3D 0; idx < count; idx++) { /* Do not calculate array index using count, as it may be truncated. */ list->cd_fan[idx] =3D (struct capdata_fan) { @@ -695,8 +724,7 @@ static int lwmi_cd_fan_list_alloc_cache(struct lwmi_cd_= priv *priv, struct cd_lis }; } =20 - *listptr =3D list; - return count; + return 0; } =20 /** @@ -712,7 +740,7 @@ static int lwmi_cd_alloc(struct lwmi_cd_priv *priv) { struct cd_list *list; size_t list_size; - int count, ret; + int count; =20 count =3D wmidev_instance_count(priv->wdev); =20 @@ -724,11 +752,7 @@ static int lwmi_cd_alloc(struct lwmi_cd_priv *priv) list_size =3D struct_size(list, cd01, count); break; case LENOVO_FAN_TEST_DATA: - count =3D lwmi_cd_fan_list_alloc_cache(priv, &list); - if (count < 0) - return count; - - goto got_list; + return lwmi_cd_fan_list_alloc_cache(priv); default: return -EINVAL; } @@ -737,17 +761,33 @@ static int lwmi_cd_alloc(struct lwmi_cd_priv *priv) if (!list) return -ENOMEM; =20 -got_list: - ret =3D devm_mutex_init(&priv->wdev->dev, &list->list_mutex); - if (ret) - return ret; - list->count =3D count; priv->list =3D list; =20 return 0; } =20 +/** + * lwmi_cd_finalize() - Finalize the capability data initialization + * @priv: lenovo-wmi-capdata driver data. + * + * Return: 0 on success, or an error code. + */ +static int lwmi_cd_finalize(struct lwmi_cd_priv *priv) +{ + int ret; + + if (priv->list) { + ret =3D devm_mutex_init(&priv->wdev->dev, &priv->list->list_mutex); + if (ret) + return ret; + } + + /* Synchronize mutex initialization. Paired with lwmi_cd_cache(). */ + smp_store_release(&priv->initialized, 1); + return 0; +} + /** * lwmi_cd_setup() - Cache all WMI data block information * @priv: lenovo-wmi-capdata driver data. @@ -766,7 +806,11 @@ static int lwmi_cd_setup(struct lwmi_cd_priv *priv) if (ret) return ret; =20 - return lwmi_cd_cache(priv); + ret =3D lwmi_cd_cache(priv); + if (ret) + return ret; + + return lwmi_cd_finalize(priv); } =20 /** --=20 2.55.0 From nobody Sat Oct 24 13:21:58 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8BC253F6A9; Tue, 13 Oct 2026 19:28:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919683; cv=pass; b=ci1oWbVIWsKVFmIsUoKEZzZaVLnbDZ0BStdKu4dDLED/EP+O1O5/DUI+WRfvrsZ+wsD3gYMu1JQvFn9U/uqFMCCBuxQeS+j3KVilYXBI3P4V3UM38+JMYX3FJ6tF26k3i8dLvUOsCT940KnVX1UN+3m/hZo2AISAyXdIZuz8+F8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919683; c=relaxed/simple; bh=iRXUZqFPPpJ25YkGuCknxQTbLHCKfYV9llRV76+HIyI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VAyR6+VWv1woi2202ZlirivlI79F83zYG7+8uqe99syLJftOthtEp8wUlRbqtYnnow2cW3ARwsrGgaUl9D5TN8Ue9GbLvEk4ql9p/NOQSUMWzWB4/NOCC8oecAq0e0QEREl1TikUq4+TXrme43anPTGeWWxLkvFI2ElM7g41aPc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=XJSrhWYO; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="XJSrhWYO" ARC-Seal: i=1; a=rsa-sha256; t=1791919617; cv=none; d=zohomail.com; s=zohoarc; b=Jc3aKoRBNdnncmXJVuPjMsjLJNhoVEgT+tXDlL2BfD+3W7sPWgAfprQXjt/obbPJOeOvdBLkm3+as1pVTxbu6CyQkPP/McDg/h6yONAnr9hUJ2vMWhkyRUwgTT7WXyavSBaZSaLggU1GqLvho/dkdkyPE7DSOnZQhArzj2onJEE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791919617; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=oGfX1urLw9UobKagc1pefW/2V9yNTK3tkxEu83nmGzQ=; b=bUthvWJgghei9fuAcG1pqOGvOw8P0ZPiDJlhGf4cUk+tStLoAVwCpqGC/He2HzEZKSGoYhTo3NAPgJ2cdZhNmrqdUAy+Rn1xdehVa/vzNcycdYeiHdHYYCylIuaN74/hgGjAVPFU5IG/TbtZJQcEE8RRFL6yfeiRQNQPS30tNC8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791919617; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=oGfX1urLw9UobKagc1pefW/2V9yNTK3tkxEu83nmGzQ=; b=XJSrhWYOntmPZWyfBeyKufQHaWWDhIyX2JxK0KAE4rNpNKGEpKhes0EL2D/nO0eT ZGY1+Z/Ctlit3YdYTwwsXtEwTVRDKe4L0PcWJNdwEIBT5+qvQUAGl+L2XuzJvT0Cmd2 Pv9yzL6xScOS1rdWqxygJv46gdFGAkLwsByZav11rAfaPiXejMWucwxpvH/CI3kKnjl rkkvGaBhw6p6eQmlyst/PqiktDcCTYfMKthEituC2ZtTTjFWc6WNf9MQW4erZBHQraZ c30z9YsI6rXn0ejYMqlnShhqkuidVmZ/HJUBzxwOvWaw7vZW+SoxT6ZBIO+uu9r1y58 llxlyFh8iw== Received: by smtp.zohomail.com with SMTPS id 1791919616834128.51599979007904; Tue, 13 Oct 2026 12:26:56 -0700 (PDT) From: Rong Zhang Date: Wed, 14 Oct 2026 03:21:49 +0800 Subject: [PATCH v3 06/12] platform/x86: lenovo-wmi-{capdata,other}: Only allocate capdata list when necessary Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261014-lwmi-wmi-new-api-v3-6-e1032bed1c81@rong.moe> References: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> In-Reply-To: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> To: Mark Pearson , "Derek J. Clark" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Armin Wolf Cc: Charles , Navon John Lukose , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.17-dev-73bef X-ZohoMailClient: External When no capability data is available, there is no need to allocate capability data list as it's basically unused except for the priv->list->count =3D=3D 0 placeholder. Therefore, only allocate priv->list when necessary, otherwise its absence implies the absence of capability data. In this manner, lenovo-wmi-other can skip registering unavailable functionalities accordingly. Meanwhile, skip creating the debugfs directory as it provides nothing when there is no capability data. Tested-by: Navon John Lukose Reviewed-by: Derek J. Clark Signed-off-by: Rong Zhang Reported-by: Charles Reported-by: Navon John Lukose Reviewed-by: Mark Pearson Suggested-by: Derek J. Clark Suggested-by: Mark Pearson --- Changes in v2: - Refine line wrap (thanks Ilpo J=C3=A4rvinen) --- drivers/platform/x86/lenovo/wmi-capdata.c | 42 ++++++++++++++++++++++-----= ---- drivers/platform/x86/lenovo/wmi-other.c | 24 +++++++++++------- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/drivers/platform/x86/lenovo/wmi-capdata.c b/drivers/platform/x= 86/lenovo/wmi-capdata.c index 3ef8879d8587..3c09bb9e3d46 100644 --- a/drivers/platform/x86/lenovo/wmi-capdata.c +++ b/drivers/platform/x86/lenovo/wmi-capdata.c @@ -313,8 +313,8 @@ static const struct component_ops lwmi_cd_component_ops= =3D { * @dev: The sub-master capdata basic device. * * Call component_bind_all to bind the sub-component device to the sub-mas= ter - * device. On success, collect the pointer to the sub-component list and t= ry - * to call the master callback. + * device. On success, collect the pointer (or ERR_PTR(-ENODEV) if it's st= ubbed) + * to the sub-component list and try to call the master callback. * * Return: 0 on success, or an error code. */ @@ -328,7 +328,7 @@ static int lwmi_cd_sub_master_bind(struct device *dev) if (ret) return ret; =20 - priv->sub_master->sub_component_list =3D sub_component_list; + priv->sub_master->sub_component_list =3D sub_component_list ?: ERR_PTR(-E= NODEV); lwmi_cd_call_master_cb(priv); =20 return 0; @@ -460,6 +460,9 @@ static const struct component_ops lwmi_cd_sub_component= _ops =3D { { \ u8 idx; \ \ + if (WARN_ON(!list)) \ + return -EINVAL; \ + \ guard(mutex)(&list->list_mutex); \ for (idx =3D 0; idx < list->count; idx++) { \ if (list->_cdxx[idx].id !=3D attribute_id) \ @@ -571,6 +574,9 @@ DEFINE_SHOW_ATTRIBUTE(lwmi_cd_debugfs); */ static void lwmi_cd_debugfs_add(struct lwmi_cd_priv *priv) { + if (!priv->list) + return; + priv->debugfs_dir =3D lwmi_debugfs_create_dir(priv->wdev); =20 debugfs_create_file("capdata", 0444, priv->debugfs_dir, priv, &lwmi_cd_de= bugfs_fops); @@ -582,6 +588,7 @@ static void lwmi_cd_debugfs_add(struct lwmi_cd_priv *pr= iv) */ static void lwmi_cd_debugfs_remove(struct lwmi_cd_priv *priv) { + /* Debugfs can handle NULL dir, no need to check. */ debugfs_remove_recursive(priv->debugfs_dir); priv->debugfs_dir =3D NULL; } @@ -645,6 +652,9 @@ static int __lwmi_cd_cache(struct lwmi_cd_priv *priv) */ static int lwmi_cd_cache(struct lwmi_cd_priv *priv) { + if (!priv->list) + return 0; + /* Synchronize mutex initialization. Paired with lwmi_cd_finalize(). */ if (!smp_load_acquire(&priv->initialized)) return __lwmi_cd_cache(priv); @@ -708,6 +718,9 @@ static int lwmi_cd_fan_list_alloc_cache(struct lwmi_cd_= priv *priv) count =3D 0; } =20 + if (!count) + return 0; + list =3D devm_kzalloc(&priv->wdev->dev, struct_size(list, cd_fan, count),= GFP_KERNEL); if (!list) return -ENOMEM; @@ -743,6 +756,8 @@ static int lwmi_cd_alloc(struct lwmi_cd_priv *priv) int count; =20 count =3D wmidev_instance_count(priv->wdev); + if (!count) + return 0; =20 switch (priv->info->type) { case LENOVO_CAPABILITY_DATA_00: @@ -892,7 +907,8 @@ static int lwmi_cd_probe(struct wmi_device *wdev, const= void *context) enum lwmi_cd_type sub_component_type =3D LENOVO_FAN_TEST_DATA; struct capdata00 capdata00; =20 - ret =3D lwmi_cd00_get_data(priv->list, LWMI_ATTR_ID_FAN_TEST, &capdata00= ); + ret =3D priv->list ? lwmi_cd00_get_data(priv->list, LWMI_ATTR_ID_FAN_TES= T, + &capdata00) : -ENODATA; if (ret || !(capdata00.supported & LWMI_SUPP_VALID)) { dev_dbg(&wdev->dev, "capdata00 declares no fan test support\n"); sub_component_type =3D CD_TYPE_NONE; @@ -913,14 +929,16 @@ static int lwmi_cd_probe(struct wmi_device *wdev, con= st void *context) case LENOVO_CAPABILITY_DATA_01: priv->acpi_nb.notifier_call =3D lwmi_cd01_notifier_call; =20 - ret =3D register_acpi_notifier(&priv->acpi_nb); - if (ret) - goto out; + if (priv->list) { + ret =3D register_acpi_notifier(&priv->acpi_nb); + if (ret) + goto out; =20 - ret =3D devm_add_action_or_reset(&wdev->dev, lwmi_cd01_unregister, - &priv->acpi_nb); - if (ret) - goto out; + ret =3D devm_add_action_or_reset(&wdev->dev, lwmi_cd01_unregister, + &priv->acpi_nb); + if (ret) + goto out; + } =20 ret =3D component_add(&wdev->dev, &lwmi_cd_component_ops); goto out; @@ -938,7 +956,7 @@ static int lwmi_cd_probe(struct wmi_device *wdev, const= void *context) lwmi_cd_debugfs_add(priv); =20 dev_dbg(&wdev->dev, "registered %s with %u items\n", - info->name, priv->list->count); + info->name, priv->list ? priv->list->count : 0); } return ret; } diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86= /lenovo/wmi-other.c index fbb32bf404f2..147e182685a1 100644 --- a/drivers/platform/x86/lenovo/wmi-other.c +++ b/drivers/platform/x86/lenovo/wmi-other.c @@ -1619,11 +1619,14 @@ static void lwmi_om_fw_attr_remove(struct lwmi_om_p= riv *priv) * lenovo-wmi-other master driver, with a callback to collect fan info from * capdata_fan. On success, assign the capability data list pointers to the * driver data struct for later access. These pointers are only valid whil= e the - * capdata interfaces exist. Finally, collect fan info from capdata00 and - * register all firmware attribute groups. Note that the HWMON device is - * registered only if all fan info is collected. Hence, it is not register= ed - * here. See lwmi_om_fan_info_collect_cd00() and - * lwmi_om_fan_info_collect_cd_fan(). + * capdata interfaces exist. + * + * If capdata00 is bound, collect fan info from capdata00 and register the= power + * supply extension. Note that the HWMON device is registered only if all = fan + * info is collected. Hence, it is not registered here. See + * lwmi_om_fan_info_collect_cd00() and lwmi_om_fan_info_collect_cd_fan(). + * + * If capdata01 is bound, register all firmware attribute groups. * * Return: 0 on success, or an error code. */ @@ -1643,16 +1646,19 @@ static int lwmi_om_master_bind(struct device *dev) =20 priv->cd00_list =3D binder.cd00_list; priv->cd01_list =3D binder.cd01_list; - if (!priv->cd00_list || !priv->cd01_list) { + if (!priv->cd00_list && !priv->cd01_list) { component_unbind_all(dev, NULL); =20 return -ENODEV; } =20 - lwmi_om_fan_info_collect_cd00(priv); - lwmi_om_psy_ext_init(priv); + if (priv->cd00_list) { + lwmi_om_fan_info_collect_cd00(priv); + lwmi_om_psy_ext_init(priv); + } =20 - lwmi_om_fw_attr_add(priv); + if (priv->cd01_list) + lwmi_om_fw_attr_add(priv); =20 return 0; } --=20 2.55.0 From nobody Sat Oct 24 13:21:58 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F81553FD45; Tue, 13 Oct 2026 19:28:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919696; cv=pass; b=eSDkNH3dINFN5F7A9XZtq1XUCGRJ6pF9uGoTvlXCESrMblYvkXfvbTDKe7B9iWhXfW412KXNFlRQxjgYIXjnGwQhty9DKosfThX3wgLp/k4mVDFOfKc0iMu8A2ljvrw2iT3V5AQrA6JtRfjv5ensn9Ks3OKEqx59iZJKE2RCpMc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919696; c=relaxed/simple; bh=OPdHYTRxAMKwJ5x9sc9T3VWr7jmnIH3F+aS5+9RWjC4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PfCoR0FKlKrm8zp/ZlOPLWr3EhsLl3ZfngJ16E0udqk2D+lwUY2oyRbZtzH+L8MofVe1F6i/ZN4xaCxAYq/NlXLuxwj/qPPTIAar6C7N16jQFaTpwN02RBgalFbKZv71wpgIruO7W1DtBm8qcZoRuimQWJ+cZ/lu9bMxo2nWD1s= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=qZeqnbIB; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="qZeqnbIB" ARC-Seal: i=1; a=rsa-sha256; t=1791919622; cv=none; d=zohomail.com; s=zohoarc; b=UAw8DauB10tHLGthDetrCPDmfuJWIoaK2Gak4rjIATet6f4/NmcYmL1lKDPgqPwfG/pUaVKstZl2u105MufGk6l7PlWxL8nC+ROM2YfEMrjm+Gof1SSFsyFILc33SEOUQvu1ggUfoBklAcA6kIY3nUAST4B0tpXGH+ZTas3buu8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791919622; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=gdsTya4Xwf6ghj7dLSQAZZMnNpsvUz00TfCufqZ4bS8=; b=HsU7VGhocJGhm1SkpCinBY0Ua6GeOSXtbxa+1Cfjc2LRQX9a4jjqlL5BRuNShjkCLz6lAvUfdBwkCilFoWQk72YRm3u16nHJgL2j1ivnAOxH/OpGRPDYLwzocFsDpYIPjVZ+F+47ZIkXPhWve+VamC5L1bb415McEJMrhQRFqJI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791919621; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=gdsTya4Xwf6ghj7dLSQAZZMnNpsvUz00TfCufqZ4bS8=; b=qZeqnbIBHnxl5kJBFqLhknEJINEfVfyaHaJ2ywIA8YkJr9jx4nPCgR8RNI5uYc+L ECu2x6vNXmKwBLS//hsBsEh/5magYY5Fp0/UpjKgpYBuFLXT2OTGH6bhYarwfr81GCo xbF7i/YELgdNI76RVEbB7WWNwa2AyJpO/l8F8UnB/sQkDyz3P4YbcrfTrBVQCvLCB64 MBbd7bZxHFL0hGCqcFb5I7Q6NGhDFkOrYy1sL9esqDAlRmSfNXu5vKIodncS3nDScym dyaMJ12y0AIe5Nre3HjayiNqMYZ08b+5mENk2fFoa0kDcxWrABoKnfsN561OPB4cjtX +X3RebIemw== Received: by smtp.zohomail.com with SMTPS id 1791919619373463.8231147683416; Tue, 13 Oct 2026 12:26:59 -0700 (PDT) From: Rong Zhang Date: Wed, 14 Oct 2026 03:21:50 +0800 Subject: [PATCH v3 07/12] platform/x86: lenovo-wmi-capdata: Adopt new WMI API Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261014-lwmi-wmi-new-api-v3-7-e1032bed1c81@rong.moe> References: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> In-Reply-To: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> To: Mark Pearson , "Derek J. Clark" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Armin Wolf Cc: Charles , Navon John Lukose , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.17-dev-73bef X-ZohoMailClient: External The new WMI API supports multiple ACPI types by converting them into a unified buffer that satisfies alignment and size requirements. Adopt it to make our life easier. Note that the new WMI API only accepts a few ACPI types to conform to the behavior of the Windows WMI-ACPI driver. By adopting the new API, we intentionally rejects improper ACPI types instead of silently ignoring them. Meanwhile, considering that `struct_size(block, data, count * 3)' may overflow when calculating `count * 3', ignore Fan Test Data with count > U8_MAX instead of caping `count'. Reviewed-by: Armin Wolf Tested-by: Navon John Lukose Reviewed-by: Derek J. Clark Signed-off-by: Rong Zhang Reported-by: Charles Reported-by: Navon John Lukose Reviewed-by: Mark Pearson Suggested-by: Derek J. Clark Suggested-by: Mark Pearson --- Changes in v3: - Leave struct cd_fan_block's __packed attribute as is (thanks Armin Wolf) --- drivers/platform/x86/lenovo/wmi-capdata.c | 70 ++++++++++++++-------------= ---- 1 file changed, 31 insertions(+), 39 deletions(-) diff --git a/drivers/platform/x86/lenovo/wmi-capdata.c b/drivers/platform/x= 86/lenovo/wmi-capdata.c index 3c09bb9e3d46..abf5ffda7163 100644 --- a/drivers/platform/x86/lenovo/wmi-capdata.c +++ b/drivers/platform/x86/lenovo/wmi-capdata.c @@ -626,17 +626,19 @@ static int __lwmi_cd_cache(struct lwmi_cd_priv *priv) } =20 for (idx =3D 0; idx < priv->list->count; idx++, p +=3D size) { - union acpi_object *ret_obj __free(kfree) =3D NULL; + struct wmi_buffer wbuf; + int ret; =20 - ret_obj =3D wmidev_block_query(priv->wdev, idx); - if (!ret_obj) - return -ENODEV; - - if (ret_obj->type !=3D ACPI_TYPE_BUFFER || - ret_obj->buffer.length < size) + ret =3D wmidev_query_block(priv->wdev, idx, &wbuf, size); + if (ret =3D=3D -ENODATA) /* The block is too short, probably stubbed. */ continue; + if (ret) + return ret; + + /* Capdata 01 is an extension to capdata 00. */ + struct capdata00 *capdata __free(kfree) =3D wbuf.data; =20 - memcpy(p, ret_obj->buffer.pointer, size); + memcpy(p, capdata, size); } =20 return 0; @@ -678,43 +680,34 @@ static int lwmi_cd_cache(struct lwmi_cd_priv *priv) */ static int lwmi_cd_fan_list_alloc_cache(struct lwmi_cd_priv *priv) { + struct wmi_buffer wbuf; struct cd_list *list; - size_t size; + int ret, idx; u32 count; - int idx; =20 - /* Emit unaligned access to u8 buffer with __packed. */ struct cd_fan_block { u32 nr; u32 data[]; /* id[nr], max_rpm[nr], min_rpm[nr] */ - } __packed * block; + } __packed; =20 - union acpi_object *ret_obj __free(kfree) =3D wmidev_block_query(priv->wde= v, 0); - if (!ret_obj) - return -ENODEV; + ret =3D wmidev_query_block(priv->wdev, 0, &wbuf, sizeof(struct cd_fan_blo= ck)); + if (ret =3D=3D -ENODATA) /* The block is too short, probably stubbed. */ + return 0; + if (ret) + return ret; =20 - if (ret_obj->type =3D=3D ACPI_TYPE_BUFFER) { - block =3D (struct cd_fan_block *)ret_obj->buffer.pointer; - size =3D ret_obj->buffer.length; + struct cd_fan_block *block __free(kfree) =3D wbuf.data; =20 - count =3D size >=3D sizeof(*block) ? block->nr : 0; - if (size < struct_size(block, data, count * 3)) { - dev_warn(&priv->wdev->dev, - "incomplete fan test data block: %zu < %zu, ignoring\n", - size, struct_size(block, data, count * 3)); - count =3D 0; - } else if (count > U8_MAX) { - dev_warn(&priv->wdev->dev, - "too many fans reported: %u > %u, truncating\n", - count, U8_MAX); - count =3D U8_MAX; - } - } else { - /* - * This is usually caused by a dummy ACPI method. Do not return an error - * as failing to probe this device will result in sub-master device being - * unbound. This behavior aligns with lwmi_cd_cache(). - */ + count =3D block->nr; + + if (count > U8_MAX) { + dev_warn(&priv->wdev->dev, + "too many fans reported: %u > %u, ignoring\n", count, U8_MAX); + count =3D 0; + } else if (wbuf.length < struct_size(block, data, count * 3)) { + dev_warn(&priv->wdev->dev, + "incomplete fan test data block: %zu < %zu (%u fans), ignoring\n", + wbuf.length, struct_size(block, data, count * 3), count); count =3D 0; } =20 @@ -729,11 +722,10 @@ static int lwmi_cd_fan_list_alloc_cache(struct lwmi_c= d_priv *priv) priv->list =3D list; =20 for (idx =3D 0; idx < count; idx++) { - /* Do not calculate array index using count, as it may be truncated. */ list->cd_fan[idx] =3D (struct capdata_fan) { .id =3D block->data[idx], - .max_rpm =3D block->data[idx + block->nr], - .min_rpm =3D block->data[idx + (2 * block->nr)], + .max_rpm =3D block->data[idx + count], + .min_rpm =3D block->data[idx + (2 * count)], }; } =20 --=20 2.55.0 From nobody Sat Oct 24 13:21:58 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8F4A5293F6; Tue, 13 Oct 2026 19:28:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919706; cv=pass; b=nnpK1h8XJiStaLFiU1CfzoFp/z0JlthrAjoaEY3yP58t0NuLdOHUR2LGWTSNlRip7rGZlcKZixA6y2lA8LMrt7DTEPUvRtK38QMUy50iXkw9Z1fNvPvXFa/xpKKEgEJfU2rfvtNer38PM70sfRIbNnQDiZiGHOrGAikkZkcNRnQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919706; c=relaxed/simple; bh=BK9zPgZ4NjnJkQUnOeM3fi3M8R+OeU0xBp5LqbrU88Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KlbJT9GcpGp8YMEVusoJPnAibkIlBq58pe2ocVooVpDxjEsmXa/pjJkfTFafHc3DorxNQJik6Ls46GnJPAA37rcgMSxQeuK2z64PAbpfgED1qcGnU2sMkwwWUMgD9A52VF7N+hvtCUNuB7SUFm+JNdbCsO/1DSD3fUzSIdCRNpE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=XjQX4cmR; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="XjQX4cmR" ARC-Seal: i=1; a=rsa-sha256; t=1791919624; cv=none; d=zohomail.com; s=zohoarc; b=VekdCNZzg2SvWW2k64itRp25XG6+TsKcL1uW9j/WOw8nXxMPV67EmQdD3RgUM4WxP6Kof7JF34zJtj0IebNukjIoGR0vMn6tzz475Mpv0cSEKlibiv6M/S4tS5Mfwr9YzncurN1cbSz1pb0alExmrD+KmBLgwGA2PDprCwu2NTQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791919624; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=6yk3KjRB3nrjjjf75SCpbNtXXfXfBd5qBXdFyBHV5OU=; b=k4pUu/NeEu2ngq84O3yAMCN9aAlPpVYwQyZ3OPrRtZvlB5lTjCnV4hU9fJKVQVK/gfuz7LQWnEaF2M6qsnmkLnPPglMLA5mrglbkyB52Rc4MkfruVlyuIkSghWq0KC7zPqr8A+4ikHBGn8zbKljPAwvAMMjGxLb/px1B9GzLxpA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791919624; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=6yk3KjRB3nrjjjf75SCpbNtXXfXfBd5qBXdFyBHV5OU=; b=XjQX4cmRB9b64OcLcTlaM/tLmePcxCmi9zfgYOy5PdE3sHpWNMOnXvCYykAa0+me zscUAk5tdytMGOwV36aXJlmAwwhyunyFBtFcVduqY4DmTZNK2bj5xyDs9ABn8UGTM3d h0uxUzMCt+1pWRzMQ7SrDgVYRWZwh8tKZv0A/fv8bFzPlYKYQb5q0YORBEJ/vE/LcgT jFR7MzrKiyzDTr7b+Rh4LYdKtohgKjio5umNuJN+cjoWlkvULeZRv700n3IE4SZPGfE R51KLJ7e3C1YD6fnMjGkofNrmiqSafbZXNTAtbfKncCHHxM3JHVcDC585Aw2m5fau2O XvsTnf461g== Received: by smtp.zohomail.com with SMTPS id 1791919621912708.0975044850209; Tue, 13 Oct 2026 12:27:01 -0700 (PDT) From: Rong Zhang Date: Wed, 14 Oct 2026 03:21:51 +0800 Subject: [PATCH v3 08/12] platform/x86: lenovo-wmi-capdata: Register component even on WMI error Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261014-lwmi-wmi-new-api-v3-8-e1032bed1c81@rong.moe> References: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> In-Reply-To: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> To: Mark Pearson , "Derek J. Clark" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Armin Wolf Cc: Charles , Navon John Lukose , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.17-dev-73bef X-ZohoMailClient: External Some devices do not support LENOVO_CAPABILITY_DATA_01 and define the query method as a stub that returns zero buffer. Unfortunately, some devices do not implement the stub properly, causing WMI errors (including ACPI errors). The current lenovo-wmi-* implementation enforces the binding between LENOVO_CAPABILITY_DATA_00+01 and LENOVO_OTHER_MODE because of a limitation of the device component framework. When the capdata device bailing out due to a WMI error, lenovo-wmi-other becomes unbound and unable to provide firmware-attributes or hwmon device for the other functional capdata device. Therefore, errors must be non-fatal in order not to break the assumptions made by the device component framework. Stub the capdata device by releasing the capability data list in this case. After that, NULL list will be passed to lenovo-wmi-other on bind. The latter will provide whatever is available, or unbind the components if nothing is available. A stubbed capdata device releases or skips allocating most resources, e.g., the capability data list and the debugfs directory. The device itself is only used to satisfy the component dependency of lenovo-wmi- other and coordinate with the latter about the absence of the capability data. Reported-by: Charles Closes: https://msgid.link/CAKtz0s8UYRQYW_0bh=3D0TMx47Axm-W-muEay-r3rqUBS1N= HMPVw@mail.gmail.com/ Tested-by: Navon John Lukose Reviewed-by: Derek J. Clark Signed-off-by: Rong Zhang Reported-by: Navon John Lukose Reviewed-by: Mark Pearson Suggested-by: Derek J. Clark Suggested-by: Mark Pearson --- Changes in v2: - Replace the term "poison" with "stub" (thanks Ilpo J=C3=A4rvinen) --- drivers/platform/x86/lenovo/wmi-capdata.c | 94 +++++++++++++++++++++++++++= ++-- 1 file changed, 90 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/lenovo/wmi-capdata.c b/drivers/platform/x= 86/lenovo/wmi-capdata.c index abf5ffda7163..71ea31482987 100644 --- a/drivers/platform/x86/lenovo/wmi-capdata.c +++ b/drivers/platform/x86/lenovo/wmi-capdata.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -38,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +47,7 @@ #include #include #include +#include #include #include =20 @@ -447,7 +450,7 @@ static const struct component_ops lwmi_cd_sub_component= _ops =3D { /* * lwmi_cd*_get_data - Get the data of the specified attribute * @list: The lenovo-wmi-capdata pointer to its cd_list struct. - * @attribute_id: The capdata attribute ID to be found. + * @attribute_id: The capdata attribute ID (non-zero) to be found. * @output: Pointer to a capdata* struct to return the data. * * Retrieves the capability data struct pointer for the given @@ -460,7 +463,7 @@ static const struct component_ops lwmi_cd_sub_component= _ops =3D { { \ u8 idx; \ \ - if (WARN_ON(!list)) \ + if (WARN_ON(!list || !attribute_id)) \ return -EINVAL; \ \ guard(mutex)(&list->list_mutex); \ @@ -595,6 +598,89 @@ static void lwmi_cd_debugfs_remove(struct lwmi_cd_priv= *priv) =20 /* =3D=3D=3D=3D=3D=3D=3D=3D WMI interface =3D=3D=3D=3D=3D=3D=3D=3D */ =20 +/** + * lwmi_cd_stub() - Stub the device by not providing any capability data + * @priv: lenovo-wmi-capdata driver data. + * @err: The occurred error. + * + * The Other Mode driver binds to both Capability Data 00 and 01. If eithe= r 00 + * or 01 fails to probe, the Other Mode device will fail to provide fw-att= r or + * hwmon/power_supply_ext devices for the other functional capdata device. + * + * Therefore, errors must be non-fatal in order not to break the assumptio= ns + * made by the device component framework, so that the Other Mode device c= an + * provide whatever is functional. + * + * After stubbing the device, a NULL list will be passed to the Other Mode + * device on bind. + * + * Return: 0 if the @err is suppressed, otherwise its propagated as is. + */ +static int lwmi_cd_stub(struct lwmi_cd_priv *priv, int err) +{ + /* + * No barrier is required in any possible code paths: + * - called from lwmi_cd_cache(): a proper barrier has been employed + * - called from lwmi_cd_fan_list_alloc_cache(): early setup does not + * require synchronization, and priv->initialized must be false + */ + bool initialized =3D READ_ONCE(priv->initialized); + + dev_warn(&priv->wdev->dev, "%s %s (%u items) due to error: %d\n", + initialized ? "clearing" : "stubbing", priv->info->name, + priv->list ? priv->list->count : 0, err); + + /* Simply print the warning message. */ + if (!priv->list) + return initialized ? err : 0; + + /* + * Stub the device on initialization errors. + * + * Note that if a transient error occurs during initialization, there is + * nothing we can do to re-enable the functionalities of the Other Mode + * driver even if a successful runtime notifier call making the relevant + * capdata emerge, as registering functionalities without the protection + * of the component framework is unsafe. Therefore, registering the + * notifier for a stubbed device is meaningless, and we don't need to + * distinguish transient and pernament errors during initialization. + * + * For runtime errors (see below), the registered functionalities + * (fw-attr) become temporarily unavailable due to the unavailablilty of + * the relevant capdata, and will recover after a successful runtime + * notifier call. + */ + if (!initialized) { + devm_kfree(&priv->wdev->dev, priv->list); + priv->list =3D NULL; + + return 0; + } + + /* + * Runtime errors are transient. Simply clear all cached data and + * propagate the error. + * + * Since a valid attribute id is never 0 (the firmware also untilize the + * fact to stub some capabilities according to platform metadata), + * clearing the cached data effectively makes all attributes temporarily + * unavailable until the next notifier call. + */ + + lockdep_assert_held(&priv->list->list_mutex); + + switch (priv->info->type) { + case LENOVO_CAPABILITY_DATA_01: + memset(priv->list->cd01, 0, + flex_array_size(priv->list, cd01, priv->list->count)); + break; + default: + unreachable(); + } + + return err; +} + /** * __lwmi_cd_cache() - Cache all WMI data block information locklessly * @priv: lenovo-wmi-capdata driver data. @@ -633,7 +719,7 @@ static int __lwmi_cd_cache(struct lwmi_cd_priv *priv) if (ret =3D=3D -ENODATA) /* The block is too short, probably stubbed. */ continue; if (ret) - return ret; + return lwmi_cd_stub(priv, ret); =20 /* Capdata 01 is an extension to capdata 00. */ struct capdata00 *capdata __free(kfree) =3D wbuf.data; @@ -694,7 +780,7 @@ static int lwmi_cd_fan_list_alloc_cache(struct lwmi_cd_= priv *priv) if (ret =3D=3D -ENODATA) /* The block is too short, probably stubbed. */ return 0; if (ret) - return ret; + return lwmi_cd_stub(priv, ret); /* Print the warning message. */ =20 struct cd_fan_block *block __free(kfree) =3D wbuf.data; =20 --=20 2.55.0 From nobody Sat Oct 24 13:21:58 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BC2553ED09; Tue, 13 Oct 2026 19:28:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919716; cv=pass; b=fXfvqi/dH4QTzOmqW3JgIyzNJHyGZ5S9eiuHHPvNJOvCnVJsnwE9UrzItQtmoa0pzXWUximeNzmOwJ1VKuvEZD9pFquq1Ob3eIKYx6FieriCDOWGvYreDTfMvuV3eVy0D82fIH75wgw9ke/iBSuEuTQYTE61RnQWBEnRFRg0qIQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919716; c=relaxed/simple; bh=Z/EgMuZRht3C+mlUe6TYGGFMUH962FkYo1a5s0rK470=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FcpKXUfZYhinpFduahck5NGDSX0iEIv3xKbAP1IFfuLYnVIU0hCpjiBVtysQAIFRC5X1RXCx+LvUb0oDQ/zc2DTPRXnMjPTWe2AAI2Los+qvsxGnJnHbiWpUnqvUPtYL2C2ZuMKHEVeebiJL0GkkdGbtmcL8JIp+SBBTq9xR0ko= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=BqjFAx9L; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="BqjFAx9L" ARC-Seal: i=1; a=rsa-sha256; t=1791919626; cv=none; d=zohomail.com; s=zohoarc; b=iodHWioOYP8z/I5gre9EIQTsRSdZ1je6YSj2DQfjKAv/6ZhYoT7XRk3SaA/l4sIsQ9Dl+fzA0npGbBm3AbZRWAREqH6mkj259F2xvUaj0kYCUyCiKljBlk6gOOA/9drfgqo9f7rZZAqALDS6oVzE+L1uQXnTqazhTtTgupT2YnE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791919626; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=J+2aVV1CS5xpzWZhcOeDvxRDMUoYFasAwmzY2nS0yWE=; b=J6WHVgAetwPSpWZjerqEDIrcZezFTm3qpzcnN2UDvlIT/CuxNi+T9EAfwfchAHIb1Qums90I+rPPdkBrekOsFRJU0Qfi0A9fLLau0Hfi1BVZvgHAuhBb1cVVLXfoQ+RO+sXqEbiw0eDPPMlivZ2utRzfhQ9Xoc4/dtYBGGfQlzY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791919626; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=J+2aVV1CS5xpzWZhcOeDvxRDMUoYFasAwmzY2nS0yWE=; b=BqjFAx9LtLoJI/zviD16FRdHYByZdaqH0tUNJPHI311T6xWhMOYb9B3fiRiqElA+ 0SrPf9iuJMMW5RU2W0FrkvS42qznynhos+JH710/h96FnvAEHAMeksx2W9Vt+J/2Pw8 IHp9hZZo2G/aMgw3b+PXC6YtjCmjhkPVv2huU/WFGOlE9vIYfa5aO5I8Ksv1WbmpOjf 5dmWVPcvLDWHIUHayvoJ8bOMzbzjSBUffYIAQjBWcM2ACHyid7yDlzKC9sZ9ncLk9wr x8wCsZ2JLSEkFICtilyc3+BB91PLweJ3JWWO0bAUH6E88N+D5rgL7DETpbXusHkQlvC 427QYBjNvg== Received: by smtp.zohomail.com with SMTPS id 1791919624598928.479475526039; Tue, 13 Oct 2026 12:27:04 -0700 (PDT) From: Rong Zhang Date: Wed, 14 Oct 2026 03:21:52 +0800 Subject: [PATCH v3 09/12] platform/x86: lenovo-wmi-capdata: Detect stubbed capdata device Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261014-lwmi-wmi-new-api-v3-9-e1032bed1c81@rong.moe> References: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> In-Reply-To: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> To: Mark Pearson , "Derek J. Clark" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Armin Wolf Cc: Charles , Navon John Lukose , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.17-dev-73bef X-ZohoMailClient: External Some devices may stub the capdata device's WMI query method because it doesn't support the relevant interfaces at all. For example, most ThinkBook devices doesn't support GameZone or Other Mode thermal tuning, so capdata 01 is useless and stubbed. Keeping the capability data list with empty data is meaningless and causes lenovo-wmi-other to call lwmi_cd*_get_data() to retrieve nonexistent capdata in vain. Therefore, stub the device and release (or skip allocating) needless resources, e.g., the capability data list and the debugfs directory. Tested-by: Navon John Lukose Reviewed-by: Derek J. Clark Signed-off-by: Rong Zhang Reported-by: Charles Reported-by: Navon John Lukose Reviewed-by: Mark Pearson Suggested-by: Derek J. Clark Suggested-by: Mark Pearson --- Changes in v2: - Replace the term "poison" with "stub" (thanks Ilpo J=C3=A4rvinen) --- drivers/platform/x86/lenovo/wmi-capdata.c | 33 +++++++++++++++++++++++++++= ++++ 1 file changed, 33 insertions(+) diff --git a/drivers/platform/x86/lenovo/wmi-capdata.c b/drivers/platform/x= 86/lenovo/wmi-capdata.c index 71ea31482987..39fc7a52cdfe 100644 --- a/drivers/platform/x86/lenovo/wmi-capdata.c +++ b/drivers/platform/x86/lenovo/wmi-capdata.c @@ -691,6 +691,7 @@ static int lwmi_cd_stub(struct lwmi_cd_priv *priv, int = err) */ static int __lwmi_cd_cache(struct lwmi_cd_priv *priv) { + bool got_data =3D false; size_t size; int idx; void *p; @@ -725,8 +726,31 @@ static int __lwmi_cd_cache(struct lwmi_cd_priv *priv) struct capdata00 *capdata __free(kfree) =3D wbuf.data; =20 memcpy(p, capdata, size); + + /* + * A valid attribute always has a non-zero id. IOW, a zero id + * implies a stubbed item (or the query method being stubbed). + * + * The stubbed item is still copied to the cache slot anyway, in + * case the firmware dynamically stubs the capdata item after + * switching Game Zone mode. In this manner, the previously + * exposed capdata can be void. + */ + if (capdata->id) + got_data =3D true; } =20 + /* + * Some devices may stub the query method because it doesn't support the + * relevant interfaces at all. For example, most ThinkBook devices + * doesn't support Game Zone or Other Mode thermal tuning, so capdata 01 + * is useless and stubbed. + * + * Stub the device and release needless resources. + */ + if (!got_data) + return lwmi_cd_stub(priv, -ENODATA); + return 0; } =20 @@ -767,6 +791,7 @@ static int lwmi_cd_cache(struct lwmi_cd_priv *priv) static int lwmi_cd_fan_list_alloc_cache(struct lwmi_cd_priv *priv) { struct wmi_buffer wbuf; + bool got_data =3D false; struct cd_list *list; int ret, idx; u32 count; @@ -808,13 +833,21 @@ static int lwmi_cd_fan_list_alloc_cache(struct lwmi_c= d_priv *priv) priv->list =3D list; =20 for (idx =3D 0; idx < count; idx++) { + if (!block->data[idx]) /* Ignore stub. */ + continue; + list->cd_fan[idx] =3D (struct capdata_fan) { .id =3D block->data[idx], .max_rpm =3D block->data[idx + count], .min_rpm =3D block->data[idx + (2 * count)], }; + + got_data =3D true; } =20 + if (!got_data) + return lwmi_cd_stub(priv, -ENODATA); + return 0; } =20 --=20 2.55.0 From nobody Sat Oct 24 13:21:58 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D450153D9E3; Tue, 13 Oct 2026 19:28:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919727; cv=pass; b=AfwmIugTlcsEjpI0G3/A2d4c2ztx34VHKYM2OL/1t9+ywccQyxHDG4nFuJapZ0K6Uejqo4CwuP1e+o0doebYWHq9QYDIm9K+xvUdS4ljdKKvglOj4Y3opWesAsVVTvFW1as8b5mwtvqtoI3vAVRp6fp+z70PV5ZSpVUGJS9qFe0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919727; c=relaxed/simple; bh=p8itfBwQQrpNtZMXufhAA2/3Td1V+kLJrMDgB/Lvfao=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CiIlwoDgugX6129c+j9WyDIlEAT8IMb5PZ+pTxIF9J9MX2tFSOIbFKRZBpvfnraBJ1wF2q+IkejDtwqveSrlXFEXeG8C+8XLCQW6ua/UY2AlftjlkLB91m7qIBrqpuAJXRTCWS1gMSyjHVfEs8Bnvi6SyEN59DAX93R5HQNYpTE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=O2hCtFgo; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="O2hCtFgo" ARC-Seal: i=1; a=rsa-sha256; t=1791919630; cv=none; d=zohomail.com; s=zohoarc; b=kzOWDmeLKJHq7hoxIpqhQgrN5lZIBmXERBYL/WqSmwiJrBk96qbyEPFjghRPOWTtT/Wkr2FcmHaMeSEqA+VZ6KJ4OsA5oEfx3eswRxDwz5Di4Y9Vys0J2YZ9CdcBIi9jMV0ASZaATI2iheG/VsltbK4w//DWuYl33uI7FlOwm/M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791919630; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=E9TyccREoFHGrLehmnX0JYXkP4kY0q7P0mosXdR41L0=; b=KzaBiIWu+iXzxBe7Sh7NjfXt2qD2edelIx7Zsm4eWSJRfIxnBisIgnXjygZxOcD6lpY01+FB9iRXJZ47E+n7YpocJEHjTAKTJUXDrVebCWArVz9bStLnde6/tDpNFozFqXcrK+5yJz+F2dax6kRTSebEJeuiHvdf2LRKA3RKWZs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791919630; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=E9TyccREoFHGrLehmnX0JYXkP4kY0q7P0mosXdR41L0=; b=O2hCtFgoXcVteZHW9HmvUA63fYJ9qN+q5Q63jg3YNhIoTtFj4GihDAZW/H5H2zkL 4xTgLdS3WzggGzcJv2H3qZjtAYVmt5o4xSAOeNYRJC1Q3jIecJTs5rRHPg1B56zymZl zIgs5DC6XR7wdntaULF3bhfzXVv4nWOR0UfOq8yKSqDkWyTsj/Nf5mrAXwTg6EqLN5S eLGVrZ5BZ6p/XluYM6sFaiKfQ2kFNGI6UI/4ryFkELwS/E5QzaP/XQHZuoYDXllgeyI WGKeI3+OGBQsiYiVkxZ9J9D9wsBamcbu+hwvs88VxHfWeHvhbPxBCYJj0iAWYzjj0Ng nVDbIhmXHA== Received: by smtp.zohomail.com with SMTPS id 1791919627138884.0484964145857; Tue, 13 Oct 2026 12:27:07 -0700 (PDT) From: Rong Zhang Date: Wed, 14 Oct 2026 03:21:53 +0800 Subject: [PATCH v3 10/12] platform/x86: lenovo-wmi-capdata: Do not match missing components Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261014-lwmi-wmi-new-api-v3-10-e1032bed1c81@rong.moe> References: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> In-Reply-To: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> To: Mark Pearson , "Derek J. Clark" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Armin Wolf Cc: Charles , Navon John Lukose , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.17-dev-73bef X-ZohoMailClient: External Some devices do not support LENOVO_CAPABILITY_DATA_01. They either do not have the corresponding WMI GUID, or do not implement the query method. In both cases, the WMI core does not create the corresponding WMI device, leaving the component master (i.e., lenovo-wmi-other) waits for the missing component forever. Identify missing components using the new wmidev_exists() interface, and skip adding them to the match list, so that all components in the list must present, fulfilling the binding requirement. Reported-by: Navon John Lukose Closes: https://msgid.link/20260928190901.1369497-1-navonjohnlukose@gmail.c= om Suggested-by: Mark Pearson Link: https://msgid.link/9789f452-d7eb-4f1e-8a13-7335332193a7@app.fastmail.= com Tested-by: Navon John Lukose Reviewed-by: Derek J. Clark Signed-off-by: Rong Zhang Reported-by: Charles Reviewed-by: Mark Pearson Suggested-by: Derek J. Clark --- Changes in v2: - New patch in the series to solve the report made by Navon --- drivers/platform/x86/lenovo/wmi-capdata.c | 36 +++++++++++++++++++++++++++= ---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/drivers/platform/x86/lenovo/wmi-capdata.c b/drivers/platform/x= 86/lenovo/wmi-capdata.c index 39fc7a52cdfe..c55b65e8750c 100644 --- a/drivers/platform/x86/lenovo/wmi-capdata.c +++ b/drivers/platform/x86/lenovo/wmi-capdata.c @@ -49,6 +49,7 @@ #include #include #include +#include #include =20 #include @@ -75,14 +76,19 @@ enum lwmi_cd_type { CD_TYPE_NONE =3D -1, }; =20 -#define LWMI_CD_TABLE_ITEM(_type) \ - [_type] =3D { \ - .name =3D #_type, \ - .type =3D _type, \ +static const struct wmi_device_id lwmi_cd_id_table[]; + +/* Save some .rodata space by reusing the GUID strings from the id table. = */ +#define LWMI_CD_TABLE_ITEM(_type) \ + [_type] =3D { \ + .name =3D #_type, \ + .guid_string =3D lwmi_cd_id_table[_type].guid_string, \ + .type =3D _type, \ } =20 static const struct lwmi_cd_info { const char *name; + const char *guid_string; enum lwmi_cd_type type; } lwmi_cd_table[] =3D { LWMI_CD_TABLE_ITEM(LENOVO_CAPABILITY_DATA_00), @@ -153,24 +159,46 @@ static int lwmi_cd_match(struct device *dev, void *ty= pe) * * Adds all component matches to the list stored in @matchptr for the @mas= ter * device. @matchptr must be initialized to NULL. + * + * Missing components are not added to the match list, or else the master = waits + * for them forever. For some components, their existence can be determine= d by + * querying other components, so they are handled as sub-components and th= us not + * matched here. For components with no existence declaration, wmidev_exis= ts() + * is used to determine their existence. + * + * If all components are missing, ERR_PTR(-ENXIO) is returned through @mat= chptr. */ void lwmi_cd_match_add_all(struct device *master, struct component_match *= *matchptr) { + bool matched =3D false; int i; =20 if (WARN_ON(*matchptr)) return; =20 for (i =3D 0; i < ARRAY_SIZE(lwmi_cd_table); i++) { + guid_t guid; + /* Skip sub-components. */ if (lwmi_cd_table[i].type =3D=3D LENOVO_FAN_TEST_DATA) continue; =20 + if (WARN_ON(guid_parse(lwmi_cd_table[i].guid_string, &guid))) + return; + + if (!wmidev_exists(&guid)) + continue; + component_match_add(master, matchptr, lwmi_cd_match, (void *)&lwmi_cd_table[i].type); if (IS_ERR(*matchptr)) return; + + matched =3D true; } + + if (!matched) + *matchptr =3D ERR_PTR(-ENXIO); } EXPORT_SYMBOL_NS_GPL(lwmi_cd_match_add_all, "LENOVO_WMI_CAPDATA"); =20 --=20 2.55.0 From nobody Sat Oct 24 13:21:58 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 557BA53F6A0; Tue, 13 Oct 2026 19:28:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919737; cv=pass; b=GXu/vVlnqdk4+1w3xjGrOuKqsTQTM9DJEdpTLjxITMEbhBEjYv2pyvwId+9FWutINViJ/w+56H6wDK0DYaAI2uyIc4w4aoAtSN88QBHugLli3+3likKpmPcuctcnBjkvvtWn9WMukxwmai6738s9ubLYNP5fJa29KslymtT89oA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919737; c=relaxed/simple; bh=uHfnDD+jPNh8KieapDA9xzkwLCXguNL96+a1PNWWyoc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Fc7DWcQ5yvKm3jIw+pBiHSu7oMEMQEt+Y01qlne5qnHZeseF4BSEgOZY/FL44dvQZpdKIdlvmTgDGtgszehY5Cl39IAsDPOhH9vKs35/64u1+ptBITfTl2OF4Gww/t3i+p48DD0GCnzasjoboOcQw5DWjI1ikGJ9PzXOJJe0SeI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=K58gh8hP; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="K58gh8hP" ARC-Seal: i=1; a=rsa-sha256; t=1791919632; cv=none; d=zohomail.com; s=zohoarc; b=AbMDoCTsVnGLvqWrXMgH6leEiY6Di4vUyfyUgare/bBzbVEnv+A28+vqCPWacGGOCALCooYza1r4QWBa/Sz+OcgoJOmc25znx8AuG4sqUjfc2dQoYb9V5nOaDxZVoVqKdfyBaDA8s4o0P7CkOLvJEmPNIICXXZxbgKnHYGis+HM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791919632; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=r7rA5rpFBvVY1ow6UQfRPytRSFWWYCs7Ekz7UsHWvRw=; b=af/5z+P8eF7V5tidMJP0EKofOk2AHNPBZ7uAriQKnXGKsQ2/z+0cUxxWJ2is+tCrIbdwXU710KYRZRmAgb0B+JPD3D4LFa6h6iiK8gsh5k7Zmx/8tFPVUEUfFfZ/mWowBDdhWzp7xGyD3PCUO1OUexvBa4yXHBnNQCQsM5Q1LZk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791919632; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=r7rA5rpFBvVY1ow6UQfRPytRSFWWYCs7Ekz7UsHWvRw=; b=K58gh8hPBGAU+C1eeDVXTvQO/+B0/dQF9jMKzXbDDj8I0V+9EWPDPte2L3RiA/Jb CTzoC8dT8u/w5cqUk5WYaUYp6JiVg6Po9u2kos89sSpwUZwjQh1won4nujQ0qUaZRh3 dH1LtTLvhf6cuITnHyF5dZIuQOD9/J8DPlP/xt7Y7s8zIC6VKnSprxKWAX/C+7jeEZN 8EwDsdICkv8wyyjPTv46aiF/G8BOJqZGXld/lIEUbhjkfBf1FjMeOQYzwEqCtO6gJhJ NBvU8qGP/uKpf8fljtCq4D8YkGzF4Pr58MEvGJj2sMRtGYUIAKB4i95+zRWEQBgCONK aHVQXnYMWg== Received: by smtp.zohomail.com with SMTPS id 1791919629797487.774529568703; Tue, 13 Oct 2026 12:27:09 -0700 (PDT) From: Rong Zhang Date: Wed, 14 Oct 2026 03:21:54 +0800 Subject: [PATCH v3 11/12] platform/x86: lenovo-wmi-helpers: Adopt new WMI API Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261014-lwmi-wmi-new-api-v3-11-e1032bed1c81@rong.moe> References: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> In-Reply-To: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> To: Mark Pearson , "Derek J. Clark" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Armin Wolf Cc: Charles , Navon John Lukose , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.17-dev-73bef X-ZohoMailClient: External The new WMI API supports multiple ACPI types by converting them into a unified buffer that satisfies alignment and size requirements. Adopt it to make our life easier. Note that the Windows WMI-ACPI driver converts all ACPI objects into a common buffer format, so adopting the new API intentionally accepts more ACPI types as a followup of commit 465dc9da8ff6 ("platform/x86: lenovo-wmi-helpers: Convert returned buffer into u32"). Suggested-by: Armin Wolf Link: https://lore.kernel.org/r/f1787927-b655-4321-b9d9-bc12353c72db@gmx.de/ Reviewed-by: Armin Wolf Tested-by: Navon John Lukose Reviewed-by: Derek J. Clark Signed-off-by: Rong Zhang Reported-by: Charles Reported-by: Navon John Lukose Reviewed-by: Mark Pearson Suggested-by: Derek J. Clark Suggested-by: Mark Pearson --- drivers/platform/x86/lenovo/wmi-helpers.c | 61 ++++++++++++---------------= ---- 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/drivers/platform/x86/lenovo/wmi-helpers.c b/drivers/platform/x= 86/lenovo/wmi-helpers.c index 8f5766c391eb..687caa226263 100644 --- a/drivers/platform/x86/lenovo/wmi-helpers.c +++ b/drivers/platform/x86/lenovo/wmi-helpers.c @@ -24,9 +24,10 @@ #include #include #include -#include #include =20 +#include + #include "wmi-helpers.h" =20 /* Thermal mode notifier chain. */ @@ -42,49 +43,33 @@ static BLOCKING_NOTIFIER_HEAD(tm_chain_head); * @size: Length of the buffer. * @retval: Pointer for the return value to be assigned. * - * Calls wmidev_evaluate_method for Lenovo WMI devices that return an ACPI - * integer. Validates the return value type and assigns the value to the - * retval pointer. + * Calls the specified WMI method for Lenovo WMI devices that return a WMI + * integer. Validates the return value and assigns it to @retval when it's= not + * NULL, otherwise the return value is not validated. * * Return: 0 on success, or an error code. */ int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method= _id, unsigned char *buf, size_t size, u32 *retval) { - struct acpi_buffer output =3D { ACPI_ALLOCATE_BUFFER, NULL }; - struct acpi_buffer input =3D { size, buf }; - acpi_status status; - - status =3D wmidev_evaluate_method(wdev, instance, method_id, &input, - &output); - if (ACPI_FAILURE(status)) - return -EIO; - - union acpi_object *ret_obj __free(kfree) =3D output.pointer; - - if (retval) { - if (!ret_obj) - return -ENODATA; - - switch (ret_obj->type) { - /* - * The ACPI method may simply return a buffer when a u32 - * is expected. This is valid on Windows as its WMI-ACPI - * driver converts everything to a common buffer. - */ - case ACPI_TYPE_BUFFER: - if (ret_obj->buffer.length < sizeof(u32)) - return -ENXIO; - - *retval =3D get_unaligned_le32(ret_obj->buffer.pointer); - return 0; - case ACPI_TYPE_INTEGER: - *retval =3D (u32)ret_obj->integer.value; - return 0; - default: - return -ENXIO; - } - } + struct wmi_buffer input =3D { + .length =3D size, + .data =3D buf, + }; + struct wmi_buffer output; + int ret; + + if (!retval) + return wmidev_invoke_procedure(wdev, instance, method_id, &input); + + ret =3D wmidev_invoke_method(wdev, instance, method_id, &input, + &output, sizeof(__le32)); + if (ret) + return ret; + + __le32 *valp __free(kfree) =3D output.data; + + *retval =3D le32_to_cpu(*valp); =20 return 0; }; --=20 2.55.0 From nobody Sat Oct 24 13:21:58 2026 Received: from sender4-pp-f112.zoho.com (sender4-pp-f112.zoho.com [136.143.188.112]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70C2D51DB07; Tue, 13 Oct 2026 19:29:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.112 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919746; cv=pass; b=ENIraCtEKh5uQuEft9O3MTVC7k8D5JtzgepstjMRM22kq5K9uajvd6R3fBS4IemLfLqgv+4/U/SQeKFDldy9ycFmwbkOfJ8K/XeYjCBWkT+43OxiVFyRpzI5OSH64McJGD9m5q+mUKMJjnd2XBJJZhdSH2LhBRHfH9bLH73Dphg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791919746; c=relaxed/simple; bh=A0rRh/QeYtmdUgAhUuqkGkSk2dzuMp4cLDqwyVGPelM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q5fTrl63UFES/NHB1YB320iz7WEJjdXTS+FGyFk80pw/iMrQHQ6J6whL4jH320x5nbJEOq8Q4fwmc5W6KaIwSb1TzZdHBV+pvBs5WXko2TKPgN6VlowhzxmsX7aGfGX5k8oP6nq1u1GtnmqOhkEEwAYh3NHWMQeWuNCurFcUnjQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=YE/wBb2i; arc=pass smtp.client-ip=136.143.188.112 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="YE/wBb2i" ARC-Seal: i=1; a=rsa-sha256; t=1791919634; cv=none; d=zohomail.com; s=zohoarc; b=K2QcfHuMcfp50TbvsAnwV7RLWaj8VwGTrxLhcsOOAh2i5ylhAPpc6pSyWRcThlktEjKTQbM1s4KxAGGEniC/KmtFIKA/SVX+o4PnTxpvRwktV3l9GqA3Oj3Oop6ee4m1rsZBXX/s47hTTBohCb6QijM7WSDjNAMK/Y5z97klHlc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1791919634; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=Cu0Ku63ibtiD8dSCNBVjWGKMrJyfLPEWtMUvr63+F74=; b=Mb4xZHNfi+zc+Lczo67y1a8HCqI4fFIm/c0+5A85x5635mLchqw8V+ox2x6dlCqoaSIPUhnJAaKS8doHvN1FCphPqNeFIQrvBMLWXH7v4mKcDs/r8bVut+dmc2TG/ISjZa1Iz5+G5KRetP3RmmGTSNoDX7US8lZWpVR6wU/bYIY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1791919634; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=Cu0Ku63ibtiD8dSCNBVjWGKMrJyfLPEWtMUvr63+F74=; b=YE/wBb2iImwU+TmPa2PLVaZ6jBDUbIL/3zr84EYjxleGb+ug9gY2MEHDtdTpSEZS sBwTRLJ6lLChrvxQUHq/QYWUjMtRr/PV0deZV1wZxiqKU+LKOoiMduEoTanVVa/Mxh2 NLrLmjz0cAn2qUwH4zMRrxCsGku7sjOcP1hHkn2nUlVwibqg8suLIiHguAL4CjkSN/m 19fIPbE2CRWukUrL0DPuVk2okaQZC3EZ6xEdC0i3JmQJ5nnETGQ8xOB8xXLK50JotoW /snjuEHJab60/8e1cZfvip27F8hmp1mEfzAuz7/1/TTWp0fG1u+LKt/NDlJRz3lRbVe PRv8UVEPhw== Received: by smtp.zohomail.com with SMTPS id 1791919632384990.8018042401861; Tue, 13 Oct 2026 12:27:12 -0700 (PDT) From: Rong Zhang Date: Wed, 14 Oct 2026 03:21:55 +0800 Subject: [PATCH v3 12/12] MAINTAINERS: Add myself as a LENOVO drivers co-maintainer Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20261014-lwmi-wmi-new-api-v3-12-e1032bed1c81@rong.moe> References: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> In-Reply-To: <20261014-lwmi-wmi-new-api-v3-0-e1032bed1c81@rong.moe> To: Mark Pearson , "Derek J. Clark" , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Armin Wolf Cc: Charles , Navon John Lukose , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.17-dev-73bef X-ZohoMailClient: External I regularly review patches and resolve bug reports posted on the pdx86 mailing list or the kernel Bugzilla to improve LENOVO drivers (including lenovo-wmi-* and ideapad-laptop) along with Derek J. Clark and Mark Pearson. I've been submitting patches to add new features and fix issues on my devices, too. Add myself as a LENOVO drivers co-maintainer to reflect this. Suggested-by: Derek J. Clark Link: https://msgid.link/782FE636-A06A-4E12-9563-786374805947@gmail.com Reviewed-by: Mark Pearson Reviewed-by: Derek J. Clark Signed-off-by: Rong Zhang Reported-by: Charles Reported-by: Navon John Lukose Suggested-by: Mark Pearson --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index f53047aa8d3c..fa576b4b5919 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14808,6 +14808,7 @@ F: drivers/usb/misc/legousbtower.c LENOVO drivers M: Mark Pearson M: Derek J. Clark +M: Rong Zhang L: platform-driver-x86@vger.kernel.org S: Maintained F: Documentation/wmi/devices/lenovo-wmi-gamezone.rst --=20 2.55.0