Re: [PATCH 1/5] platform/x86: lenovo-wmi-other: Retrieve private data from firmware_attributes device

From: Mark Pearson

Date: Wed Nov 18 2026 - 17:19:42 EST


On Wed, Nov 18, 2026, at 1:58 PM, Rong Zhang wrote:
> Currently, each tunable_attr_01 stores a pointer to the WMI device,
> which is unnecessary, as attributes' show/store callbacks can always
> access the firmware_attributes device through the kobject hierarchy.
> This also makes the driver fail to satisfy the requirements of a
> no_singleton driver.
>
> Store a pointer to the driver's privated data in the firmware_attributes
> device's drvdata, and retrieve it in attributes' show/store callbacks,
> so that we can get rid of tunable_attr_01.device and make it possible
> for upcoming refactoring to eliminate all wrapper callbacks created by
> macros and constify all statically allocated variables relevant to our
> firmware_attributes interface.
>
> Fixes: edc4b183b794 ("platform/x86: Add Lenovo Other Mode WMI Driver")
> Signed-off-by: Rong Zhang <i@xxxxxxxx>
> ---
> drivers/platform/x86/lenovo/wmi-other.c | 27 ++++++++++++++++-----------
> 1 file changed, 16 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/wmi-other.c
> b/drivers/platform/x86/lenovo/wmi-other.c
> index bd64e7b44669..c31a8bd08a85 100644
> --- a/drivers/platform/x86/lenovo/wmi-other.c
> +++ b/drivers/platform/x86/lenovo/wmi-other.c
> @@ -967,7 +967,6 @@ static void lwmi_om_psy_remove(struct lwmi_om_priv
> *priv)
> /* ======== fw_attributes (component: lenovo-wmi-capdata 01) ========
> */
>
> struct tunable_attr_01 {
> - struct device *dev;
> u8 feature_id;
> u8 device_id;
> u8 type_id;
> @@ -1124,6 +1123,11 @@ struct capdata01_attr_group {
> struct tunable_attr_01 *tunable_attr;
> };
>
> +static inline struct lwmi_om_priv *kobj_to_om_priv(const struct kobject *kobj)
> +{
> + return dev_get_drvdata(kobj_to_dev(kobj->parent));
> +}
> +
> /* Attribute Methods */
>
> /**
> @@ -1163,7 +1167,7 @@ static ssize_t attr_capdata01_show(struct kobject
> *kobj,
> struct tunable_attr_01 *tunable_attr,
> enum attribute_property prop)
> {
> - struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev);
> + struct lwmi_om_priv *priv = kobj_to_om_priv(kobj);
> struct capdata01 capdata;
> u32 attribute_id;
> int value, ret;
> @@ -1219,7 +1223,7 @@ static ssize_t attr_current_value_store(struct
> kobject *kobj,
> const char *buf, size_t count,
> struct tunable_attr_01 *tunable_attr)
> {
> - struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev);
> + struct lwmi_om_priv *priv = kobj_to_om_priv(kobj);
> struct wmi_method_args_32 args = {};
> struct capdata01 capdata;
> enum thermal_mode mode;
> @@ -1277,7 +1281,7 @@ static ssize_t attr_current_value_show(struct
> kobject *kobj,
> struct kobj_attribute *kattr, char *buf,
> struct tunable_attr_01 *tunable_attr)
> {
> - struct lwmi_om_priv *priv = dev_get_drvdata(tunable_attr->dev);
> + struct lwmi_om_priv *priv = kobj_to_om_priv(kobj);
> struct wmi_method_args_32 args = {};
> enum thermal_mode mode;
> int retval;
> @@ -1304,6 +1308,7 @@ static ssize_t attr_current_value_show(struct
> kobject *kobj,
>
> /**
> * lwmi_attr_01_is_supported() - Determine if the given attribute is
> supported.
> + * @priv: Driver private data
> * @tunable_attr: The attribute to verify.
> *
> * For an attribute to be supported it must have a functional get/set
> method,
> @@ -1324,10 +1329,10 @@ static ssize_t attr_current_value_show(struct
> kobject *kobj,
> *
> * Return: true if capdata and set/get modes are found, otherwise
> false.
> */
> -static bool lwmi_attr_01_is_supported(struct tunable_attr_01
> *tunable_attr)
> +static bool lwmi_attr_01_is_supported(struct lwmi_om_priv *priv,
> + 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;
> @@ -1350,8 +1355,7 @@ static bool lwmi_attr_01_is_supported(struct
> tunable_attr_01 *tunable_attr)
> if (!cd_mode_found)
> return cd_mode_found;
>
> - dev_dbg(tunable_attr->dev,
> - "cd_mode_id: %#010x\n", args.arg0);
> + dev_dbg(&priv->wdev->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++) {
> @@ -1371,7 +1375,7 @@ static bool lwmi_attr_01_is_supported(struct
> tunable_attr_01 *tunable_attr)
> if (!cv_mode_found)
> return cv_mode_found;
>
> - dev_dbg(tunable_attr->dev, "cv_mode_id: %#010x, attribute support
> level: %#010x\n",
> + dev_dbg(&priv->wdev->dev, "cv_mode_id: %#010x, attribute support
> level: %#010x\n",
> args.arg0, capdata.supported);
>
> return capdata.supported > 0;
> @@ -1558,9 +1562,10 @@ static void lwmi_om_fw_attr_add(struct
> lwmi_om_priv *priv)
> goto err_destroy_classdev;
> }
>
> + dev_set_drvdata(priv->fw_attr_dev, 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))
> + if (!lwmi_attr_01_is_supported(priv, cd01_attr_groups[i].tunable_attr))
> continue;
>
> err = sysfs_create_group(&priv->fw_attr_kset->kobj,
>
> --
> 2.55.0

Looks good to me
Reviewed-by: Mark Pearson <mpearson-lenovo@xxxxxxxxx>
Mark