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 4/5] platform/x86: lenovo-wmi-other: Properly implement no_singleton driver
Date: Mon, 23 Nov 2026 11:42:18 -0500	[thread overview]
Message-ID: <ac95c8c7-287b-4e06-b1d8-bd15f5842c06@app.fastmail.com> (raw)
In-Reply-To: <5b82091b356a4134ba59e032bd927049b3a6451a.camel@rong.moe>


On Thu, Nov 19, 2026, at 1:23 PM, Rong Zhang wrote:
> Hi Mark,
>
> Thanks for reviewing this.
>
> On Wed, 2026-11-18 at 17:27 -0500, Mark Pearson wrote:
>> 
>> On Wed, Nov 18, 2026, at 1:58 PM, Rong Zhang wrote:
>> > The driver declares `.no_singleton = true' but stores device-specific
>> > data to statically allocated tunable_attr_01 variables. This makes the
>> > driver depend on the frigile fact that no device in wild has more than
>> 
>> Minor typo - frigile/fragile
>
> Whoops, I constantly type this word in the wrong way. Sigh...
>
>> 
>> > one LENOVO_OTHER_MODE WMI devices.
>> > 
>> 
>> As an aside - is this really fragile? I mean realistically it's never going to happen is it?
>
> I wrote the commit message like this because depending on global states
> violates the requirements of a no_singleton driver anyway. I will
> rephrase it to make it focus on constifying tunable_attr_01 instead.
>
>> 
>> > Add unique indexes to all statically allocated tunable_attr_01 variables
>> > with some __COUNTER__ tricks, and use them to access lwmi_om_priv's
>> > newly-introduced tunable_attr_01_ctx array. In this manner, move all
>> > device-specific data to the tunable_attr_01_ctx array, and constify all
>> > statically allocated tunable_attr_01 variables to make the driver a
>> > truly no_singleton driver.
>
> If the __COUNTER__ tricks are a bit hard for you to keep up with, let me
> explain below:
>
>> > 
>> > Fixes: 03bb5147da08 ("platform/x86: lenovo-wmi-other: Limit adding 
>> > attributes to supported devices")
>> > Signed-off-by: Rong Zhang <i@rong.moe>
>> > ---
>> >  drivers/platform/x86/lenovo/wmi-other.c | 54 
>> > ++++++++++++++++++++++++---------
>> >  1 file changed, 39 insertions(+), 15 deletions(-)
>> > 
>> > diff --git a/drivers/platform/x86/lenovo/wmi-other.c 
>> > b/drivers/platform/x86/lenovo/wmi-other.c
>> > index 252ef775f300..f37dca7db034 100644
>> > --- a/drivers/platform/x86/lenovo/wmi-other.c
>> > +++ b/drivers/platform/x86/lenovo/wmi-other.c
>> > @@ -134,15 +134,23 @@ struct tunable_attr_01 {
>> >  	u8 feature_id;
>> >  	u8 device_id;
>> >  	u8 type_id;
>> > +	u8 ctx_id; /* Index to tunable_attr_01_ctx[] */
>> > +};
>> > +
>> > +struct tunable_attr_01_ctx {
>> >  	u8 cd_mode_id; /* mode arg for searching capdata */
>> >  	u8 cv_mode_id; /* mode arg for set/get current_value */
>> >  };
>> > 
>> > +enum { TUNABLE_ATTR_01_COUNTER_BASE = __COUNTER__ + 1 };
>
> __COUNTER__ is like counter++ in C, but for C preprocessor.
>
> This uses an enumeration to retrieve its value (say, 403). Once
> retrieved, __COUNTER__ is self-incremented, so the retrieved value plus
> one equals the "current" value.
>
>    TUNABLE_ATTR_01_COUNTER_BASE = (counter++) + 1 = 403 + 1 = 404
>
>> > +#define TUNABLE_ATTR_01_COUNTER (__COUNTER__ - TUNABLE_ATTR_01_COUNTER_BASE)
>
> Defining a macro does not consume the __COUNTER__. The "current" value
> remains unchanged. That's why enumeration is used above and below.
>
>> > +
>> >  #define DEFINE_TUNABLE_ATTR_01(_name, _device, _feature, _type)	\
>> > -	static struct tunable_attr_01 _name = {			\
>> > +	static const struct tunable_attr_01 _name = {		\
>> >  		.device_id = LWMI_DEVICE_ID_##_device,		\
>> >  		.feature_id = LWMI_FEATURE_ID_##_feature,	\
>> >  		.type_id = LWMI_TYPE_ID_##_type,		\
>> > +		.ctx_id = TUNABLE_ATTR_01_COUNTER,		\
>
> This does not consume the __COUNTER__, too.
>
>> >  	}
>> > 
>> >  DEFINE_TUNABLE_ATTR_01(ppt_pl1_spl, CPU, CPU_SPL, NONE);
>
> Here it's consumed!
>
>    ppt_pl1_spl.ctx_id      = (counter++) - 404 = 404 - 404 = 0
>    ppt_pl1_spl_cl.ctx_id   = (counter++) - 404 = 405 - 404 = 1
>
> ...and so on.
>
>> > @@ -168,6 +176,10 @@ DEFINE_TUNABLE_ATTR_01(dgpu_didvid, GPU, 
>> > DGPU_DIDVID, NONE);
>> >  DEFINE_TUNABLE_ATTR_01(gpu_nv_bpl, GPU, GPU_NV_BPL, NONE);
>> >  DEFINE_TUNABLE_ATTR_01(gpu_nv_cpu_boost, GPU, GPU_NV_CPU_BOOST, NONE);
>
>    gpu_nv_cpu_boost.ctx_id = (counter++) - 404 = 425 - 404 = 21
>
>> > 
>> > +enum { TUNABLE_ATTR_01_NR = TUNABLE_ATTR_01_COUNTER };
>
>    TUNABLE_ATTR_01_NR      = (counter++) - 404 = 426 - 404 = 22
>
> That's it! In this manner, the C preprocessor stores self-increment ids
> to all tunable_attr_01 variables, so that the latter can be constified
> during compilation.
>
> For your minor note in PATCH 3, I will fix the order when I resubmit the
> series. I will wait for Derek's review before the resubmission.
>
> Thanks,
> Rong
>

Thanks for the more detailed explanation :)
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>

Mark

  parent reply	other threads:[~2026-11-23 16:42 UTC|newest]

Thread overview: 15+ 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
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-19 18:23     ` Rong Zhang
2026-11-19 18:43       ` Derek J. Clark
2026-11-23 16:42       ` Mark Pearson [this message]
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=ac95c8c7-287b-4e06-b1d8-bd15f5842c06@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®