Skip to contentSkip to conversation

platform/x86: lenovo-wmi-other: fix uninitialized variable in lenovo wmi-other driver

PATCH Superseded Yufei CHENG 2 participants 3 messages Apr 26

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86: lenovo-wmi-other: fix uninitialized variable in lenovo wmi-other driver

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
---
 drivers/platform/x86/lenovo/wmi-other.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/platform/x86/lenovo/wmi-other.c +2 -0
index 6040f45aa..6c2febe1a 100644
@@ -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)
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Yufei,

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

Quoted 9 lines · 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

Please run scripts/checkpatch.pl before submitting patches.

Quoted 10 lines
---
 drivers/platform/x86/lenovo/wmi-other.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/platform/x86/lenovo/wmi-other.c +0 -0
index 6040f45aa..6c2febe1a 100644

drivers/platform/x86/lenovo/wmi-other.c static int lwmi_om_hwmon_write(struct device *dev, enum hwmon_sensor_types type, · line 353

Quoted 5 lines
drivers/platform/x86/lenovo/wmi-other.c +2 -0
@@ -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:

Thanks,
Rong

Quoted 3 lines
drivers/platform/x86/lenovo/wmi-other.c +0 -0
 			err = lwmi_om_fan_get_set(priv, channel, &raw, true);
 			if (err)
author
#2 lore raw

Hi Rong,

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

Thanks,
Yufei

Quoted 47 lines · Rong Zhang

Hi Yufei,

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

Quoted 9 lines · 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

Please run scripts/checkpatch.pl before submitting patches.

Quoted 10 lines
---
 drivers/platform/x86/lenovo/wmi-other.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/platform/x86/lenovo/wmi-other.c +0 -0
index 6040f45aa..6c2febe1a 100644

drivers/platform/x86/lenovo/wmi-other.c static int lwmi_om_hwmon_write(struct device *dev, enum hwmon_sensor_types type, · line 353

Quoted 5 lines
drivers/platform/x86/lenovo/wmi-other.c +2 -0
@@ -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:

Thanks,
Rong

Quoted 3 lines
drivers/platform/x86/lenovo/wmi-other.c +0 -0
                      err = lwmi_om_fan_get_set(priv, channel, &raw, true);
                      if (err)