drivers/hwmon/adm9240: fix data race in adm9240_fan_read
PATCH 1/1 drivers/hwmon/adm9240: fix data race in adm9240_fan_read
Inadm9240_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.
--- drivers/hwmon/adm9240.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/hwmon/adm9240.c +2 -0
@@ -501,6 +501,7 @@ static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *valswitch (attr) {case hwmon_fan_input: +mutex_lock (&data->update_lock); err =regmap_read (data->regmap,ADM9240_REG_FAN (channel), ®val);if (err <0 )return err;
@@ -511,6 +512,7 @@ static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *valif (err)return err; } +mutex_unlock (&data->update_lock); *val =FAN_FROM_REG (regval,BIT (data->fan_div[channel]));break ;case hwmon_fan_div:
Signature · 1 line
2.25.1
Guenter Roeck
maintainerQuoted 19 lines · Li Zhong
In
adm9240_read()
adm9240_fan_read()adm9240_write_fan_div(),it assumes that the caller of
adm9240_write_fan_div()must holddata->update_lock. Otherwise, it may cause data races when data is updated by other threads.Signed-off-by Li Zhong <[email protected]>--- drivers/hwmon/adm9240.c | 2 ++ 1 file changed, 2 insertions(+)drivers/hwmon/adm9240.c +0
-0
drivers/hwmon/adm9240.c static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *val · line 507
Quoted 7 lines
drivers/hwmon/adm9240.c +1
-0@@ -501,6 +501,7 @@ static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *valswitch (attr) {case hwmon_fan_input: +mutex_lock (&data->update_lock); err =regmap_read (data->regmap,ADM9240_REG_FAN (channel), ®val);if (err <0 )return err;
The mutex needs to be released here.
Quoted 8 lines
drivers/hwmon/adm9240.c +1
-0@@ -511,6 +512,7 @@ static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *valif (err)return err; } +mutex_unlock (&data->update_lock); *val =FAN_FROM_REG (regval,BIT (data->fan_div[channel]));break ;case hwmon_fan_div:
Quoted 31 lines · Guenter Roeck
Quoted 19 lines · Li Zhong
In
adm9240_read()
adm9240_fan_read()adm9240_write_fan_div(),it assumes that the caller of
adm9240_write_fan_div()must holddata->update_lock. Otherwise, it may cause data races when data is updated by other threads.Signed-off-by Li Zhong <[email protected]>--- drivers/hwmon/adm9240.c | 2 ++ 1 file changed, 2 insertions(+)drivers/hwmon/adm9240.c +0
-0drivers/hwmon/adm9240.c static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *val · line 507
Quoted 7 lines
drivers/hwmon/adm9240.c +1
-0@@ -501,6 +501,7 @@ static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *valswitch (attr) {case hwmon_fan_input: +mutex_lock (&data->update_lock); err =regmap_read (data->regmap,ADM9240_REG_FAN (channel), ®val);if (err <0 )return err;The mutex needs to be released here.
Quoted 9 lines
drivers/hwmon/adm9240.c static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *val · line 518
Quoted 8 lines
drivers/hwmon/adm9240.c +1
-0@@ -511,6 +512,7 @@ static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *valif (err)return err; } +mutex_unlock (&data->update_lock); *val =FAN_FROM_REG (regval,BIT (data->fan_div[channel]));break ;case hwmon_fan_div:
Thanks. Fixed in v2 patch.
Guenter Roeck
maintainerQuoted 27 lines · Li Zhong
In
adm9240_read()
adm9240_fan_read()adm9240_write_fan_div(),it assumes that the caller of
adm9240_write_fan_div()must holddata->update_lock. Otherwise, it may cause data races when data is updated by other threads.Signed-off-by Li Zhong <[email protected]>--- drivers/hwmon/adm9240.c | 2 ++ 1 file changed, 2 insertions(+)drivers/hwmon/adm9240.c +1
-0@@ -501,6 +501,7 @@ static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *valswitch (attr) {case hwmon_fan_input: +mutex_lock (&data->update_lock); err =regmap_read (data->regmap,ADM9240_REG_FAN (channel), ®val);if (err <0 )return err;
drivers/hwmon/adm9240.c static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *val · line 513
Quoted 2 lines
drivers/hwmon/adm9240.c +0
-0@@ -511,6 +512,7 @@ static int adm9240_fan_read(struct device *dev, u32 attr, int channel, long *valif (err)return err;
The mutex also needs to be released here (in the error handling path).
Quoted 5 lines
drivers/hwmon/adm9240.c +1
-0} +mutex_unlock (&data->update_lock); *val =FAN_FROM_REG (regval,BIT (data->fan_div[channel]));break ;case hwmon_fan_div: