mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Mark Pearson" <mpearson-lenovo@squebb.ca>
To: "Rong Zhang" <i@rong.moe>,
	"Derek J . Clark" <derekjohn.clark@gmail.com>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	"Alok Tiwari" <alok.a.tiwari@oracle.com>,
	"Armin Wolf" <W_Armin@gmx.de>
Cc: "platform-driver-x86@vger.kernel.org"
	<platform-driver-x86@vger.kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/5] platform/x86: lenovo-wmi-other: Retrieve private data from firmware_attributes device
Date: Wed, 18 Nov 2026 17:19:14 -0500	[thread overview]
Message-ID: <57a8122f-f0c7-4844-ab21-be2c81272c3e@app.fastmail.com> (raw)
In-Reply-To: <20261119-lwmi-no-singleton-v1-1-6b06fcfb5126@rong.moe>

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@rong.moe>
> ---
>  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@squebb.ca>
Mark

  reply	other threads:[~2026-11-18 22:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 18:58 [PATCH 0/5] platform/x86: lenovo-wmi-other: Refine firmware_attributes interface Rong Zhang
2026-11-18 18:58 ` [PATCH 1/5] platform/x86: lenovo-wmi-other: Retrieve private data from firmware_attributes device Rong Zhang
2026-11-18 22:19   ` Mark Pearson [this message]
2026-11-18 18:58 ` [PATCH 2/5] platform/x86: lenovo-wmi-other: Eliminate attribute-specific callbacks Rong Zhang
2026-11-18 22:17   ` Mark Pearson
2026-11-18 18:58 ` [PATCH 3/5] platform/x86: lenovo-wmi-other: Factor out tunable_attr_01 definition into a macro Rong Zhang
2026-11-18 22:19   ` Mark Pearson
2026-11-18 18:58 ` [PATCH 4/5] platform/x86: lenovo-wmi-other: Properly implement no_singleton driver Rong Zhang
2026-11-18 22:27   ` Mark Pearson
2026-11-18 18:58 ` [PATCH 5/5] platform/x86: lenovo-wmi-other: Hide unsupported attributes using is_visible() callback Rong Zhang
2026-11-18 22:23   ` Mark Pearson
2026-11-18 22:19 ` [PATCH 0/5] platform/x86: lenovo-wmi-other: Refine firmware_attributes interface Mark Pearson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57a8122f-f0c7-4844-ab21-be2c81272c3e@app.fastmail.com \
    --to=mpearson-lenovo@squebb.ca \
    --cc=W_Armin@gmx.de \
    --cc=alok.a.tiwari@oracle.com \
    --cc=derekjohn.clark@gmail.com \
    --cc=hansg@kernel.org \
    --cc=i@rong.moe \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®