Commit 920057ad authored by Zev Weiss's avatar Zev Weiss Committed by Guenter Roeck

hwmon: (nct6775) Fix incorrect variable reuse in fan_div calculation

In the regmap conversion in commit 4ef27745 ("hwmon: (nct6775)
Convert register access to regmap API") I reused the 'reg' variable
for all three register reads in the fan speed calculation loop in
nct6775_update_device(), but failed to notice that the value from the
first one (data->REG_FAN[i]) is actually used in the call to
nct6775_select_fan_div() at the end of the loop body.  Since that
patch the register value passed to nct6775_select_fan_div() has been
(conditionally) incorrectly clobbered with the value of a different
register than intended, which has in at least some cases resulted in
fan speeds being adjusted down to zero.

Fix this by using dedicated temporaries for the two intermediate
register reads instead of 'reg'.
Signed-off-by: default avatarZev Weiss <zev@bewilderbeest.net>
Fixes: 4ef27745 ("hwmon: (nct6775) Convert register access to regmap API")
Reported-by: default avatarThomas Zajic <zlatko@gmx.at>
Tested-by: default avatarThomas Zajic <zlatko@gmx.at>
Cc: stable@vger.kernel.org # v5.19+
Link: https://lore.kernel.org/r/20230929200822.964-2-zev@bewilderbeest.netSigned-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent bbfff736
......@@ -1614,17 +1614,21 @@ struct nct6775_data *nct6775_update_device(struct device *dev)
data->fan_div[i]);
if (data->has_fan_min & BIT(i)) {
err = nct6775_read_value(data, data->REG_FAN_MIN[i], &reg);
u16 tmp;
err = nct6775_read_value(data, data->REG_FAN_MIN[i], &tmp);
if (err)
goto out;
data->fan_min[i] = reg;
data->fan_min[i] = tmp;
}
if (data->REG_FAN_PULSES[i]) {
err = nct6775_read_value(data, data->REG_FAN_PULSES[i], &reg);
u16 tmp;
err = nct6775_read_value(data, data->REG_FAN_PULSES[i], &tmp);
if (err)
goto out;
data->fan_pulses[i] = (reg >> data->FAN_PULSE_SHIFT[i]) & 0x03;
data->fan_pulses[i] = (tmp >> data->FAN_PULSE_SHIFT[i]) & 0x03;
}
err = nct6775_select_fan_div(dev, data, i, reg);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment