Re: [PATCH v2] platform/x86: lenovo: wmi-other: Fix uninitialized variable in lwmi_om_hwmon_write()
From: Rong Zhang
Date: Sun Apr 26 2026 - 12:09:17 EST
Hi Yufei,
On Sun, 2026-04-26 at 22:59 +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
You didn't run scripts/checkpatch.pl before submitting patches, as I've
reminded in the previous reply to v1.
Had you run it, you would see:
WARNING: Please use correct Fixes: style 'Fixes: <12+ chars of sha1>
("<title line>")' - ie: 'Fixes: 51ed34282f63 ("platform/x86: lenovo-wmi-
other: Add HWMON for fan reporting/tuning")'
> Signed-off-by: Yufei CHENG <cd345al@xxxxxxxxx>
My Reviewed-by was dropped. You should've included it in v2.
Please read https://docs.kernel.org/process/submitting-patches.html
Thanks,
Rong
> ---
> v2: rewrite the commit title to be more specific
>
> 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)