* [PATCH v3] drivers/hwmon/adm9240: fix data race in adm9240_fan_read
@ 2022-09-24 0:17 Li Zhong
2022-09-24 14:33 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Li Zhong @ 2022-09-24 0:17 UTC (permalink / raw)
To: linux-hwmon; +Cc: linux, jdelvare, Li Zhong
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>
---
drivers/hwmon/adm9240.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/adm9240.c b/drivers/hwmon/adm9240.c
index 483cd757abd3..40e3558d3709 100644
--- a/drivers/hwmon/adm9240.c
+++ b/drivers/hwmon/adm9240.c
@@ -501,17 +501,23 @@ static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *val
switch (attr) {
case hwmon_fan_input:
+ mutex_lock(&data->update_lock);
err = regmap_read(data->regmap, ADM9240_REG_FAN(channel), ®val);
- if (err < 0)
+ if (err < 0) {
+ mutex_unlock(&data->update_lock);
return err;
+ }
if (regval == 255 && data->fan_div[channel] < 3) {
/* adjust fan clock divider on overflow */
err = adm9240_write_fan_div(data, channel,
++data->fan_div[channel]);
- if (err)
+ if (err) {
+ mutex_unlock(&data->update_lock);
return err;
+ }
}
*val = FAN_FROM_REG(regval, BIT(data->fan_div[channel]));
+ mutex_unlock(&data->update_lock);
break;
case hwmon_fan_div:
*val = BIT(data->fan_div[channel]);
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] drivers/hwmon/adm9240: fix data race in adm9240_fan_read
2022-09-24 0:17 [PATCH v3] drivers/hwmon/adm9240: fix data race in adm9240_fan_read Li Zhong
@ 2022-09-24 14:33 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2022-09-24 14:33 UTC (permalink / raw)
To: Li Zhong; +Cc: linux-hwmon, jdelvare
On Fri, Sep 23, 2022 at 05:17:51PM -0700, Li Zhong wrote:
> 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>
Applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-24 14:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-24 0:17 [PATCH v3] drivers/hwmon/adm9240: fix data race in adm9240_fan_read Li Zhong
2022-09-24 14:33 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox