hwmon: (adm9240) fix data race in adm9240_fan_read
In adm9240_read() adm9240_fan_read() adm9240_write_fan_div(), it assumes that the caller of adm9240_write_fan_div() must hold data->update_lock. Otherwise, it may cause data races when data is updated by other threads. Signed-off-by: Li Zhong <floridsleeves@gmail.com> Link: https://lore.kernel.org/r/20220924001751.1726369-1-floridsleeves@gmail.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
parent
f9c0cf8f26
commit
8887516f01
|
@ -501,17 +501,23 @@ static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *val
|
||||||
|
|
||||||
switch (attr) {
|
switch (attr) {
|
||||||
case hwmon_fan_input:
|
case hwmon_fan_input:
|
||||||
|
mutex_lock(&data->update_lock);
|
||||||
err = regmap_read(data->regmap, ADM9240_REG_FAN(channel), ®val);
|
err = regmap_read(data->regmap, ADM9240_REG_FAN(channel), ®val);
|
||||||
if (err < 0)
|
if (err < 0) {
|
||||||
|
mutex_unlock(&data->update_lock);
|
||||||
return err;
|
return err;
|
||||||
|
}
|
||||||
if (regval == 255 && data->fan_div[channel] < 3) {
|
if (regval == 255 && data->fan_div[channel] < 3) {
|
||||||
/* adjust fan clock divider on overflow */
|
/* adjust fan clock divider on overflow */
|
||||||
err = adm9240_write_fan_div(data, channel,
|
err = adm9240_write_fan_div(data, channel,
|
||||||
++data->fan_div[channel]);
|
++data->fan_div[channel]);
|
||||||
if (err)
|
if (err) {
|
||||||
|
mutex_unlock(&data->update_lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
*val = FAN_FROM_REG(regval, BIT(data->fan_div[channel]));
|
*val = FAN_FROM_REG(regval, BIT(data->fan_div[channel]));
|
||||||
|
mutex_unlock(&data->update_lock);
|
||||||
break;
|
break;
|
||||||
case hwmon_fan_div:
|
case hwmon_fan_div:
|
||||||
*val = BIT(data->fan_div[channel]);
|
*val = BIT(data->fan_div[channel]);
|
||||||
|
|
Loading…
Reference in New Issue