* [PATCH v11 01/15] platform/x86: lenovo-wmi-helpers: Fix memory leak in lwmi_dev_evaluate_int()
[not found] <20260507180507.912966-1-derekjohn.clark@gmail.com>
@ 2026-05-07 18:04 ` Derek J. Clark
2026-05-07 18:04 ` [PATCH v11 02/15] platform/x86: lenovo-wmi-other: Balance IDA id allocation and free Derek J. Clark
` (7 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Derek J. Clark @ 2026-05-07 18:04 UTC (permalink / raw)
To: Ilpo Järvinen, Hans de Goede
Cc: Mark Pearson, Armin Wolf, Jonathan Corbet, Rong Zhang, Kurt Borja,
Derek J . Clark, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, linux-kernel, stable
From: Rong Zhang <i@rong.moe>
lwmi_dev_evaluate_int() leaks output.pointer when retval == NULL (found
by sashiko.dev [1]).
Fix it by moving `ret_obj = output.pointer' outside of the `if (retval)'
block so that it is always freed by the __free cleanup callback.
No functional change intended.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Fixes: e521d16e76cd ("platform/x86: Add lenovo-wmi-helpers")
Cc: stable@vger.kernel.org
Link: https://sashiko.dev/#/patchset/20260331181208.421552-1-derekjohn.clark%40gmail.com [1]
Signed-off-by: Rong Zhang <i@rong.moe>
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/platform/x86/lenovo/wmi-helpers.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/platform/x86/lenovo/wmi-helpers.c b/drivers/platform/x86/lenovo/wmi-helpers.c
index 7379defac500..018d7642e2bd 100644
--- a/drivers/platform/x86/lenovo/wmi-helpers.c
+++ b/drivers/platform/x86/lenovo/wmi-helpers.c
@@ -46,7 +46,6 @@ 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 = { ACPI_ALLOCATE_BUFFER, NULL };
- union acpi_object *ret_obj __free(kfree) = NULL;
struct acpi_buffer input = { size, buf };
acpi_status status;
@@ -55,8 +54,9 @@ int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method_id,
if (ACPI_FAILURE(status))
return -EIO;
+ union acpi_object *ret_obj __free(kfree) = output.pointer;
+
if (retval) {
- ret_obj = output.pointer;
if (!ret_obj)
return -ENODATA;
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v11 02/15] platform/x86: lenovo-wmi-other: Balance IDA id allocation and free
[not found] <20260507180507.912966-1-derekjohn.clark@gmail.com>
2026-05-07 18:04 ` [PATCH v11 01/15] platform/x86: lenovo-wmi-helpers: Fix memory leak in lwmi_dev_evaluate_int() Derek J. Clark
@ 2026-05-07 18:04 ` Derek J. Clark
2026-05-07 18:04 ` [PATCH v11 03/15] platform/x86: lenovo-wmi-other: Balance component bind and unbind Derek J. Clark
` (6 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Derek J. Clark @ 2026-05-07 18:04 UTC (permalink / raw)
To: Ilpo Järvinen, Hans de Goede
Cc: Mark Pearson, Armin Wolf, Jonathan Corbet, Rong Zhang, Kurt Borja,
Derek J . Clark, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, linux-kernel, stable
From: Rong Zhang <i@rong.moe>
Currently, the IDA id is only freed on wmi-other device removal or
failure to create firmware-attributes device, kset, or attributes. It
leaks IDA ids if the wmi-other device is bound multiple times, as the
unbind callback never frees the previously allocated IDA id.
Additionally, if the wmi-other device has failed to create a
firmware-attributes device before it gets removed, the wmi-device
removal callback double frees the same IDA id.
These bugs were found by sashiko.dev [1].
Fix them by moving ida_free() into lwmi_om_fw_attr_remove() so it is
balanced with ida_alloc() in lwmi_om_fw_attr_add(). With them fixed,
properly set and utilize the validity of priv->ida_id to balance
firmware-attributes registration and removal, without relying on
propagating the registration error to the component framework, which is
more reliable and aligns with the hwmon device registration and removal
sequences.
No functional change intended.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Fixes: edc4b183b794 ("platform/x86: Add Lenovo Other Mode WMI Driver")
Cc: stable@vger.kernel.org
Link: https://sashiko.dev/#/patchset/20260331181208.421552-1-derekjohn.clark%40gmail.com [1]
Signed-off-by: Rong Zhang <i@rong.moe>
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
v9:
- Invert err logic for when allocating IDA fails.
- Rename ida_alloc err goto from 'err' to 'err_no_ida' to disambiguate
from 'int err'.
---
drivers/platform/x86/lenovo/wmi-other.c | 36 ++++++++++++++-----------
1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
index 6040f45aa2b0..be3309d74e03 100644
--- a/drivers/platform/x86/lenovo/wmi-other.c
+++ b/drivers/platform/x86/lenovo/wmi-other.c
@@ -957,17 +957,17 @@ static struct capdata01_attr_group cd01_attr_groups[] = {
/**
* lwmi_om_fw_attr_add() - Register all firmware_attributes_class members
* @priv: The Other Mode driver data.
- *
- * Return: Either 0, or an error code.
*/
-static int lwmi_om_fw_attr_add(struct lwmi_om_priv *priv)
+static void lwmi_om_fw_attr_add(struct lwmi_om_priv *priv)
{
unsigned int i;
int err;
- priv->ida_id = ida_alloc(&lwmi_om_ida, GFP_KERNEL);
- if (priv->ida_id < 0)
- return priv->ida_id;
+ err = ida_alloc(&lwmi_om_ida, GFP_KERNEL);
+ if (err < 0)
+ goto err_no_ida;
+
+ priv->ida_id = err;
priv->fw_attr_dev = device_create(&firmware_attributes_class, NULL,
MKDEV(0, 0), NULL, "%s-%u",
@@ -993,7 +993,7 @@ static int lwmi_om_fw_attr_add(struct lwmi_om_priv *priv)
cd01_attr_groups[i].tunable_attr->dev = &priv->wdev->dev;
}
- return 0;
+ return;
err_remove_groups:
while (i--)
@@ -1007,7 +1007,12 @@ static int lwmi_om_fw_attr_add(struct lwmi_om_priv *priv)
err_free_ida:
ida_free(&lwmi_om_ida, priv->ida_id);
- return err;
+
+err_no_ida:
+ priv->ida_id = -EIDRM;
+
+ dev_warn(&priv->wdev->dev,
+ "failed to register firmware-attributes device: %d\n", err);
}
/**
@@ -1016,12 +1021,17 @@ static int lwmi_om_fw_attr_add(struct lwmi_om_priv *priv)
*/
static void lwmi_om_fw_attr_remove(struct lwmi_om_priv *priv)
{
+ if (priv->ida_id < 0)
+ return;
+
for (unsigned int i = 0; i < ARRAY_SIZE(cd01_attr_groups) - 1; i++)
sysfs_remove_group(&priv->fw_attr_kset->kobj,
cd01_attr_groups[i].attr_group);
kset_unregister(priv->fw_attr_kset);
device_unregister(priv->fw_attr_dev);
+ ida_free(&lwmi_om_ida, priv->ida_id);
+ priv->ida_id = -EIDRM;
}
/* ======== Self (master: lenovo-wmi-other) ======== */
@@ -1063,7 +1073,9 @@ static int lwmi_om_master_bind(struct device *dev)
lwmi_om_fan_info_collect_cd00(priv);
- return lwmi_om_fw_attr_add(priv);
+ lwmi_om_fw_attr_add(priv);
+
+ return 0;
}
/**
@@ -1115,13 +1127,7 @@ static int lwmi_other_probe(struct wmi_device *wdev, const void *context)
static void lwmi_other_remove(struct wmi_device *wdev)
{
- struct lwmi_om_priv *priv = dev_get_drvdata(&wdev->dev);
-
component_master_del(&wdev->dev, &lwmi_om_master_ops);
-
- /* No IDA to free if the driver is never bound to its components. */
- if (priv->ida_id >= 0)
- ida_free(&lwmi_om_ida, priv->ida_id);
}
static const struct wmi_device_id lwmi_other_id_table[] = {
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v11 03/15] platform/x86: lenovo-wmi-other: Balance component bind and unbind
[not found] <20260507180507.912966-1-derekjohn.clark@gmail.com>
2026-05-07 18:04 ` [PATCH v11 01/15] platform/x86: lenovo-wmi-helpers: Fix memory leak in lwmi_dev_evaluate_int() Derek J. Clark
2026-05-07 18:04 ` [PATCH v11 02/15] platform/x86: lenovo-wmi-other: Balance IDA id allocation and free Derek J. Clark
@ 2026-05-07 18:04 ` Derek J. Clark
2026-05-07 18:04 ` [PATCH v11 04/15] platform/x86: lenovo-wmi-other: Zero initialize WMI arguments Derek J. Clark
` (5 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Derek J. Clark @ 2026-05-07 18:04 UTC (permalink / raw)
To: Ilpo Järvinen, Hans de Goede
Cc: Mark Pearson, Armin Wolf, Jonathan Corbet, Rong Zhang, Kurt Borja,
Derek J . Clark, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, linux-kernel, stable
From: Rong Zhang <i@rong.moe>
When lwmi_om_master_bind() fails, the master device's components are
left bound, with the aggregate device destroyed due to the failure
(found by sashiko.dev [1]).
Balance calls to component_bind_all() and component_unbind_all() when an
error is propagated to the component framework.
No functional change intended.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Fixes: edc4b183b794 ("platform/x86: Add Lenovo Other Mode WMI Driver")
Cc: stable@vger.kernel.org
Link: https://sashiko.dev/#/patchset/20260331181208.421552-1-derekjohn.clark%40gmail.com [1]
Signed-off-by: Rong Zhang <i@rong.moe>
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/platform/x86/lenovo/wmi-other.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
index be3309d74e03..a6be3463341c 100644
--- a/drivers/platform/x86/lenovo/wmi-other.c
+++ b/drivers/platform/x86/lenovo/wmi-other.c
@@ -1068,8 +1068,11 @@ static int lwmi_om_master_bind(struct device *dev)
priv->cd00_list = binder.cd00_list;
priv->cd01_list = binder.cd01_list;
- if (!priv->cd00_list || !priv->cd01_list)
+ if (!priv->cd00_list || !priv->cd01_list) {
+ component_unbind_all(dev, NULL);
+
return -ENODEV;
+ }
lwmi_om_fan_info_collect_cd00(priv);
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v11 04/15] platform/x86: lenovo-wmi-other: Zero initialize WMI arguments
[not found] <20260507180507.912966-1-derekjohn.clark@gmail.com>
` (2 preceding siblings ...)
2026-05-07 18:04 ` [PATCH v11 03/15] platform/x86: lenovo-wmi-other: Balance component bind and unbind Derek J. Clark
@ 2026-05-07 18:04 ` Derek J. Clark
2026-05-08 14:22 ` Ilpo Järvinen
2026-05-07 18:04 ` [PATCH v11 05/15] platform/x86: lenovo-wmi-other: Fix tunable_attr_01 struct members Derek J. Clark
` (4 subsequent siblings)
8 siblings, 1 reply; 15+ messages in thread
From: Derek J. Clark @ 2026-05-07 18:04 UTC (permalink / raw)
To: Ilpo Järvinen, Hans de Goede
Cc: Mark Pearson, Armin Wolf, Jonathan Corbet, Rong Zhang, Kurt Borja,
Derek J . Clark, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, linux-kernel, stable
Adds explicit initialization of wmi_method_args_32 declarations with
zero values to prevent uninitialized data from being sent to the device
BIOS when passed.
No functional change intended.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Fixes: 22024ac5366f ("platform/x86: Add Lenovo Gamezone WMI Driver")
Fixes: edc4b183b794 ("platform/x86: Add Lenovo Other Mode WMI Driver")
Reported-by: Rong Zhang <i@rong.moe>
Closes: https://lore.kernel.org/platform-driver-x86/95c7e7b539dd0af41189c754fcd35cec5b6fe182.camel@rong.moe/
Cc: stable@vger.kernel.org
Reviewed-by: Rong Zhang <i@rong.moe>
Tested-by: Rong Zhang <i@rong.moe>
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
v7:
- Include lwmi_gz_profile_set() fix as well.
---
drivers/platform/x86/lenovo/wmi-gamezone.c | 2 +-
drivers/platform/x86/lenovo/wmi-other.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/lenovo/wmi-gamezone.c b/drivers/platform/x86/lenovo/wmi-gamezone.c
index 381836d29a96..ca559e6c031d 100644
--- a/drivers/platform/x86/lenovo/wmi-gamezone.c
+++ b/drivers/platform/x86/lenovo/wmi-gamezone.c
@@ -203,7 +203,7 @@ static int lwmi_gz_profile_set(struct device *dev,
enum platform_profile_option profile)
{
struct lwmi_gz_priv *priv = dev_get_drvdata(dev);
- struct wmi_method_args_32 args;
+ struct wmi_method_args_32 args = {};
enum thermal_mode mode;
int ret;
diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
index a6be3463341c..1e06b894cfcc 100644
--- a/drivers/platform/x86/lenovo/wmi-other.c
+++ b/drivers/platform/x86/lenovo/wmi-other.c
@@ -166,7 +166,7 @@ MODULE_PARM_DESC(relax_fan_constraint,
*/
static int lwmi_om_fan_get_set(struct lwmi_om_priv *priv, int channel, u32 *val, bool set)
{
- struct wmi_method_args_32 args;
+ struct wmi_method_args_32 args = {};
u32 method_id, retval;
int err;
@@ -773,7 +773,7 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
struct tunable_attr_01 *tunable_attr)
{
struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev);
- struct wmi_method_args_32 args;
+ struct wmi_method_args_32 args = {};
struct capdata01 capdata;
enum thermal_mode mode;
u32 attribute_id;
@@ -836,7 +836,7 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
struct tunable_attr_01 *tunable_attr)
{
struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev);
- struct wmi_method_args_32 args;
+ struct wmi_method_args_32 args = {};
enum thermal_mode mode;
u32 attribute_id;
int retval;
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v11 04/15] platform/x86: lenovo-wmi-other: Zero initialize WMI arguments
2026-05-07 18:04 ` [PATCH v11 04/15] platform/x86: lenovo-wmi-other: Zero initialize WMI arguments Derek J. Clark
@ 2026-05-08 14:22 ` Ilpo Järvinen
0 siblings, 0 replies; 15+ messages in thread
From: Ilpo Järvinen @ 2026-05-08 14:22 UTC (permalink / raw)
To: Derek J. Clark
Cc: Hans de Goede, Mark Pearson, Armin Wolf, Jonathan Corbet,
Rong Zhang, Kurt Borja, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, LKML, stable
On Thu, 7 May 2026, Derek J. Clark wrote:
> Adds explicit initialization of wmi_method_args_32 declarations with
> zero values to prevent uninitialized data from being sent to the device
> BIOS when passed.
>
> No functional change intended.
Missing empty line.
> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Fixes: 22024ac5366f ("platform/x86: Add Lenovo Gamezone WMI Driver")
> Fixes: edc4b183b794 ("platform/x86: Add Lenovo Other Mode WMI Driver")
> Reported-by: Rong Zhang <i@rong.moe>
> Closes: https://lore.kernel.org/platform-driver-x86/95c7e7b539dd0af41189c754fcd35cec5b6fe182.camel@rong.moe/
> Cc: stable@vger.kernel.org
> Reviewed-by: Rong Zhang <i@rong.moe>
> Tested-by: Rong Zhang <i@rong.moe>
> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
> ---
> v7:
> - Include lwmi_gz_profile_set() fix as well.
> ---
> drivers/platform/x86/lenovo/wmi-gamezone.c | 2 +-
> drivers/platform/x86/lenovo/wmi-other.c | 6 +++---
> 2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/wmi-gamezone.c b/drivers/platform/x86/lenovo/wmi-gamezone.c
> index 381836d29a96..ca559e6c031d 100644
> --- a/drivers/platform/x86/lenovo/wmi-gamezone.c
> +++ b/drivers/platform/x86/lenovo/wmi-gamezone.c
> @@ -203,7 +203,7 @@ static int lwmi_gz_profile_set(struct device *dev,
> enum platform_profile_option profile)
> {
> struct lwmi_gz_priv *priv = dev_get_drvdata(dev);
> - struct wmi_method_args_32 args;
> + struct wmi_method_args_32 args = {};
> enum thermal_mode mode;
> int ret;
>
> diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
> index a6be3463341c..1e06b894cfcc 100644
> --- a/drivers/platform/x86/lenovo/wmi-other.c
> +++ b/drivers/platform/x86/lenovo/wmi-other.c
> @@ -166,7 +166,7 @@ MODULE_PARM_DESC(relax_fan_constraint,
> */
> static int lwmi_om_fan_get_set(struct lwmi_om_priv *priv, int channel, u32 *val, bool set)
> {
> - struct wmi_method_args_32 args;
> + struct wmi_method_args_32 args = {};
> u32 method_id, retval;
> int err;
>
> @@ -773,7 +773,7 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
> struct tunable_attr_01 *tunable_attr)
> {
> struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev);
> - struct wmi_method_args_32 args;
> + struct wmi_method_args_32 args = {};
> struct capdata01 capdata;
> enum thermal_mode mode;
> u32 attribute_id;
> @@ -836,7 +836,7 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
> struct tunable_attr_01 *tunable_attr)
> {
> struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev);
> - struct wmi_method_args_32 args;
> + struct wmi_method_args_32 args = {};
> enum thermal_mode mode;
> u32 attribute_id;
> int retval;
>
--
i.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v11 05/15] platform/x86: lenovo-wmi-other: Fix tunable_attr_01 struct members
[not found] <20260507180507.912966-1-derekjohn.clark@gmail.com>
` (3 preceding siblings ...)
2026-05-07 18:04 ` [PATCH v11 04/15] platform/x86: lenovo-wmi-other: Zero initialize WMI arguments Derek J. Clark
@ 2026-05-07 18:04 ` Derek J. Clark
2026-05-08 14:32 ` Ilpo Järvinen
2026-05-07 18:04 ` [PATCH v11 06/15] platform/x86: lenovo: Decouple lenovo-wmi-gamezone and lenovo-wmi-other Derek J. Clark
` (3 subsequent siblings)
8 siblings, 1 reply; 15+ messages in thread
From: Derek J. Clark @ 2026-05-07 18:04 UTC (permalink / raw)
To: Ilpo Järvinen, Hans de Goede
Cc: Mark Pearson, Armin Wolf, Jonathan Corbet, Rong Zhang, Kurt Borja,
Derek J . Clark, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, linux-kernel, stable
In struct tunable_attr_01 the capdata pointer is unused and the size of
the id members is u32 when it should be u8. Fix these prior to adding
additional members.
No functional change intended.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Fixes: e1a5fe662b59 ("platform/x86: Add Lenovo Capability Data 01 WMI Driver")
Cc: stable@vger.kernel.org
Reviewed-by: Rong Zhang <i@rong.moe>
Tested-by: Rong Zhang <i@rong.moe>
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/platform/x86/lenovo/wmi-other.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
index 1e06b894cfcc..50a03f5fd6ab 100644
--- a/drivers/platform/x86/lenovo/wmi-other.c
+++ b/drivers/platform/x86/lenovo/wmi-other.c
@@ -546,11 +546,10 @@ static void lwmi_om_fan_info_collect_cd_fan(struct device *dev, struct cd_list *
/* ======== fw_attributes (component: lenovo-wmi-capdata 01) ======== */
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;
};
static struct tunable_attr_01 ppt_pl1_spl = {
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v11 05/15] platform/x86: lenovo-wmi-other: Fix tunable_attr_01 struct members
2026-05-07 18:04 ` [PATCH v11 05/15] platform/x86: lenovo-wmi-other: Fix tunable_attr_01 struct members Derek J. Clark
@ 2026-05-08 14:32 ` Ilpo Järvinen
0 siblings, 0 replies; 15+ messages in thread
From: Ilpo Järvinen @ 2026-05-08 14:32 UTC (permalink / raw)
To: Derek J. Clark
Cc: Hans de Goede, Mark Pearson, Armin Wolf, Jonathan Corbet,
Rong Zhang, Kurt Borja, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, LKML, stable
On Thu, 7 May 2026, Derek J. Clark wrote:
> In struct tunable_attr_01 the capdata pointer is unused and the size of
> the id members is u32 when it should be u8. Fix these prior to adding
> additional members.
>
> No functional change intended.
>
> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Fixes: e1a5fe662b59 ("platform/x86: Add Lenovo Capability Data 01 WMI Driver")
This too does not need fixes tag as there is no user visible bug that is
being fixed. An unused variable isn't bug even if it's a good thing to
maintain such cleanliness while coding.
--
i.
> Cc: stable@vger.kernel.org
> Reviewed-by: Rong Zhang <i@rong.moe>
> Tested-by: Rong Zhang <i@rong.moe>
> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
> ---
> drivers/platform/x86/lenovo/wmi-other.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
> index 1e06b894cfcc..50a03f5fd6ab 100644
> --- a/drivers/platform/x86/lenovo/wmi-other.c
> +++ b/drivers/platform/x86/lenovo/wmi-other.c
> @@ -546,11 +546,10 @@ static void lwmi_om_fan_info_collect_cd_fan(struct device *dev, struct cd_list *
> /* ======== fw_attributes (component: lenovo-wmi-capdata 01) ======== */
>
> 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;
> };
>
> static struct tunable_attr_01 ppt_pl1_spl = {
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v11 06/15] platform/x86: lenovo: Decouple lenovo-wmi-gamezone and lenovo-wmi-other
[not found] <20260507180507.912966-1-derekjohn.clark@gmail.com>
` (4 preceding siblings ...)
2026-05-07 18:04 ` [PATCH v11 05/15] platform/x86: lenovo-wmi-other: Fix tunable_attr_01 struct members Derek J. Clark
@ 2026-05-07 18:04 ` Derek J. Clark
2026-05-07 18:04 ` [PATCH v11 07/15] platform/x86: lenovo-wmi-helpers: Move gamezone enums to wmi-helpers Derek J. Clark
` (2 subsequent siblings)
8 siblings, 0 replies; 15+ messages in thread
From: Derek J. Clark @ 2026-05-07 18:04 UTC (permalink / raw)
To: Ilpo Järvinen, Hans de Goede
Cc: Mark Pearson, Armin Wolf, Jonathan Corbet, Rong Zhang, Kurt Borja,
Derek J . Clark, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, linux-kernel, stable, kernel test robot
From: Rong Zhang <i@rong.moe>
Currently, lenovo-wmi-gamezone depends on lenovo-wmi-other as the former
imports symbols from the latter. The imported symbols are just used to
register a notifier block. However, there is no runtime dependency
between both drivers, and either of them can run without the other,
which is the major purpose of using the notifier framework.
Such a link-time dependency is non-optimal. A previous attempt to "fix"
it made LENOVO_WMI_GAMEZONE select LENOVO_WMI_TUNING, which was
fundamentally broken and resulted in undefined Kconfig behavior, as
`select' cannot be used on a symbol with potentially unmet dependencies.
Decouple both drivers by moving the thermal mode notifier chain to
lenovo-wmi-helpers. Methods for notifier block (un)registration are
exported for lenovo-wmi-gamezone, while a method for querying the
current thermal mode are exported for lenovo-wmi-other.
This turns the dependency graph from
+------------ lenovo-wmi-gamezone
| |
v |
lenovo-wmi-helpers |
^ |
| V
+------------ lenovo-wmi-other
into
+------------ lenovo-wmi-gamezone
|
v
lenovo-wmi-helpers
^
|
+------------ lenovo-wmi-other
To make it clear, the name of the notifier chain is also renamed from
`om_chain_head' to `tm_chain_head', indicating that it's used to query
the current thermal mode.
No functional change intended.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Fixes: 6e38b9fcbfa3 ("platform/x86: lenovo: gamezone needs "other mode"")
Cc: stable@vger.kernel.org
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202603252259.gHvJDyh3-lkp@intel.com/
Closes: https://lore.kernel.org/oe-kbuild-all/202603260302.X0NjQOda-lkp@intel.com/
Signed-off-by: Rong Zhang <i@rong.moe>
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
drivers/platform/x86/lenovo/Kconfig | 1 -
drivers/platform/x86/lenovo/wmi-gamezone.c | 4 +-
drivers/platform/x86/lenovo/wmi-helpers.c | 101 ++++++++++++++++++++
drivers/platform/x86/lenovo/wmi-helpers.h | 8 ++
drivers/platform/x86/lenovo/wmi-other.c | 104 +--------------------
drivers/platform/x86/lenovo/wmi-other.h | 16 ----
6 files changed, 112 insertions(+), 122 deletions(-)
delete mode 100644 drivers/platform/x86/lenovo/wmi-other.h
diff --git a/drivers/platform/x86/lenovo/Kconfig b/drivers/platform/x86/lenovo/Kconfig
index f885127b007f..09b1b055d2e0 100644
--- a/drivers/platform/x86/lenovo/Kconfig
+++ b/drivers/platform/x86/lenovo/Kconfig
@@ -252,7 +252,6 @@ config LENOVO_WMI_GAMEZONE
select ACPI_PLATFORM_PROFILE
select LENOVO_WMI_EVENTS
select LENOVO_WMI_HELPERS
- select LENOVO_WMI_TUNING
help
Say Y here if you have a WMI aware Lenovo Legion device and would like to use the
platform-profile firmware interface to manage power usage.
diff --git a/drivers/platform/x86/lenovo/wmi-gamezone.c b/drivers/platform/x86/lenovo/wmi-gamezone.c
index ca559e6c031d..a91089694727 100644
--- a/drivers/platform/x86/lenovo/wmi-gamezone.c
+++ b/drivers/platform/x86/lenovo/wmi-gamezone.c
@@ -23,7 +23,6 @@
#include "wmi-events.h"
#include "wmi-gamezone.h"
#include "wmi-helpers.h"
-#include "wmi-other.h"
#define LENOVO_GAMEZONE_GUID "887B54E3-DDDC-4B2C-8B88-68A26A8835D0"
@@ -385,7 +384,7 @@ static int lwmi_gz_probe(struct wmi_device *wdev, const void *context)
return ret;
priv->mode_nb.notifier_call = lwmi_gz_mode_call;
- return devm_lwmi_om_register_notifier(&wdev->dev, &priv->mode_nb);
+ return devm_lwmi_tm_register_notifier(&wdev->dev, &priv->mode_nb);
}
static const struct wmi_device_id lwmi_gz_id_table[] = {
@@ -407,7 +406,6 @@ module_wmi_driver(lwmi_gz_driver);
MODULE_IMPORT_NS("LENOVO_WMI_EVENTS");
MODULE_IMPORT_NS("LENOVO_WMI_HELPERS");
-MODULE_IMPORT_NS("LENOVO_WMI_OTHER");
MODULE_DEVICE_TABLE(wmi, lwmi_gz_id_table);
MODULE_AUTHOR("Derek J. Clark <derekjohn.clark@gmail.com>");
MODULE_DESCRIPTION("Lenovo GameZone WMI Driver");
diff --git a/drivers/platform/x86/lenovo/wmi-helpers.c b/drivers/platform/x86/lenovo/wmi-helpers.c
index 018d7642e2bd..7a198259e393 100644
--- a/drivers/platform/x86/lenovo/wmi-helpers.c
+++ b/drivers/platform/x86/lenovo/wmi-helpers.c
@@ -21,11 +21,15 @@
#include <linux/errno.h>
#include <linux/export.h>
#include <linux/module.h>
+#include <linux/notifier.h>
#include <linux/unaligned.h>
#include <linux/wmi.h>
#include "wmi-helpers.h"
+/* Thermal mode notifier chain. */
+static BLOCKING_NOTIFIER_HEAD(tm_chain_head);
+
/**
* lwmi_dev_evaluate_int() - Helper function for calling WMI methods that
* return an integer.
@@ -84,6 +88,103 @@ int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method_id,
};
EXPORT_SYMBOL_NS_GPL(lwmi_dev_evaluate_int, "LENOVO_WMI_HELPERS");
+/**
+ * lwmi_tm_register_notifier() - Add a notifier to the blocking notifier chain
+ * @nb: The notifier_block struct to register
+ *
+ * Call blocking_notifier_chain_register to register the notifier block to the
+ * thermal mode notifier chain.
+ *
+ * Return: 0 on success, %-EEXIST on error.
+ */
+int lwmi_tm_register_notifier(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_register(&tm_chain_head, nb);
+}
+EXPORT_SYMBOL_NS_GPL(lwmi_tm_register_notifier, "LENOVO_WMI_HELPERS");
+
+/**
+ * lwmi_tm_unregister_notifier() - Remove a notifier from the blocking notifier
+ * chain.
+ * @nb: The notifier_block struct to register
+ *
+ * Call blocking_notifier_chain_unregister to unregister the notifier block from the
+ * thermal mode notifier chain.
+ *
+ * Return: 0 on success, %-ENOENT on error.
+ */
+int lwmi_tm_unregister_notifier(struct notifier_block *nb)
+{
+ return blocking_notifier_chain_unregister(&tm_chain_head, nb);
+}
+EXPORT_SYMBOL_NS_GPL(lwmi_tm_unregister_notifier, "LENOVO_WMI_HELPERS");
+
+/**
+ * devm_lwmi_tm_unregister_notifier() - Remove a notifier from the blocking
+ * notifier chain.
+ * @data: Void pointer to the notifier_block struct to register.
+ *
+ * Call lwmi_tm_unregister_notifier to unregister the notifier block from the
+ * thermal mode notifier chain.
+ *
+ * Return: 0 on success, %-ENOENT on error.
+ */
+static void devm_lwmi_tm_unregister_notifier(void *data)
+{
+ struct notifier_block *nb = data;
+
+ lwmi_tm_unregister_notifier(nb);
+}
+
+/**
+ * devm_lwmi_tm_register_notifier() - Add a notifier to the blocking notifier
+ * chain.
+ * @dev: The parent device of the notifier_block struct.
+ * @nb: The notifier_block struct to register
+ *
+ * Call lwmi_tm_register_notifier to register the notifier block to the
+ * thermal mode notifier chain. Then add devm_lwmi_tm_unregister_notifier
+ * as a device managed action to automatically unregister the notifier block
+ * upon parent device removal.
+ *
+ * Return: 0 on success, or an error code.
+ */
+int devm_lwmi_tm_register_notifier(struct device *dev,
+ struct notifier_block *nb)
+{
+ int ret;
+
+ ret = lwmi_tm_register_notifier(nb);
+ if (ret < 0)
+ return ret;
+
+ return devm_add_action_or_reset(dev, devm_lwmi_tm_unregister_notifier,
+ nb);
+}
+EXPORT_SYMBOL_NS_GPL(devm_lwmi_tm_register_notifier, "LENOVO_WMI_HELPERS");
+
+/**
+ * lwmi_tm_notifier_call() - Call functions for the notifier call chain.
+ * @mode: Pointer to a thermal mode enum to retrieve the data from.
+ *
+ * Call blocking_notifier_call_chain to retrieve the thermal mode from the
+ * lenovo-wmi-gamezone driver.
+ *
+ * Return: 0 on success, or an error code.
+ */
+int lwmi_tm_notifier_call(enum thermal_mode *mode)
+{
+ int ret;
+
+ ret = blocking_notifier_call_chain(&tm_chain_head,
+ LWMI_GZ_GET_THERMAL_MODE, &mode);
+ if ((ret & ~NOTIFY_STOP_MASK) != NOTIFY_OK)
+ return -EINVAL;
+
+ return 0;
+}
+EXPORT_SYMBOL_NS_GPL(lwmi_tm_notifier_call, "LENOVO_WMI_HELPERS");
+
MODULE_AUTHOR("Derek J. Clark <derekjohn.clark@gmail.com>");
MODULE_DESCRIPTION("Lenovo WMI Helpers Driver");
MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/lenovo/wmi-helpers.h b/drivers/platform/x86/lenovo/wmi-helpers.h
index 20fd21749803..651a039228ed 100644
--- a/drivers/platform/x86/lenovo/wmi-helpers.h
+++ b/drivers/platform/x86/lenovo/wmi-helpers.h
@@ -7,6 +7,8 @@
#include <linux/types.h>
+struct device;
+struct notifier_block;
struct wmi_device;
struct wmi_method_args_32 {
@@ -17,4 +19,10 @@ struct wmi_method_args_32 {
int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method_id,
unsigned char *buf, size_t size, u32 *retval);
+int lwmi_tm_register_notifier(struct notifier_block *nb);
+int lwmi_tm_unregister_notifier(struct notifier_block *nb);
+int devm_lwmi_tm_register_notifier(struct device *dev,
+ struct notifier_block *nb);
+int lwmi_tm_notifier_call(enum thermal_mode *mode);
+
#endif /* !_LENOVO_WMI_HELPERS_H_ */
diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
index 50a03f5fd6ab..f63e568a4e12 100644
--- a/drivers/platform/x86/lenovo/wmi-other.c
+++ b/drivers/platform/x86/lenovo/wmi-other.c
@@ -40,7 +40,6 @@
#include <linux/kobject.h>
#include <linux/limits.h>
#include <linux/module.h>
-#include <linux/notifier.h>
#include <linux/platform_profile.h>
#include <linux/types.h>
#include <linux/wmi.h>
@@ -49,7 +48,6 @@
#include "wmi-events.h"
#include "wmi-gamezone.h"
#include "wmi-helpers.h"
-#include "wmi-other.h"
#include "../firmware_attributes_class.h"
#define LENOVO_OTHER_MODE_GUID "DC2A8805-3A8C-41BA-A6F7-092E0089CD3B"
@@ -81,7 +79,6 @@
#define LWMI_OM_FW_ATTR_BASE_PATH "lenovo-wmi-other"
#define LWMI_OM_HWMON_NAME "lenovo_wmi_other"
-static BLOCKING_NOTIFIER_HEAD(om_chain_head);
static DEFINE_IDA(lwmi_om_ida);
enum attribute_property {
@@ -109,7 +106,6 @@ struct lwmi_om_priv {
struct device *hwmon_dev;
struct device *fw_attr_dev;
struct kset *fw_attr_kset;
- struct notifier_block nb;
struct wmi_device *wdev;
int ida_id;
@@ -575,102 +571,6 @@ struct capdata01_attr_group {
struct tunable_attr_01 *tunable_attr;
};
-/**
- * lwmi_om_register_notifier() - Add a notifier to the blocking notifier chain
- * @nb: The notifier_block struct to register
- *
- * Call blocking_notifier_chain_register to register the notifier block to the
- * lenovo-wmi-other driver notifier chain.
- *
- * Return: 0 on success, %-EEXIST on error.
- */
-int lwmi_om_register_notifier(struct notifier_block *nb)
-{
- return blocking_notifier_chain_register(&om_chain_head, nb);
-}
-EXPORT_SYMBOL_NS_GPL(lwmi_om_register_notifier, "LENOVO_WMI_OTHER");
-
-/**
- * lwmi_om_unregister_notifier() - Remove a notifier from the blocking notifier
- * chain.
- * @nb: The notifier_block struct to register
- *
- * Call blocking_notifier_chain_unregister to unregister the notifier block from the
- * lenovo-wmi-other driver notifier chain.
- *
- * Return: 0 on success, %-ENOENT on error.
- */
-int lwmi_om_unregister_notifier(struct notifier_block *nb)
-{
- return blocking_notifier_chain_unregister(&om_chain_head, nb);
-}
-EXPORT_SYMBOL_NS_GPL(lwmi_om_unregister_notifier, "LENOVO_WMI_OTHER");
-
-/**
- * devm_lwmi_om_unregister_notifier() - Remove a notifier from the blocking
- * notifier chain.
- * @data: Void pointer to the notifier_block struct to register.
- *
- * Call lwmi_om_unregister_notifier to unregister the notifier block from the
- * lenovo-wmi-other driver notifier chain.
- *
- * Return: 0 on success, %-ENOENT on error.
- */
-static void devm_lwmi_om_unregister_notifier(void *data)
-{
- struct notifier_block *nb = data;
-
- lwmi_om_unregister_notifier(nb);
-}
-
-/**
- * devm_lwmi_om_register_notifier() - Add a notifier to the blocking notifier
- * chain.
- * @dev: The parent device of the notifier_block struct.
- * @nb: The notifier_block struct to register
- *
- * Call lwmi_om_register_notifier to register the notifier block to the
- * lenovo-wmi-other driver notifier chain. Then add devm_lwmi_om_unregister_notifier
- * as a device managed action to automatically unregister the notifier block
- * upon parent device removal.
- *
- * Return: 0 on success, or an error code.
- */
-int devm_lwmi_om_register_notifier(struct device *dev,
- struct notifier_block *nb)
-{
- int ret;
-
- ret = lwmi_om_register_notifier(nb);
- if (ret < 0)
- return ret;
-
- return devm_add_action_or_reset(dev, devm_lwmi_om_unregister_notifier,
- nb);
-}
-EXPORT_SYMBOL_NS_GPL(devm_lwmi_om_register_notifier, "LENOVO_WMI_OTHER");
-
-/**
- * lwmi_om_notifier_call() - Call functions for the notifier call chain.
- * @mode: Pointer to a thermal mode enum to retrieve the data from.
- *
- * Call blocking_notifier_call_chain to retrieve the thermal mode from the
- * lenovo-wmi-gamezone driver.
- *
- * Return: 0 on success, or an error code.
- */
-static int lwmi_om_notifier_call(enum thermal_mode *mode)
-{
- int ret;
-
- ret = blocking_notifier_call_chain(&om_chain_head,
- LWMI_GZ_GET_THERMAL_MODE, &mode);
- if ((ret & ~NOTIFY_STOP_MASK) != NOTIFY_OK)
- return -EINVAL;
-
- return 0;
-}
-
/* Attribute Methods */
/**
@@ -779,7 +679,7 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
u32 value;
int ret;
- ret = lwmi_om_notifier_call(&mode);
+ ret = lwmi_tm_notifier_call(&mode);
if (ret)
return ret;
@@ -841,7 +741,7 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
int retval;
int ret;
- ret = lwmi_om_notifier_call(&mode);
+ ret = lwmi_tm_notifier_call(&mode);
if (ret)
return ret;
diff --git a/drivers/platform/x86/lenovo/wmi-other.h b/drivers/platform/x86/lenovo/wmi-other.h
deleted file mode 100644
index 8ebf5602bb99..000000000000
--- a/drivers/platform/x86/lenovo/wmi-other.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-/* Copyright (C) 2025 Derek J. Clark <derekjohn.clark@gmail.com> */
-
-#ifndef _LENOVO_WMI_OTHER_H_
-#define _LENOVO_WMI_OTHER_H_
-
-struct device;
-struct notifier_block;
-
-int lwmi_om_register_notifier(struct notifier_block *nb);
-int lwmi_om_unregister_notifier(struct notifier_block *nb);
-int devm_lwmi_om_register_notifier(struct device *dev,
- struct notifier_block *nb);
-
-#endif /* !_LENOVO_WMI_OTHER_H_ */
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH v11 07/15] platform/x86: lenovo-wmi-helpers: Move gamezone enums to wmi-helpers
[not found] <20260507180507.912966-1-derekjohn.clark@gmail.com>
` (5 preceding siblings ...)
2026-05-07 18:04 ` [PATCH v11 06/15] platform/x86: lenovo: Decouple lenovo-wmi-gamezone and lenovo-wmi-other Derek J. Clark
@ 2026-05-07 18:04 ` Derek J. Clark
2026-05-08 14:21 ` Ilpo Järvinen
2026-05-07 18:05 ` [PATCH v11 08/15] platform/x86: lenovo-wmi-other: Add lwmi_attr_id() function Derek J. Clark
2026-05-07 18:05 ` [PATCH v11 09/15] platform/x86: lenovo-wmi-other: Limit adding attributes to supported devices Derek J. Clark
8 siblings, 1 reply; 15+ messages in thread
From: Derek J. Clark @ 2026-05-07 18:04 UTC (permalink / raw)
To: Ilpo Järvinen, Hans de Goede
Cc: Mark Pearson, Armin Wolf, Jonathan Corbet, Rong Zhang, Kurt Borja,
Derek J . Clark, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, linux-kernel, stable
In a later patch in the series the thermal mode enum will be accessed
across three separate drivers (wmi-capdata, wmi-gamezonem and wmi-other).
An additional patch in the series will also add a function protoype that
needs to reference this enum in wmi-helpers.h. To avoid having all these
drivers begin to import each others headers, and to avoid declaring an
opaque enum to hande the second case, move the thermal mode enum to
helpers where it can be safely accessed by everything that needs it from
a single import.
While at it, since the gamezone_events_type enum is the only remaining
item in the header, move that as well and remove the gamezone header
entirely.
Fixes: 22024ac5366f ("platform/x86: Add Lenovo Gamezone WMI Driver")
Cc: stable@vger.kernel.org
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Reviewed-by: Rong Zhang <i@rong.moe>
Tested-by: Rong Zhang <i@rong.moe>
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
v11:
- Move to earlier in the series as later patches depend on it.
---
drivers/platform/x86/lenovo/wmi-events.c | 2 +-
drivers/platform/x86/lenovo/wmi-gamezone.c | 1 -
drivers/platform/x86/lenovo/wmi-gamezone.h | 20 --------------------
drivers/platform/x86/lenovo/wmi-helpers.h | 13 +++++++++++++
drivers/platform/x86/lenovo/wmi-other.c | 1 -
5 files changed, 14 insertions(+), 23 deletions(-)
delete mode 100644 drivers/platform/x86/lenovo/wmi-gamezone.h
diff --git a/drivers/platform/x86/lenovo/wmi-events.c b/drivers/platform/x86/lenovo/wmi-events.c
index 0994cd7dd504..9e9f2e82e04d 100644
--- a/drivers/platform/x86/lenovo/wmi-events.c
+++ b/drivers/platform/x86/lenovo/wmi-events.c
@@ -17,7 +17,7 @@
#include <linux/wmi.h>
#include "wmi-events.h"
-#include "wmi-gamezone.h"
+#include "wmi-helpers.h"
#define THERMAL_MODE_EVENT_GUID "D320289E-8FEA-41E0-86F9-911D83151B5F"
diff --git a/drivers/platform/x86/lenovo/wmi-gamezone.c b/drivers/platform/x86/lenovo/wmi-gamezone.c
index a91089694727..5a8f4aee02cf 100644
--- a/drivers/platform/x86/lenovo/wmi-gamezone.c
+++ b/drivers/platform/x86/lenovo/wmi-gamezone.c
@@ -21,7 +21,6 @@
#include <linux/wmi.h>
#include "wmi-events.h"
-#include "wmi-gamezone.h"
#include "wmi-helpers.h"
#define LENOVO_GAMEZONE_GUID "887B54E3-DDDC-4B2C-8B88-68A26A8835D0"
diff --git a/drivers/platform/x86/lenovo/wmi-gamezone.h b/drivers/platform/x86/lenovo/wmi-gamezone.h
deleted file mode 100644
index 6b163a5eeb95..000000000000
--- a/drivers/platform/x86/lenovo/wmi-gamezone.h
+++ /dev/null
@@ -1,20 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-/* Copyright (C) 2025 Derek J. Clark <derekjohn.clark@gmail.com> */
-
-#ifndef _LENOVO_WMI_GAMEZONE_H_
-#define _LENOVO_WMI_GAMEZONE_H_
-
-enum gamezone_events_type {
- LWMI_GZ_GET_THERMAL_MODE = 1,
-};
-
-enum thermal_mode {
- LWMI_GZ_THERMAL_MODE_QUIET = 0x01,
- LWMI_GZ_THERMAL_MODE_BALANCED = 0x02,
- LWMI_GZ_THERMAL_MODE_PERFORMANCE = 0x03,
- LWMI_GZ_THERMAL_MODE_EXTREME = 0xE0, /* Ver 6+ */
- LWMI_GZ_THERMAL_MODE_CUSTOM = 0xFF,
-};
-
-#endif /* !_LENOVO_WMI_GAMEZONE_H_ */
diff --git a/drivers/platform/x86/lenovo/wmi-helpers.h b/drivers/platform/x86/lenovo/wmi-helpers.h
index 651a039228ed..ed7db3ebba6c 100644
--- a/drivers/platform/x86/lenovo/wmi-helpers.h
+++ b/drivers/platform/x86/lenovo/wmi-helpers.h
@@ -16,6 +16,19 @@ struct wmi_method_args_32 {
u32 arg1;
};
+enum lwmi_event_type {
+ LWMI_GZ_GET_THERMAL_MODE = 0x01,
+};
+
+enum thermal_mode {
+ LWMI_GZ_THERMAL_MODE_NONE = 0x00,
+ LWMI_GZ_THERMAL_MODE_QUIET = 0x01,
+ LWMI_GZ_THERMAL_MODE_BALANCED = 0x02,
+ LWMI_GZ_THERMAL_MODE_PERFORMANCE = 0x03,
+ LWMI_GZ_THERMAL_MODE_EXTREME = 0xE0, /* Ver 6+ */
+ LWMI_GZ_THERMAL_MODE_CUSTOM = 0xFF,
+};
+
int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method_id,
unsigned char *buf, size_t size, u32 *retval);
diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
index f63e568a4e12..b4ed7af50a24 100644
--- a/drivers/platform/x86/lenovo/wmi-other.c
+++ b/drivers/platform/x86/lenovo/wmi-other.c
@@ -46,7 +46,6 @@
#include "wmi-capdata.h"
#include "wmi-events.h"
-#include "wmi-gamezone.h"
#include "wmi-helpers.h"
#include "../firmware_attributes_class.h"
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v11 07/15] platform/x86: lenovo-wmi-helpers: Move gamezone enums to wmi-helpers
2026-05-07 18:04 ` [PATCH v11 07/15] platform/x86: lenovo-wmi-helpers: Move gamezone enums to wmi-helpers Derek J. Clark
@ 2026-05-08 14:21 ` Ilpo Järvinen
2026-05-08 14:30 ` Derek J. Clark
0 siblings, 1 reply; 15+ messages in thread
From: Ilpo Järvinen @ 2026-05-08 14:21 UTC (permalink / raw)
To: Derek J. Clark
Cc: Hans de Goede, Mark Pearson, Armin Wolf, Jonathan Corbet,
Rong Zhang, Kurt Borja, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, LKML, stable
On Thu, 7 May 2026, Derek J. Clark wrote:
It seems there are a few nits still to address (they were too many so I'd
want to try to do inline editing).
> In a later patch in the series the thermal mode enum will be accessed
> across three separate drivers (wmi-capdata, wmi-gamezonem and wmi-other).
> An additional patch in the series will also add a function protoype that
prototype
> needs to reference this enum in wmi-helpers.h. To avoid having all these
> drivers begin to import each others headers, and to avoid declaring an
> opaque enum to hande the second case, move the thermal mode enum to
> helpers where it can be safely accessed by everything that needs it from
> a single import.
>
> While at it, since the gamezone_events_type enum is the only remaining
> item in the header, move that as well and remove the gamezone header
> entirely.
>
> Fixes: 22024ac5366f ("platform/x86: Add Lenovo Gamezone WMI Driver")
This change doesn't seem to exactly fix anything so it shouldn't have
Fixes tag.
We want to only have Cc: stable in the prerequisites for some other fix
that comes after.
My plan is to take patches 1-9 through fixes branch and then merge fixes
to for-next and take the rest through for-next.
--
i.
> Cc: stable@vger.kernel.org
> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Reviewed-by: Rong Zhang <i@rong.moe>
> Tested-by: Rong Zhang <i@rong.moe>
> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
> ---
> v11:
> - Move to earlier in the series as later patches depend on it.
> ---
> drivers/platform/x86/lenovo/wmi-events.c | 2 +-
> drivers/platform/x86/lenovo/wmi-gamezone.c | 1 -
> drivers/platform/x86/lenovo/wmi-gamezone.h | 20 --------------------
> drivers/platform/x86/lenovo/wmi-helpers.h | 13 +++++++++++++
> drivers/platform/x86/lenovo/wmi-other.c | 1 -
> 5 files changed, 14 insertions(+), 23 deletions(-)
> delete mode 100644 drivers/platform/x86/lenovo/wmi-gamezone.h
>
> diff --git a/drivers/platform/x86/lenovo/wmi-events.c b/drivers/platform/x86/lenovo/wmi-events.c
> index 0994cd7dd504..9e9f2e82e04d 100644
> --- a/drivers/platform/x86/lenovo/wmi-events.c
> +++ b/drivers/platform/x86/lenovo/wmi-events.c
> @@ -17,7 +17,7 @@
> #include <linux/wmi.h>
>
> #include "wmi-events.h"
> -#include "wmi-gamezone.h"
> +#include "wmi-helpers.h"
>
> #define THERMAL_MODE_EVENT_GUID "D320289E-8FEA-41E0-86F9-911D83151B5F"
>
> diff --git a/drivers/platform/x86/lenovo/wmi-gamezone.c b/drivers/platform/x86/lenovo/wmi-gamezone.c
> index a91089694727..5a8f4aee02cf 100644
> --- a/drivers/platform/x86/lenovo/wmi-gamezone.c
> +++ b/drivers/platform/x86/lenovo/wmi-gamezone.c
> @@ -21,7 +21,6 @@
> #include <linux/wmi.h>
>
> #include "wmi-events.h"
> -#include "wmi-gamezone.h"
> #include "wmi-helpers.h"
>
> #define LENOVO_GAMEZONE_GUID "887B54E3-DDDC-4B2C-8B88-68A26A8835D0"
> diff --git a/drivers/platform/x86/lenovo/wmi-gamezone.h b/drivers/platform/x86/lenovo/wmi-gamezone.h
> deleted file mode 100644
> index 6b163a5eeb95..000000000000
> --- a/drivers/platform/x86/lenovo/wmi-gamezone.h
> +++ /dev/null
> @@ -1,20 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0-or-later */
> -
> -/* Copyright (C) 2025 Derek J. Clark <derekjohn.clark@gmail.com> */
> -
> -#ifndef _LENOVO_WMI_GAMEZONE_H_
> -#define _LENOVO_WMI_GAMEZONE_H_
> -
> -enum gamezone_events_type {
> - LWMI_GZ_GET_THERMAL_MODE = 1,
> -};
> -
> -enum thermal_mode {
> - LWMI_GZ_THERMAL_MODE_QUIET = 0x01,
> - LWMI_GZ_THERMAL_MODE_BALANCED = 0x02,
> - LWMI_GZ_THERMAL_MODE_PERFORMANCE = 0x03,
> - LWMI_GZ_THERMAL_MODE_EXTREME = 0xE0, /* Ver 6+ */
> - LWMI_GZ_THERMAL_MODE_CUSTOM = 0xFF,
> -};
> -
> -#endif /* !_LENOVO_WMI_GAMEZONE_H_ */
> diff --git a/drivers/platform/x86/lenovo/wmi-helpers.h b/drivers/platform/x86/lenovo/wmi-helpers.h
> index 651a039228ed..ed7db3ebba6c 100644
> --- a/drivers/platform/x86/lenovo/wmi-helpers.h
> +++ b/drivers/platform/x86/lenovo/wmi-helpers.h
> @@ -16,6 +16,19 @@ struct wmi_method_args_32 {
> u32 arg1;
> };
>
> +enum lwmi_event_type {
> + LWMI_GZ_GET_THERMAL_MODE = 0x01,
> +};
> +
> +enum thermal_mode {
> + LWMI_GZ_THERMAL_MODE_NONE = 0x00,
> + LWMI_GZ_THERMAL_MODE_QUIET = 0x01,
> + LWMI_GZ_THERMAL_MODE_BALANCED = 0x02,
> + LWMI_GZ_THERMAL_MODE_PERFORMANCE = 0x03,
> + LWMI_GZ_THERMAL_MODE_EXTREME = 0xE0, /* Ver 6+ */
> + LWMI_GZ_THERMAL_MODE_CUSTOM = 0xFF,
> +};
> +
> int lwmi_dev_evaluate_int(struct wmi_device *wdev, u8 instance, u32 method_id,
> unsigned char *buf, size_t size, u32 *retval);
>
> diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
> index f63e568a4e12..b4ed7af50a24 100644
> --- a/drivers/platform/x86/lenovo/wmi-other.c
> +++ b/drivers/platform/x86/lenovo/wmi-other.c
> @@ -46,7 +46,6 @@
>
> #include "wmi-capdata.h"
> #include "wmi-events.h"
> -#include "wmi-gamezone.h"
> #include "wmi-helpers.h"
> #include "../firmware_attributes_class.h"
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH v11 07/15] platform/x86: lenovo-wmi-helpers: Move gamezone enums to wmi-helpers
2026-05-08 14:21 ` Ilpo Järvinen
@ 2026-05-08 14:30 ` Derek J. Clark
0 siblings, 0 replies; 15+ messages in thread
From: Derek J. Clark @ 2026-05-08 14:30 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Hans de Goede, Mark Pearson, Armin Wolf, Jonathan Corbet,
Rong Zhang, Kurt Borja, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, LKML, stable
On May 8, 2026 7:21:22 AM PDT, "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com> wrote:
>On Thu, 7 May 2026, Derek J. Clark wrote:
>
>It seems there are a few nits still to address (they were too many so I'd
>want to try to do inline editing).
>
No problem. I'll try to get v12 done today after you're done with the review.
>> In a later patch in the series the thermal mode enum will be accessed
>> across three separate drivers (wmi-capdata, wmi-gamezonem and wmi-other).
>> An additional patch in the series will also add a function protoype that
>
>prototype
>
>> needs to reference this enum in wmi-helpers.h. To avoid having all these
>> drivers begin to import each others headers, and to avoid declaring an
>> opaque enum to hande the second case, move the thermal mode enum to
>> helpers where it can be safely accessed by everything that needs it from
>> a single import.
>>
>> While at it, since the gamezone_events_type enum is the only remaining
>> item in the header, move that as well and remove the gamezone header
>> entirely.
>>
>> Fixes: 22024ac5366f ("platform/x86: Add Lenovo Gamezone WMI Driver")
>
>This change doesn't seem to exactly fix anything so it shouldn't have
>Fixes tag.
>
>We want to only have Cc: stable in the prerequisites for some other fix
>that comes after.
>
Makes sense. I wasn't sure, checkpatch flagged it as missing a fixes tag and I figured it was easier to drop than to have you try and find the original commit. I'll drop that for the formatting only patches.
Thanks,
Derek
>My plan is to take patches 1-9 through fixes branch and then merge fixes
>to for-next and take the rest through for-next.
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v11 08/15] platform/x86: lenovo-wmi-other: Add lwmi_attr_id() function
[not found] <20260507180507.912966-1-derekjohn.clark@gmail.com>
` (6 preceding siblings ...)
2026-05-07 18:04 ` [PATCH v11 07/15] platform/x86: lenovo-wmi-helpers: Move gamezone enums to wmi-helpers Derek J. Clark
@ 2026-05-07 18:05 ` Derek J. Clark
2026-05-08 14:25 ` Ilpo Järvinen
2026-05-07 18:05 ` [PATCH v11 09/15] platform/x86: lenovo-wmi-other: Limit adding attributes to supported devices Derek J. Clark
8 siblings, 1 reply; 15+ messages in thread
From: Derek J. Clark @ 2026-05-07 18:05 UTC (permalink / raw)
To: Ilpo Järvinen, Hans de Goede
Cc: Mark Pearson, Armin Wolf, Jonathan Corbet, Rong Zhang, Kurt Borja,
Derek J . Clark, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, linux-kernel, stable
Adds lwmi_attr_id() function. In the same vein as LWMI_ATTR_ID_FAN_RPM(),
but as a generic, to de-duplicate attribute_id assignment biolerplate.
Fixes: edc4b183b794 ("platform/x86: Add Lenovo Other Mode WMI Driver")
Cc: stable@vger.kernel.org
Reviewed-by: Rong Zhang <i@rong.moe>
Tested-by: Rong Zhang <i@rong.moe>
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
v11:
- Move to earlier in the series to clean up later patches that can
use it.
- Add helper function that takes a tunable_attr_01 instead of breaking
out all struct members manually each time the macro is used.
v9:
- Fix dropped use of mode variable in current_value_show.
v7:
- Incorporate additional replacements in lwmi_attr_01_is_supported
after moving the patch that adds it to earlier in the series.
v6:
- Move lwmi_attr_id to wmi-capdata.h as static inline.
v5:
- Move references to cv/cd_mode_id to patch 4/8.
- Move lwmi_attr_id to wmi-capdata.c and export with namespace.
v4:
- Switch from macro to static inline to preserve types.
---
drivers/platform/x86/lenovo/wmi-capdata.c | 8 ++--
drivers/platform/x86/lenovo/wmi-capdata.h | 20 +++++++++
drivers/platform/x86/lenovo/wmi-other.c | 49 +++++++++--------------
3 files changed, 44 insertions(+), 33 deletions(-)
diff --git a/drivers/platform/x86/lenovo/wmi-capdata.c b/drivers/platform/x86/lenovo/wmi-capdata.c
index ee1fb02d8e31..169665be4dcf 100644
--- a/drivers/platform/x86/lenovo/wmi-capdata.c
+++ b/drivers/platform/x86/lenovo/wmi-capdata.c
@@ -27,7 +27,6 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/acpi.h>
-#include <linux/bitfield.h>
#include <linux/bug.h>
#include <linux/cleanup.h>
#include <linux/component.h>
@@ -48,6 +47,7 @@
#include <linux/wmi.h>
#include "wmi-capdata.h"
+#include "wmi-helpers.h"
#define LENOVO_CAPABILITY_DATA_00_GUID "362A3AFE-3D96-4665-8530-96DAD5BB300E"
#define LENOVO_CAPABILITY_DATA_01_GUID "7A8F5407-CB67-4D6E-B547-39B3BE018154"
@@ -58,9 +58,9 @@
#define LWMI_FEATURE_ID_FAN_TEST 0x05
-#define LWMI_ATTR_ID_FAN_TEST \
- (FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, LWMI_DEVICE_ID_FAN) | \
- FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, LWMI_FEATURE_ID_FAN_TEST))
+#define LWMI_ATTR_ID_FAN_TEST \
+ lwmi_attr_id(LWMI_DEVICE_ID_FAN, LWMI_FEATURE_ID_FAN_TEST, \
+ LWMI_GZ_THERMAL_MODE_NONE, LWMI_TYPE_ID_NONE)
enum lwmi_cd_type {
LENOVO_CAPABILITY_DATA_00,
diff --git a/drivers/platform/x86/lenovo/wmi-capdata.h b/drivers/platform/x86/lenovo/wmi-capdata.h
index 8c1df3efcc55..1388eaf4ab4a 100644
--- a/drivers/platform/x86/lenovo/wmi-capdata.h
+++ b/drivers/platform/x86/lenovo/wmi-capdata.h
@@ -6,6 +6,7 @@
#define _LENOVO_WMI_CAPDATA_H_
#include <linux/bits.h>
+#include <linux/bitfield.h>
#include <linux/types.h>
#define LWMI_SUPP_VALID BIT(0)
@@ -19,6 +20,8 @@
#define LWMI_DEVICE_ID_FAN 0x04
+#define LWMI_TYPE_ID_NONE 0x00
+
struct component_match;
struct device;
struct cd_list;
@@ -57,6 +60,23 @@ struct lwmi_cd_binder {
cd_list_cb_t cd_fan_list_cb;
};
+/**
+ * lwmi_attr_id() - Formats a capability data attribute ID
+ * @dev_id: The u8 corresponding to the device ID.
+ * @feat_id: The u8 corresponding to the feature ID on the device.
+ * @mode_id: The u8 corresponding to the wmi-gamezone mode for set/get.
+ * @type_id: The u8 corresponding to the sub-device.
+ *
+ * Return: u32.
+ */
+static inline u32 lwmi_attr_id(u8 dev_id, u8 feat_id, u8 mode_id, u8 type_id)
+{
+ return (FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, dev_id) |
+ FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, feat_id) |
+ FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode_id) |
+ FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, type_id));
+}
+
void lwmi_cd_match_add_all(struct device *master, struct component_match **matchptr);
int lwmi_cd00_get_data(struct cd_list *list, u32 attribute_id, struct capdata00 *output);
int lwmi_cd01_get_data(struct cd_list *list, u32 attribute_id, struct capdata01 *output);
diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
index b4ed7af50a24..e69bea72e6d3 100644
--- a/drivers/platform/x86/lenovo/wmi-other.c
+++ b/drivers/platform/x86/lenovo/wmi-other.c
@@ -59,8 +59,6 @@
#define LWMI_FEATURE_ID_FAN_RPM 0x03
-#define LWMI_TYPE_ID_NONE 0x00
-
#define LWMI_FEATURE_VALUE_GET 17
#define LWMI_FEATURE_VALUE_SET 18
@@ -68,13 +66,12 @@
#define LWMI_FAN_NR 4
#define LWMI_FAN_ID(x) ((x) + LWMI_FAN_ID_BASE)
-#define LWMI_ATTR_ID_FAN_RPM(x) \
- (FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, LWMI_DEVICE_ID_FAN) | \
- FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, LWMI_FEATURE_ID_FAN_RPM) | \
- FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, LWMI_FAN_ID(x)))
-
#define LWMI_FAN_DIV 100
+#define LWMI_ATTR_ID_FAN_RPM(x) \
+ lwmi_attr_id(LWMI_DEVICE_ID_FAN, LWMI_FEATURE_ID_FAN_RPM, \
+ LWMI_GZ_THERMAL_MODE_NONE, LWMI_FAN_ID(x))
+
#define LWMI_OM_FW_ATTR_BASE_PATH "lenovo-wmi-other"
#define LWMI_OM_HWMON_NAME "lenovo_wmi_other"
@@ -547,6 +544,18 @@ struct tunable_attr_01 {
u8 type_id;
};
+/**
+ * tunable_attr_01_id() - Formats a tunable_attr_01 to a capdata attribute ID
+ * @attr: The tunable_attr_01 to format.
+ * @mode: The u8 corresponding to the wmi-gamezone mode for set/get.
+ *
+ * Return: u32.
+ */
+static u32 tunable_attr_01_id(struct tunable_attr_01 *attr, u8 mode)
+{
+ return lwmi_attr_id(attr->device_id, attr->feature_id, mode, attr->type_id);
+}
+
static struct tunable_attr_01 ppt_pl1_spl = {
.device_id = LWMI_DEVICE_ID_CPU,
.feature_id = LWMI_FEATURE_ID_CPU_SPL,
@@ -614,12 +623,7 @@ static ssize_t attr_capdata01_show(struct kobject *kobj,
u32 attribute_id;
int value, ret;
- attribute_id =
- FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) |
- FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) |
- FIELD_PREP(LWMI_ATTR_MODE_ID_MASK,
- LWMI_GZ_THERMAL_MODE_CUSTOM) |
- FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id);
+ attribute_id = tunable_attr_01_id(tunable_attr, LWMI_GZ_THERMAL_MODE_CUSTOM);
ret = lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata);
if (ret)
@@ -674,7 +678,6 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
struct wmi_method_args_32 args = {};
struct capdata01 capdata;
enum thermal_mode mode;
- u32 attribute_id;
u32 value;
int ret;
@@ -685,13 +688,9 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
if (mode != LWMI_GZ_THERMAL_MODE_CUSTOM)
return -EBUSY;
- attribute_id =
- FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) |
- FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) |
- FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode) |
- FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id);
+ args.arg0 = tunable_attr_01_id(tunable_attr, mode);
- ret = lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata);
+ ret = lwmi_cd01_get_data(priv->cd01_list, args.arg0, &capdata);
if (ret)
return ret;
@@ -702,7 +701,6 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
if (value < capdata.min_value || value > capdata.max_value)
return -EINVAL;
- args.arg0 = attribute_id;
args.arg1 = value;
ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_SET,
@@ -736,7 +734,6 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev);
struct wmi_method_args_32 args = {};
enum thermal_mode mode;
- u32 attribute_id;
int retval;
int ret;
@@ -744,13 +741,7 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
if (ret)
return ret;
- attribute_id =
- FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) |
- FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) |
- FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode) |
- FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id);
-
- args.arg0 = attribute_id;
+ args.arg0 = tunable_attr_01_id(tunable_attr, mode);
ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_GET,
(unsigned char *)&args, sizeof(args),
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v11 08/15] platform/x86: lenovo-wmi-other: Add lwmi_attr_id() function
2026-05-07 18:05 ` [PATCH v11 08/15] platform/x86: lenovo-wmi-other: Add lwmi_attr_id() function Derek J. Clark
@ 2026-05-08 14:25 ` Ilpo Järvinen
0 siblings, 0 replies; 15+ messages in thread
From: Ilpo Järvinen @ 2026-05-08 14:25 UTC (permalink / raw)
To: Derek J. Clark
Cc: Hans de Goede, Mark Pearson, Armin Wolf, Jonathan Corbet,
Rong Zhang, Kurt Borja, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, LKML, stable
On Thu, 7 May 2026, Derek J. Clark wrote:
> Adds lwmi_attr_id() function. In the same vein as LWMI_ATTR_ID_FAN_RPM(),
> but as a generic, to de-duplicate attribute_id assignment biolerplate.
>
> Fixes: edc4b183b794 ("platform/x86: Add Lenovo Other Mode WMI Driver")
Also for this, I don't think we're actually fixing anything here (but just
refactoring code which should result exactly the same behavior)?
> Cc: stable@vger.kernel.org
> Reviewed-by: Rong Zhang <i@rong.moe>
> Tested-by: Rong Zhang <i@rong.moe>
> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
> ---
> v11:
> - Move to earlier in the series to clean up later patches that can
> use it.
> - Add helper function that takes a tunable_attr_01 instead of breaking
> out all struct members manually each time the macro is used.
> v9:
> - Fix dropped use of mode variable in current_value_show.
> v7:
> - Incorporate additional replacements in lwmi_attr_01_is_supported
> after moving the patch that adds it to earlier in the series.
> v6:
> - Move lwmi_attr_id to wmi-capdata.h as static inline.
> v5:
> - Move references to cv/cd_mode_id to patch 4/8.
> - Move lwmi_attr_id to wmi-capdata.c and export with namespace.
> v4:
> - Switch from macro to static inline to preserve types.
> ---
> drivers/platform/x86/lenovo/wmi-capdata.c | 8 ++--
> drivers/platform/x86/lenovo/wmi-capdata.h | 20 +++++++++
> drivers/platform/x86/lenovo/wmi-other.c | 49 +++++++++--------------
> 3 files changed, 44 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/wmi-capdata.c b/drivers/platform/x86/lenovo/wmi-capdata.c
> index ee1fb02d8e31..169665be4dcf 100644
> --- a/drivers/platform/x86/lenovo/wmi-capdata.c
> +++ b/drivers/platform/x86/lenovo/wmi-capdata.c
> @@ -27,7 +27,6 @@
> #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>
> #include <linux/acpi.h>
> -#include <linux/bitfield.h>
> #include <linux/bug.h>
> #include <linux/cleanup.h>
> #include <linux/component.h>
> @@ -48,6 +47,7 @@
> #include <linux/wmi.h>
>
> #include "wmi-capdata.h"
> +#include "wmi-helpers.h"
>
> #define LENOVO_CAPABILITY_DATA_00_GUID "362A3AFE-3D96-4665-8530-96DAD5BB300E"
> #define LENOVO_CAPABILITY_DATA_01_GUID "7A8F5407-CB67-4D6E-B547-39B3BE018154"
> @@ -58,9 +58,9 @@
>
> #define LWMI_FEATURE_ID_FAN_TEST 0x05
>
> -#define LWMI_ATTR_ID_FAN_TEST \
> - (FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, LWMI_DEVICE_ID_FAN) | \
> - FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, LWMI_FEATURE_ID_FAN_TEST))
> +#define LWMI_ATTR_ID_FAN_TEST \
> + lwmi_attr_id(LWMI_DEVICE_ID_FAN, LWMI_FEATURE_ID_FAN_TEST, \
> + LWMI_GZ_THERMAL_MODE_NONE, LWMI_TYPE_ID_NONE)
>
> enum lwmi_cd_type {
> LENOVO_CAPABILITY_DATA_00,
> diff --git a/drivers/platform/x86/lenovo/wmi-capdata.h b/drivers/platform/x86/lenovo/wmi-capdata.h
> index 8c1df3efcc55..1388eaf4ab4a 100644
> --- a/drivers/platform/x86/lenovo/wmi-capdata.h
> +++ b/drivers/platform/x86/lenovo/wmi-capdata.h
> @@ -6,6 +6,7 @@
> #define _LENOVO_WMI_CAPDATA_H_
>
> #include <linux/bits.h>
> +#include <linux/bitfield.h>
> #include <linux/types.h>
>
> #define LWMI_SUPP_VALID BIT(0)
> @@ -19,6 +20,8 @@
>
> #define LWMI_DEVICE_ID_FAN 0x04
>
> +#define LWMI_TYPE_ID_NONE 0x00
> +
> struct component_match;
> struct device;
> struct cd_list;
> @@ -57,6 +60,23 @@ struct lwmi_cd_binder {
> cd_list_cb_t cd_fan_list_cb;
> };
>
> +/**
> + * lwmi_attr_id() - Formats a capability data attribute ID
> + * @dev_id: The u8 corresponding to the device ID.
> + * @feat_id: The u8 corresponding to the feature ID on the device.
> + * @mode_id: The u8 corresponding to the wmi-gamezone mode for set/get.
> + * @type_id: The u8 corresponding to the sub-device.
> + *
> + * Return: u32.
Kerneldoc knows the type from C syntax. It's more useful to write what
the returned value is (encoded attribute ID?).
--
i.
> + */
> +static inline u32 lwmi_attr_id(u8 dev_id, u8 feat_id, u8 mode_id, u8 type_id)
> +{
> + return (FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, dev_id) |
> + FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, feat_id) |
> + FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode_id) |
> + FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, type_id));
> +}
> +
> void lwmi_cd_match_add_all(struct device *master, struct component_match **matchptr);
> int lwmi_cd00_get_data(struct cd_list *list, u32 attribute_id, struct capdata00 *output);
> int lwmi_cd01_get_data(struct cd_list *list, u32 attribute_id, struct capdata01 *output);
> diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
> index b4ed7af50a24..e69bea72e6d3 100644
> --- a/drivers/platform/x86/lenovo/wmi-other.c
> +++ b/drivers/platform/x86/lenovo/wmi-other.c
> @@ -59,8 +59,6 @@
>
> #define LWMI_FEATURE_ID_FAN_RPM 0x03
>
> -#define LWMI_TYPE_ID_NONE 0x00
> -
> #define LWMI_FEATURE_VALUE_GET 17
> #define LWMI_FEATURE_VALUE_SET 18
>
> @@ -68,13 +66,12 @@
> #define LWMI_FAN_NR 4
> #define LWMI_FAN_ID(x) ((x) + LWMI_FAN_ID_BASE)
>
> -#define LWMI_ATTR_ID_FAN_RPM(x) \
> - (FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, LWMI_DEVICE_ID_FAN) | \
> - FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, LWMI_FEATURE_ID_FAN_RPM) | \
> - FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, LWMI_FAN_ID(x)))
> -
> #define LWMI_FAN_DIV 100
>
> +#define LWMI_ATTR_ID_FAN_RPM(x) \
> + lwmi_attr_id(LWMI_DEVICE_ID_FAN, LWMI_FEATURE_ID_FAN_RPM, \
> + LWMI_GZ_THERMAL_MODE_NONE, LWMI_FAN_ID(x))
> +
> #define LWMI_OM_FW_ATTR_BASE_PATH "lenovo-wmi-other"
> #define LWMI_OM_HWMON_NAME "lenovo_wmi_other"
>
> @@ -547,6 +544,18 @@ struct tunable_attr_01 {
> u8 type_id;
> };
>
> +/**
> + * tunable_attr_01_id() - Formats a tunable_attr_01 to a capdata attribute ID
> + * @attr: The tunable_attr_01 to format.
> + * @mode: The u8 corresponding to the wmi-gamezone mode for set/get.
> + *
> + * Return: u32.
> + */
> +static u32 tunable_attr_01_id(struct tunable_attr_01 *attr, u8 mode)
> +{
> + return lwmi_attr_id(attr->device_id, attr->feature_id, mode, attr->type_id);
> +}
> +
> static struct tunable_attr_01 ppt_pl1_spl = {
> .device_id = LWMI_DEVICE_ID_CPU,
> .feature_id = LWMI_FEATURE_ID_CPU_SPL,
> @@ -614,12 +623,7 @@ static ssize_t attr_capdata01_show(struct kobject *kobj,
> u32 attribute_id;
> int value, ret;
>
> - attribute_id =
> - FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) |
> - FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) |
> - FIELD_PREP(LWMI_ATTR_MODE_ID_MASK,
> - LWMI_GZ_THERMAL_MODE_CUSTOM) |
> - FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id);
> + attribute_id = tunable_attr_01_id(tunable_attr, LWMI_GZ_THERMAL_MODE_CUSTOM);
>
> ret = lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata);
> if (ret)
> @@ -674,7 +678,6 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
> struct wmi_method_args_32 args = {};
> struct capdata01 capdata;
> enum thermal_mode mode;
> - u32 attribute_id;
> u32 value;
> int ret;
>
> @@ -685,13 +688,9 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
> if (mode != LWMI_GZ_THERMAL_MODE_CUSTOM)
> return -EBUSY;
>
> - attribute_id =
> - FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) |
> - FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) |
> - FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode) |
> - FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id);
> + args.arg0 = tunable_attr_01_id(tunable_attr, mode);
>
> - ret = lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata);
> + ret = lwmi_cd01_get_data(priv->cd01_list, args.arg0, &capdata);
> if (ret)
> return ret;
>
> @@ -702,7 +701,6 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
> if (value < capdata.min_value || value > capdata.max_value)
> return -EINVAL;
>
> - args.arg0 = attribute_id;
> args.arg1 = value;
>
> ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_SET,
> @@ -736,7 +734,6 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
> struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev);
> struct wmi_method_args_32 args = {};
> enum thermal_mode mode;
> - u32 attribute_id;
> int retval;
> int ret;
>
> @@ -744,13 +741,7 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
> if (ret)
> return ret;
>
> - attribute_id =
> - FIELD_PREP(LWMI_ATTR_DEV_ID_MASK, tunable_attr->device_id) |
> - FIELD_PREP(LWMI_ATTR_FEAT_ID_MASK, tunable_attr->feature_id) |
> - FIELD_PREP(LWMI_ATTR_MODE_ID_MASK, mode) |
> - FIELD_PREP(LWMI_ATTR_TYPE_ID_MASK, tunable_attr->type_id);
> -
> - args.arg0 = attribute_id;
> + args.arg0 = tunable_attr_01_id(tunable_attr, mode);
>
> ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_GET,
> (unsigned char *)&args, sizeof(args),
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v11 09/15] platform/x86: lenovo-wmi-other: Limit adding attributes to supported devices
[not found] <20260507180507.912966-1-derekjohn.clark@gmail.com>
` (7 preceding siblings ...)
2026-05-07 18:05 ` [PATCH v11 08/15] platform/x86: lenovo-wmi-other: Add lwmi_attr_id() function Derek J. Clark
@ 2026-05-07 18:05 ` Derek J. Clark
2026-05-08 14:28 ` Ilpo Järvinen
8 siblings, 1 reply; 15+ messages in thread
From: Derek J. Clark @ 2026-05-07 18:05 UTC (permalink / raw)
To: Ilpo Järvinen, Hans de Goede
Cc: Mark Pearson, Armin Wolf, Jonathan Corbet, Rong Zhang, Kurt Borja,
Derek J . Clark, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, linux-kernel, stable
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).
- 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.
Fixes: edc4b183b794 ("platform/x86: Add Lenovo Other Mode WMI Driver")
Reported-by: Kurt Borja <kuurtb@gmail.com>
Closes: https://lore.kernel.org/platform-driver-x86/DG60P3SHXR8H.3NSEHMZ6J7XRC@gmail.com/
Cc: stable@vger.kernel.org
Reviewed-by: Rong Zhang <i@rong.moe>
Tested-by: Rong Zhang <i@rong.moe>
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
v11:
- Also use cd_mode_id in attr_capdata_show.
v7:
- Move earlier in the series. This required dropping the use of
lwmi_attr_id as it will be added later.
- Add missing switch between cd_mode_id and cv_mode_id in
current_value_store.
v6:
- Zero initialize args in lwmi_is_attr_01_supported.
- Fix formatting.
v5:
- Move cv/cd_mode_id refrences from path 3/4.
- Add missing import for ARRAY_SIZE.
- Make lwmi_is_attr_01_supported return bool instead of u32.
- Various formatting fixes.
v4:
- Use for loop instead of backtrace gotos for checking if an attribute
is supported.
- Add include for dev_printk.
- Wrap dev_dbg in lwmi_is_attr_01_supported earlier.
- Don't use symmetric cleanup of attributes in error states.
---
drivers/platform/x86/lenovo/wmi-other.c | 86 +++++++++++++++++++++++--
1 file changed, 82 insertions(+), 4 deletions(-)
diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
index e69bea72e6d3..e3cdcd0f4331 100644
--- a/drivers/platform/x86/lenovo/wmi-other.c
+++ b/drivers/platform/x86/lenovo/wmi-other.c
@@ -542,6 +542,8 @@ struct tunable_attr_01 {
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 */
};
/**
@@ -623,7 +625,7 @@ static ssize_t attr_capdata01_show(struct kobject *kobj,
u32 attribute_id;
int value, ret;
- attribute_id = tunable_attr_01_id(tunable_attr, LWMI_GZ_THERMAL_MODE_CUSTOM);
+ attribute_id = tunable_attr_01_id(tunable_attr, tunable_attr->cd_mode_id);
ret = lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata);
if (ret)
@@ -688,7 +690,7 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
if (mode != LWMI_GZ_THERMAL_MODE_CUSTOM)
return -EBUSY;
- args.arg0 = tunable_attr_01_id(tunable_attr, mode);
+ args.arg0 = tunable_attr_01_id(tunable_attr, tunable_attr->cd_mode_id);
ret = lwmi_cd01_get_data(priv->cd01_list, args.arg0, &capdata);
if (ret)
@@ -701,6 +703,7 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
if (value < capdata.min_value || value > capdata.max_value)
return -EINVAL;
+ args.arg0 = tunable_attr_01_id(tunable_attr, tunable_attr->cv_mode_id);
args.arg1 = value;
ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_SET,
@@ -741,6 +744,10 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
if (ret)
return ret;
+ /* If "no-mode" is the supported mode, ensure we never send current mode */
+ if (tunable_attr->cv_mode_id == LWMI_GZ_THERMAL_MODE_NONE)
+ mode = tunable_attr->cv_mode_id;
+
args.arg0 = tunable_attr_01_id(tunable_attr, mode);
ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_GET,
@@ -752,6 +759,75 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
return sysfs_emit(buf, "%d\n", retval);
}
+/**
+ * lwmi_attr_01_is_supported() - Determine if the given attribute is supported.
+ * @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 check if
+ * there is a corresponding "no-mode" (0x00) entry. If either of those passes,
+ * check capdata->supported for values > 0. If capdata is available, attempt to
+ * determine the set/get mode for the current value property using a similar
+ * 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 checks
+ * fail then the attribute is not fully supported.
+ *
+ * The probed cd_mode_id/cv_mode_id are stored on the tunable_attr for later
+ * reference.
+ *
+ * Return: bool.
+ */
+static bool lwmi_attr_01_is_supported(struct tunable_attr_01 *tunable_attr)
+{
+ u8 modes[2] = { LWMI_GZ_THERMAL_MODE_CUSTOM, LWMI_GZ_THERMAL_MODE_NONE };
+ struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev);
+ struct wmi_method_args_32 args = {};
+ bool cd_mode_found = false;
+ bool cv_mode_found = false;
+ struct capdata01 capdata;
+ int retval, ret, i;
+
+ /* Determine tunable_attr->cd_mode_id*/
+ for (i = 0; i < ARRAY_SIZE(modes); i++) {
+ args.arg0 = tunable_attr_01_id(tunable_attr, modes[i]);
+
+ ret = lwmi_cd01_get_data(priv->cd01_list, args.arg0, &capdata);
+ if (ret || !capdata.supported)
+ continue;
+ tunable_attr->cd_mode_id = modes[i];
+ cd_mode_found = true;
+ break;
+ }
+
+ if (!cd_mode_found)
+ return cd_mode_found;
+
+ dev_dbg(tunable_attr->dev,
+ "cd_mode_id: %#010x\n", args.arg0);
+
+ /* Determine tunable_attr->cv_mode_id, returns 1 if supported*/
+ for (i = 0; i < ARRAY_SIZE(modes); i++) {
+ args.arg0 = tunable_attr_01_id(tunable_attr, modes[i]);
+
+ ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_GET,
+ (unsigned char *)&args, sizeof(args),
+ &retval);
+ if (ret || !retval)
+ continue;
+ tunable_attr->cv_mode_id = modes[i];
+ cv_mode_found = true;
+ break;
+ }
+
+ if (!cv_mode_found)
+ return cv_mode_found;
+
+ dev_dbg(tunable_attr->dev, "cv_mode_id: %#010x, attribute support level: %#010x\n",
+ args.arg0, capdata.supported);
+
+ return capdata.supported > 0 ? true : false;
+}
+
/* Lenovo WMI Other Mode Attribute macros */
#define __LWMI_ATTR_RO(_func, _name) \
{ \
@@ -875,12 +951,14 @@ static void lwmi_om_fw_attr_add(struct lwmi_om_priv *priv)
}
for (i = 0; i < ARRAY_SIZE(cd01_attr_groups) - 1; i++) {
+ cd01_attr_groups[i].tunable_attr->dev = &priv->wdev->dev;
+ if (!lwmi_attr_01_is_supported(cd01_attr_groups[i].tunable_attr))
+ continue;
+
err = 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 = &priv->wdev->dev;
}
return;
--
2.53.0
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH v11 09/15] platform/x86: lenovo-wmi-other: Limit adding attributes to supported devices
2026-05-07 18:05 ` [PATCH v11 09/15] platform/x86: lenovo-wmi-other: Limit adding attributes to supported devices Derek J. Clark
@ 2026-05-08 14:28 ` Ilpo Järvinen
0 siblings, 0 replies; 15+ messages in thread
From: Ilpo Järvinen @ 2026-05-08 14:28 UTC (permalink / raw)
To: Derek J. Clark
Cc: Hans de Goede, Mark Pearson, Armin Wolf, Jonathan Corbet,
Rong Zhang, Kurt Borja, Pierre-Loup A . Griffais,
Nícolas F . R . A . Prado, marshall, hyacinth,
platform-driver-x86, LKML, stable
On Thu, 7 May 2026, Derek J. Clark wrote:
> 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).
> - 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.
>
> Fixes: edc4b183b794 ("platform/x86: Add Lenovo Other Mode WMI Driver")
> Reported-by: Kurt Borja <kuurtb@gmail.com>
> Closes: https://lore.kernel.org/platform-driver-x86/DG60P3SHXR8H.3NSEHMZ6J7XRC@gmail.com/
> Cc: stable@vger.kernel.org
> Reviewed-by: Rong Zhang <i@rong.moe>
> Tested-by: Rong Zhang <i@rong.moe>
> Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
> ---
> v11:
> - Also use cd_mode_id in attr_capdata_show.
> v7:
> - Move earlier in the series. This required dropping the use of
> lwmi_attr_id as it will be added later.
> - Add missing switch between cd_mode_id and cv_mode_id in
> current_value_store.
> v6:
> - Zero initialize args in lwmi_is_attr_01_supported.
> - Fix formatting.
> v5:
> - Move cv/cd_mode_id refrences from path 3/4.
> - Add missing import for ARRAY_SIZE.
> - Make lwmi_is_attr_01_supported return bool instead of u32.
> - Various formatting fixes.
> v4:
> - Use for loop instead of backtrace gotos for checking if an attribute
> is supported.
> - Add include for dev_printk.
> - Wrap dev_dbg in lwmi_is_attr_01_supported earlier.
> - Don't use symmetric cleanup of attributes in error states.
> ---
> drivers/platform/x86/lenovo/wmi-other.c | 86 +++++++++++++++++++++++--
> 1 file changed, 82 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
> index e69bea72e6d3..e3cdcd0f4331 100644
> --- a/drivers/platform/x86/lenovo/wmi-other.c
> +++ b/drivers/platform/x86/lenovo/wmi-other.c
> @@ -542,6 +542,8 @@ struct tunable_attr_01 {
> 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 */
> };
>
> /**
> @@ -623,7 +625,7 @@ static ssize_t attr_capdata01_show(struct kobject *kobj,
> u32 attribute_id;
> int value, ret;
>
> - attribute_id = tunable_attr_01_id(tunable_attr, LWMI_GZ_THERMAL_MODE_CUSTOM);
> + attribute_id = tunable_attr_01_id(tunable_attr, tunable_attr->cd_mode_id);
>
> ret = lwmi_cd01_get_data(priv->cd01_list, attribute_id, &capdata);
> if (ret)
> @@ -688,7 +690,7 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
> if (mode != LWMI_GZ_THERMAL_MODE_CUSTOM)
> return -EBUSY;
>
> - args.arg0 = tunable_attr_01_id(tunable_attr, mode);
> + args.arg0 = tunable_attr_01_id(tunable_attr, tunable_attr->cd_mode_id);
>
> ret = lwmi_cd01_get_data(priv->cd01_list, args.arg0, &capdata);
> if (ret)
> @@ -701,6 +703,7 @@ static ssize_t attr_current_value_store(struct kobject *kobj,
> if (value < capdata.min_value || value > capdata.max_value)
> return -EINVAL;
>
> + args.arg0 = tunable_attr_01_id(tunable_attr, tunable_attr->cv_mode_id);
> args.arg1 = value;
>
> ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_SET,
> @@ -741,6 +744,10 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
> if (ret)
> return ret;
>
> + /* If "no-mode" is the supported mode, ensure we never send current mode */
> + if (tunable_attr->cv_mode_id == LWMI_GZ_THERMAL_MODE_NONE)
> + mode = tunable_attr->cv_mode_id;
> +
> args.arg0 = tunable_attr_01_id(tunable_attr, mode);
>
> ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_GET,
> @@ -752,6 +759,75 @@ static ssize_t attr_current_value_show(struct kobject *kobj,
> return sysfs_emit(buf, "%d\n", retval);
> }
>
> +/**
> + * lwmi_attr_01_is_supported() - Determine if the given attribute is supported.
> + * @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 check if
> + * there is a corresponding "no-mode" (0x00) entry. If either of those passes,
> + * check capdata->supported for values > 0. If capdata is available, attempt to
> + * determine the set/get mode for the current value property using a similar
> + * 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 checks
> + * fail then the attribute is not fully supported.
Can you try to split this into 2-3 paragraphs. It has the long wall of
text feel as is.
> + *
> + * The probed cd_mode_id/cv_mode_id are stored on the tunable_attr for later
> + * reference.
> + *
> + * Return: bool.
Describe what is returned, not its type (that is know to kerneldoc from
syntax).
> + */
> +static bool lwmi_attr_01_is_supported(struct tunable_attr_01 *tunable_attr)
> +{
> + u8 modes[2] = { LWMI_GZ_THERMAL_MODE_CUSTOM, LWMI_GZ_THERMAL_MODE_NONE };
> + struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev);
> + struct wmi_method_args_32 args = {};
> + bool cd_mode_found = false;
> + bool cv_mode_found = false;
> + struct capdata01 capdata;
> + int retval, ret, i;
> +
> + /* Determine tunable_attr->cd_mode_id*/
Missing space.
> + for (i = 0; i < ARRAY_SIZE(modes); i++) {
> + args.arg0 = tunable_attr_01_id(tunable_attr, modes[i]);
> +
> + ret = lwmi_cd01_get_data(priv->cd01_list, args.arg0, &capdata);
> + if (ret || !capdata.supported)
> + continue;
I'd add empty lines here to help.
> + tunable_attr->cd_mode_id = modes[i];
> + cd_mode_found = true;
> + break;
> + }
> +
> + if (!cd_mode_found)
> + return cd_mode_found;
> +
> + dev_dbg(tunable_attr->dev,
> + "cd_mode_id: %#010x\n", args.arg0);
> +
> + /* Determine tunable_attr->cv_mode_id, returns 1 if supported*/
Missing space.
> + for (i = 0; i < ARRAY_SIZE(modes); i++) {
> + args.arg0 = tunable_attr_01_id(tunable_attr, modes[i]);
> +
> + ret = lwmi_dev_evaluate_int(priv->wdev, 0x0, LWMI_FEATURE_VALUE_GET,
> + (unsigned char *)&args, sizeof(args),
> + &retval);
> + if (ret || !retval)
> + continue;
Empty line here as well.
> + tunable_attr->cv_mode_id = modes[i];
> + cv_mode_found = true;
> + break;
> + }
> +
> + if (!cv_mode_found)
> + return cv_mode_found;
> +
> + dev_dbg(tunable_attr->dev, "cv_mode_id: %#010x, attribute support level: %#010x\n",
> + args.arg0, capdata.supported);
> +
> + return capdata.supported > 0 ? true : false;
This is enough when the function returns bool:
return capdata.supported > 0;
> +}
> +
> /* Lenovo WMI Other Mode Attribute macros */
> #define __LWMI_ATTR_RO(_func, _name) \
> { \
> @@ -875,12 +951,14 @@ static void lwmi_om_fw_attr_add(struct lwmi_om_priv *priv)
> }
>
> for (i = 0; i < ARRAY_SIZE(cd01_attr_groups) - 1; i++) {
> + cd01_attr_groups[i].tunable_attr->dev = &priv->wdev->dev;
> + if (!lwmi_attr_01_is_supported(cd01_attr_groups[i].tunable_attr))
> + continue;
> +
> err = 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 = &priv->wdev->dev;
> }
> return;
>
>
--
i.
^ permalink raw reply [flat|nested] 15+ messages in thread