public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] platform/x86: lenovo-wmi-other: fix uninitialized variable in lenovo wmi-other driver
@ 2026-04-26 10:27 Yufei CHENG
  2026-04-26 12:45 ` Rong Zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Yufei CHENG @ 2026-04-26 10:27 UTC (permalink / raw)
  To: mpearson-lenovo, derekjohn.clark
  Cc: hansg, ilpo.jarvinen, platform-driver-x86, linux-kernel,
	Yufei CHENG

When the flag relax_fan_constraint is set, local variable 'raw'
is never assigned, and lwmi_om_hwmon_write() will pass uninitialized
value to lwmi_om_fan_get_set() resulting in undefined behavior.

This flag allows user to bypass minimum fan RPM divisor rounding,
but assignment to 'raw' only happens in the non-relaxed path.
Fix by defaulting 'raw' to user provided 'val' in the else branch.

Fixes: 51ed34282f63fab5b3996477cc56135eb4de5284
Signed-off-by: Yufei CHENG <cd345al@gmail.com>
---
 drivers/platform/x86/lenovo/wmi-other.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
index 6040f45aa..6c2febe1a 100644
--- a/drivers/platform/x86/lenovo/wmi-other.c
+++ b/drivers/platform/x86/lenovo/wmi-other.c
@@ -349,6 +349,8 @@ static int lwmi_om_hwmon_write(struct device *dev, enum hwmon_sensor_types type,
 			 */
 			if (!relax_fan_constraint)
 				raw = val / LWMI_FAN_DIV * LWMI_FAN_DIV;
+			else
+				raw = val;
 
 			err = lwmi_om_fan_get_set(priv, channel, &raw, true);
 			if (err)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] platform/x86: lenovo-wmi-other: fix uninitialized variable in lenovo wmi-other driver
  2026-04-26 10:27 [PATCH] platform/x86: lenovo-wmi-other: fix uninitialized variable in lenovo wmi-other driver Yufei CHENG
@ 2026-04-26 12:45 ` Rong Zhang
  2026-04-26 15:10   ` no name
  0 siblings, 1 reply; 3+ messages in thread
From: Rong Zhang @ 2026-04-26 12:45 UTC (permalink / raw)
  To: Yufei CHENG, mpearson-lenovo, derekjohn.clark
  Cc: hansg, ilpo.jarvinen, platform-driver-x86, linux-kernel

Hi Yufei,

The title is too verbose. No need to mention the driver's name twice.

On Sun, 2026-04-26 at 18:27 +0800, Yufei CHENG wrote:
> When the flag relax_fan_constraint is set, local variable 'raw'
> is never assigned, and lwmi_om_hwmon_write() will pass uninitialized
> value to lwmi_om_fan_get_set() resulting in undefined behavior.
> 
> This flag allows user to bypass minimum fan RPM divisor rounding,
> but assignment to 'raw' only happens in the non-relaxed path.
> Fix by defaulting 'raw' to user provided 'val' in the else branch.
> 
> Fixes: 51ed34282f63fab5b3996477cc56135eb4de5284

Please run scripts/checkpatch.pl before submitting patches.

> Signed-off-by: Yufei CHENG <cd345al@gmail.com>
> ---
>  drivers/platform/x86/lenovo/wmi-other.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
> index 6040f45aa..6c2febe1a 100644
> --- a/drivers/platform/x86/lenovo/wmi-other.c
> +++ b/drivers/platform/x86/lenovo/wmi-other.c
> @@ -349,6 +349,8 @@ static int lwmi_om_hwmon_write(struct device *dev, enum hwmon_sensor_types type,
>  			 */
>  			if (!relax_fan_constraint)
>  				raw = val / LWMI_FAN_DIV * LWMI_FAN_DIV;
> +			else
> +				raw = val;

What an embarrassing mistake! I missed that when I was adding the code
path for rounding down. Thanks for fixing it.

With formatting issues fixed:

Reviewed-by: Rong Zhang <i@rong.moe>

Thanks,
Rong

>  
>  			err = lwmi_om_fan_get_set(priv, channel, &raw, true);
>  			if (err)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] platform/x86: lenovo-wmi-other: fix uninitialized variable in lenovo wmi-other driver
  2026-04-26 12:45 ` Rong Zhang
@ 2026-04-26 15:10   ` no name
  0 siblings, 0 replies; 3+ messages in thread
From: no name @ 2026-04-26 15:10 UTC (permalink / raw)
  To: Rong Zhang, mpearson-lenovo, Derek John Clark
  Cc: hansg, ilpo.jarvinen, platform-driver-x86, linux-kernel

Hi Rong,

Thanks for your review, and I really appreciate your work.
I've rewritten the title and submitted the new patch.

Thanks,
Yufei


On Sun, Apr 26, 2026 at 8:50 PM Rong Zhang <i@rong.moe> wrote:
>
> Hi Yufei,
>
> The title is too verbose. No need to mention the driver's name twice.
>
> On Sun, 2026-04-26 at 18:27 +0800, Yufei CHENG wrote:
> > When the flag relax_fan_constraint is set, local variable 'raw'
> > is never assigned, and lwmi_om_hwmon_write() will pass uninitialized
> > value to lwmi_om_fan_get_set() resulting in undefined behavior.
> >
> > This flag allows user to bypass minimum fan RPM divisor rounding,
> > but assignment to 'raw' only happens in the non-relaxed path.
> > Fix by defaulting 'raw' to user provided 'val' in the else branch.
> >
> > Fixes: 51ed34282f63fab5b3996477cc56135eb4de5284
>
> Please run scripts/checkpatch.pl before submitting patches.
>
> > Signed-off-by: Yufei CHENG <cd345al@gmail.com>
> > ---
> >  drivers/platform/x86/lenovo/wmi-other.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/platform/x86/lenovo/wmi-other.c b/drivers/platform/x86/lenovo/wmi-other.c
> > index 6040f45aa..6c2febe1a 100644
> > --- a/drivers/platform/x86/lenovo/wmi-other.c
> > +++ b/drivers/platform/x86/lenovo/wmi-other.c
> > @@ -349,6 +349,8 @@ static int lwmi_om_hwmon_write(struct device *dev, enum hwmon_sensor_types type,
> >                        */
> >                       if (!relax_fan_constraint)
> >                               raw = val / LWMI_FAN_DIV * LWMI_FAN_DIV;
> > +                     else
> > +                             raw = val;
>
> What an embarrassing mistake! I missed that when I was adding the code
> path for rounding down. Thanks for fixing it.
>
> With formatting issues fixed:
>
> Reviewed-by: Rong Zhang <i@rong.moe>
>
> Thanks,
> Rong
>
> >
> >                       err = lwmi_om_fan_get_set(priv, channel, &raw, true);
> >                       if (err)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-26 15:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-26 10:27 [PATCH] platform/x86: lenovo-wmi-other: fix uninitialized variable in lenovo wmi-other driver Yufei CHENG
2026-04-26 12:45 ` Rong Zhang
2026-04-26 15:10   ` no name

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox