From nobody Fri Apr 3 01:28:23 2026 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E45C24A054 for ; Sun, 15 Feb 2026 06:13:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771136026; cv=none; b=Z9PNjihmRVa721+axsD1NfY5yhk8ucDNWmoRA5lJJK6J/bUFXCfG06+LmhyXZvx2yt/NcgRgXKeixKCi4UnMysGtr4kZdSP56Ym1pJ/NkeurUVZa3I1O+brFPYQrwr1hiayNWiI0tyKOKyVBXNXdqIzh4OqluI5XtsPYQof/xX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771136026; c=relaxed/simple; bh=0WY/6++ifxZzESmD3bALeKnLCRCtyf7YwTde+fN6yx4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JbQOMlnekir1cHzAeyjcyYBlG22cIHvkppSjg8AmGxsMvgn5BJWn4qZmwGxM6tzfUoGn2gB47A15xzozlHh5kOEmHrD2SEZtA5OTE7lCNwWRG7bWjBebiptIvU756CNKUfbK0XDgB05cOVZVA5Q6V5Fm7/hGzVWNl0EPP/nfnZY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KRODG7JN; arc=none smtp.client-ip=74.125.82.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KRODG7JN" Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-2b82c605dbdso4746880eec.0 for ; Sat, 14 Feb 2026 22:13:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771136024; x=1771740824; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D9xOxtR3CWKKMh61qfUolY9qoF61BVM7C9Huh+ukUgc=; b=KRODG7JNubpNsOt66msFei1r+88YcKjWND8AW3rPpdBXh/dXjznsSMVbqJL7F6PSxN Sz7gyRbPaGH5Lz9PhzlcRV+xu5rdkH6qNtLGPt+XcS0sbbzNxNyhWmHAgGjG7dEjboh/ nRLWMrqSV6NdPWmblUYrEup0CfUfUW4yjJUR9aeUvCE4OvoRXeMcdDw7VocKM/Syk8fL iFaZbWWsL0MbY7frdUydmHlONCCaj9dHlvOmYUoGL/wmTfRGqjRpshXWFfXgD2KLNIlS 5E/W2jPwcCFFABrujMuCGXrcRBbqx+g2gJBN3FTEwS85lpr1T0IqcE8cG+sck3pvyBlT NKMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771136024; x=1771740824; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=D9xOxtR3CWKKMh61qfUolY9qoF61BVM7C9Huh+ukUgc=; b=JpKvKF7Hp0hZr08WtAfxziDK9kt0hDcuppg1LQY+DomhVQwLZfJiwKOL1cJXQ3QNqS YUL92YZf0L5MyK7hWh0egZvURZSMTy+wtl41sII8aZbPaAoKkFPxEqnqUVGcrCDWx0/a vFGJ0CGqkA8fD7UxYTD1kzRyJ4Msz2ZcXi/KJ+667t+n3lFuRJOYvH3si+rQPt688pUV JSQRFGNFEP1wWL+mWGHyJB1cM0e8ZAjZgYAr4zm4YPB8bIxVg7G2QNU82FFr7kihaVgb sGG9PC26AV90XP6t4dhE85sgbDIBNDLakc+VX7TJnxEXjienpXdl/OQ6CGDEnR1kKPQu lHWw== X-Forwarded-Encrypted: i=1; AJvYcCXH0s8WHP9pDuLNaFeFO8qB5OOkl6rxWRQZLwpxltSFakm3AJPhxylrEDPP4CzXBY1TiaSBxjkPzOZsa1g=@vger.kernel.org X-Gm-Message-State: AOJu0YwLJjQnkkGb0h0ilXQ7HUfqJUrvnOylwjjRy95kY3GcwVBFM8vg DbNY3mou8Hw0J1U8u5XD1utoeAU6hsCGKB6M3M5dKCH6x9n9lWIBBMhz X-Gm-Gg: AZuq6aLZnVrNXNgNa3KKLk14HQWnKSiYmRokHjtR7MpTjRz4xwOEAjdSHS8CID4VssH /icE0LO6RA9hxqeRNCPzza52dRaCAiE8VnSP3kcvBqPbzTc1siw92Im0WwSJ7rLPLsDc1Xl9A1X d2gsRXE4bh8TKk9AZNiuqT691+d8QVp68RSxvYqy1otRu0PGlOvNSCcFqG0dfWoKb/Ei7fyCqqE rkwTsIqx1Snaln6XCOnPBaYryrmYdyu38SKyJ9oQHNWj74mjP5i+a1yxwIz4Kv0Hu6yJsx3uj0B 2CtIaTIQm49nuiXyP1NgakC819qVdGjUv5Amap4jD+lHoFCUpKUxSuSrTvrxhwGlfB81HIQvLJk OnlDBF1Z0gfZIOGs0Ioo35Z/lnP2Zq+VumxAoUWE7D9iUHVLYqL1krs/12Rojt1KdHpCjWV0S+w W00Tl9eBusQC9b4syxnrCtGAppvOuYGKLTM90ZFd528mWKEzWd4e+MGpEUHpfDvwF+8YndpI/bH mg= X-Received: by 2002:a05:7300:fe0a:b0:2ba:72b1:40c7 with SMTP id 5a478bee46e88-2babc3b6ae0mr2900521eec.4.1771136024221; Sat, 14 Feb 2026 22:13:44 -0800 (PST) Received: from lappy (108-228-232-20.lightspeed.sndgca.sbcglobal.net. [108.228.232.20]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2bacb577bcasm4759245eec.12.2026.02.14.22.13.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Feb 2026 22:13:43 -0800 (PST) From: "Derek J. Clark" To: =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Hans de Goede Cc: Mark Pearson , Armin Wolf , Jonathan Corbet , Rong Zhang , Kurt Borja , "Derek J . Clark" , platform-driver-x86@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/6] platform/x86: lenovo-wmi-other: Limit adding attributes to supported devices Date: Sun, 15 Feb 2026 06:12:55 +0000 Message-ID: <20260215061339.2842486-3-derekjohn.clark@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260215061339.2842486-1-derekjohn.clark@gmail.com> References: <20260215061339.2842486-1-derekjohn.clark@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds lwmi_is_attr_01_supported, and only creates the attribute subfolder if the attribute is supported by the hardware. Due to some poorly implemented BIOS, this is a multi-step sequence of events. This is because: - Some BIOS support getting the capability data from custom mode (0xff), while others only support it in no-mode (0x00). - Similarly, some BIOS support get/set for the current value from custom mode (0xff), while others only support it in no-mode (0x00). - Some BIOS report capability data for a method that is not fully implemented. - Some BIOS have methods fully implemented, but no complimentary capability data. To ensure we only expose fully implemented methods with corresponding capability data, we check each outcome before reporting that an attribute can be supported. Checking for lwmi_is_attr_01_supported during remove is not done to ensure that we don't attempt to call cd01 or send WMI events if one of the interfaces being removed was the cause of the driver unloading. While adding members to tunable_attr_01, remove unused capdata pointer and limit size of all ID's to the appropriate size. Reported-by: Kurt Borja Closes: https://lore.kernel.org/platform-driver-x86/DG60P3SHXR8H.3NSEHMZ6J7= XRC@gmail.com/ Signed-off-by: Derek J. Clark --- drivers/platform/x86/lenovo/wmi-other.c | 117 +++++++++++++++++++++--- 1 file changed, 102 insertions(+), 15 deletions(-) diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86= /lenovo/wmi-other.c index 95886df39c8d2..f3f12303e3798 100644 --- a/drivers/platform/x86/lenovo/wmi-other.c +++ b/drivers/platform/x86/lenovo/wmi-other.c @@ -545,11 +545,12 @@ static void lwmi_om_fan_info_collect_cd_fan(struct de= vice *dev, struct cd_list * /* =3D=3D=3D=3D=3D=3D=3D=3D fw_attributes (component: lenovo-wmi-capdata 0= 1) =3D=3D=3D=3D=3D=3D=3D=3D */ =20 struct tunable_attr_01 { - struct capdata01 *capdata; struct device *dev; - u32 feature_id; - u32 device_id; - u32 type_id; + u8 feature_id; + u8 device_id; + u8 type_id; + u8 cd_mode_id; /* mode arg for searching capdata */ + u8 cv_mode_id; /* mode arg for set/get current_value */ }; =20 static struct tunable_attr_01 ppt_pl1_spl =3D { @@ -716,7 +717,7 @@ static ssize_t attr_capdata01_show(struct kobject *kobj, int value, ret; =20 attribute_id =3D LWMI_ATTR_ID(tunable_attr->device_id, tunable_attr->feat= ure_id, - LWMI_GZ_THERMAL_MODE_CUSTOM, tunable_attr->type_id); + tunable_attr->cd_mode_id, tunable_attr->type_id); =20 ret =3D lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata); if (ret) @@ -782,7 +783,7 @@ static ssize_t attr_current_value_store(struct kobject = *kobj, return -EBUSY; =20 args.arg0 =3D LWMI_ATTR_ID(tunable_attr->device_id, tunable_attr->feature= _id, - mode, tunable_attr->type_id); + tunable_attr->cd_mode_id, tunable_attr->type_id); =20 ret =3D lwmi_cd01_get_data(priv->cd01_list, args.arg0, &capdata); if (ret) @@ -795,6 +796,8 @@ static ssize_t attr_current_value_store(struct kobject = *kobj, if (value < capdata.min_value || value > capdata.max_value) return -EINVAL; =20 + args.arg0 =3D LWMI_ATTR_ID(tunable_attr->device_id, tunable_attr->feature= _id, + tunable_attr->cv_mode_id, tunable_attr->type_id); args.arg1 =3D value; =20 ret =3D lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_SET, @@ -828,13 +831,16 @@ static ssize_t attr_current_value_show(struct kobject= *kobj, struct lwmi_om_priv *priv =3D dev_get_drvdata(tunable_attr->dev); struct wmi_method_args_32 args; enum thermal_mode mode; - int retval; - int ret; + int retval, ret; =20 ret =3D lwmi_om_notifier_call(&mode); if (ret) return ret; =20 + /* If "no-mode" is the supported mode, ensure we never send current mode = */ + if (tunable_attr->cv_mode_id =3D=3D LWMI_GZ_THERMAL_MODE_NONE) + mode =3D tunable_attr->cv_mode_id; + args.arg0 =3D LWMI_ATTR_ID(tunable_attr->device_id, tunable_attr->feature= _id, mode, tunable_attr->type_id); =20 @@ -847,6 +853,85 @@ static ssize_t attr_current_value_show(struct kobject = *kobj, return sysfs_emit(buf, "%d\n", retval); } =20 +/** + * lwmi_attr_01_is_supported() - Determine if the given attribute is suppo= rted. + * @tunable_attr: The attribute to verify. + * + * First check if the attribute has a corresponding capdata01 table in the= cd01 + * module under the "custom" mode (0xff). If that is not present then chec= k if + * there is a corresponding "no-mode" (0x00) entry. If either of those pas= ses, + * check capdata->supported for values > 0. If capdata is available, attem= pt to + * determine the set/get mode for the current value property using a simil= ar + * pattern. If the value returned by either custom or no-mode is 0, or we = get + * an error, we assume that mode is not supported. If any of the above che= cks + * fail then the attribute is not fully supported. + * + * The probed cd_mode_id/cv_mode_id are stored on the tunable_attr for lat= er + * reference. + * + * Return: Support level, or an error code. + */ +static int lwmi_attr_01_is_supported(struct tunable_attr_01 *tunable_attr) +{ + struct lwmi_om_priv *priv =3D dev_get_drvdata(tunable_attr->dev); + u8 mode =3D LWMI_GZ_THERMAL_MODE_CUSTOM; + struct wmi_method_args_32 args; + struct capdata01 capdata; + int retval, ret; + + /* Determine tunable_attr->cd_mode_id */ +no_mode_fallback_1: + args.arg0 =3D LWMI_ATTR_ID(tunable_attr->device_id, tunable_attr->feature= _id, + mode, tunable_attr->type_id); + + ret =3D lwmi_cd01_get_data(priv->cd01_list, args.arg0, &capdata); + if (ret && mode) { + dev_dbg(tunable_attr->dev, "Attribute id %x not supported\n", args.arg0); + mode =3D LWMI_GZ_THERMAL_MODE_NONE; + goto no_mode_fallback_1; + } + if (ret) + goto not_supported; + if (!capdata.supported) { + ret =3D -EOPNOTSUPP; + goto not_supported; + } + + tunable_attr->cd_mode_id =3D mode; + + /* Determine tunable_attr->cv_mode_id */ + mode =3D LWMI_GZ_THERMAL_MODE_CUSTOM; +no_mode_fallback_2: + args.arg0 =3D LWMI_ATTR_ID(tunable_attr->device_id, tunable_attr->feature= _id, + mode, tunable_attr->type_id); + + ret =3D lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_GET, + (unsigned char *)&args, sizeof(args), + &retval); + if ((ret && mode) || (!retval && mode)) { + dev_dbg(tunable_attr->dev, "Attribute id %x not supported\n", args.arg0); + mode =3D LWMI_GZ_THERMAL_MODE_NONE; + goto no_mode_fallback_2; + } + if (ret) + goto not_supported; + if (retval =3D=3D 0) { + ret =3D -EOPNOTSUPP; + goto not_supported; + } + + tunable_attr->cv_mode_id =3D mode; + dev_dbg(tunable_attr->dev, "cd_mode_id: %02x%02x%02x%02x, cv_mode_id: %#0= 8x attribute support level: %x\n", + tunable_attr->device_id, tunable_attr->feature_id, tunable_attr->cd_mode= _id, + tunable_attr->type_id, args.arg0, capdata.supported); + + return capdata.supported; + +not_supported: + dev_dbg(tunable_attr->dev, "Attribute id %x not supported\n", args.arg0); + return ret; +} + /* Lenovo WMI Other Mode Attribute macros */ #define __LWMI_ATTR_RO(_func, _name) \ { \ @@ -970,19 +1055,21 @@ static int lwmi_om_fw_attr_add(struct lwmi_om_priv *= priv) } =20 for (i =3D 0; i < ARRAY_SIZE(cd01_attr_groups) - 1; i++) { - err =3D sysfs_create_group(&priv->fw_attr_kset->kobj, - cd01_attr_groups[i].attr_group); - if (err) - goto err_remove_groups; - cd01_attr_groups[i].tunable_attr->dev =3D &priv->wdev->dev; + if (lwmi_attr_01_is_supported(cd01_attr_groups[i].tunable_attr) > 0) { + err =3D sysfs_create_group(&priv->fw_attr_kset->kobj, + cd01_attr_groups[i].attr_group); + if (err) + goto err_remove_groups; + } } return 0; =20 err_remove_groups: while (i--) - sysfs_remove_group(&priv->fw_attr_kset->kobj, - cd01_attr_groups[i].attr_group); + if (lwmi_attr_01_is_supported(cd01_attr_groups[i].tunable_attr) > 0) + sysfs_remove_group(&priv->fw_attr_kset->kobj, + cd01_attr_groups[i].attr_group); =20 kset_unregister(priv->fw_attr_kset); =20 --=20 2.52.0