hwmon: pmbus: protect read-modify-write with lock
PATCH 1/1 hwmon: pmbus: protect read-modify-write with lock
The operation done in the pmbus_update_fan() function is a read-modify-write operation but it lacks any kind of lock protection which may cause problems if run more than once simultaneously. This patch uses an existing update_lock mutex to fix this problem.
---
I'm resending this patch to proper recipients this time. Sorry if the previous submission confused anybody.
drivers/hwmon/pmbus/pmbus_core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/hwmon/pmbus/pmbus_core.c +8 -3
@@ -268,6 +268,7 @@ int pmbus_update_fan(struct i2c_client *client, int page, int id,int rv;u8 to; +mutex_lock (&data->update_lock); from =pmbus_read_byte_data (client, page, pmbus_fan_config_registers[id]);if (from <0 )
@@ -278,11 +279,15 @@ int pmbus_update_fan(struct i2c_client *client, int page, int id, rv =pmbus_write_byte_data (client, page, pmbus_fan_config_registers[id], to);if (rv <0 ) -return rv; + goto out; } -return _pmbus_write_word_data (client, page, - pmbus_fan_command_registers[id], command); + rv =_pmbus_write_word_data (client, page, + pmbus_fan_command_registers[id], command); + +out: +mutex_lock (&data->update_lock); +return rv; }EXPORT_SYMBOL_GPL (pmbus_update_fan);
Signature · 1 line
2.20.1
Hi!
Quoted 31 lines · Krzysztof (Nokia - PL/Wroclaw)
The operation done in the
pmbus_update_fan()function is a read-modify-write operation but it lacks any kind of lock protection which may cause problems if run more than once simultaneously. This patch uses an existingupdate_lockmutex to fix this problem.Signed-off-by Krzysztof Adamski <[email protected]>---
I'm resending this patch to proper recipients this time. Sorry if the previous submission confused anybody.
drivers/hwmon/pmbus/pmbus_core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/hwmon/pmbus/pmbus_core.c +1
-1@@ -268,6 +268,7 @@ int pmbus_update_fan(struct i2c_client *client, int page, int id,int rv;u8 to; +mutex_lock (&data->update_lock); from =pmbus_read_byte_data (client, page, pmbus_fan_config_registers[id]);if (from <0 )@@ -278,11 +279,15 @@ int pmbus_update_fan(struct i2c_client *client, int page, int id, rv =pmbus_write_byte_data (client, page, pmbus_fan_config_registers[id], to);if (rv <0 ) -return rv;
drivers/hwmon/pmbus/pmbus_core.c int pmbus_update_fan(struct i2c_client *client, int page, int id, · line 289
Quoted 10 lines
drivers/hwmon/pmbus/pmbus_core.c +6
-2+ goto out; } -return _pmbus_write_word_data (client, page, - pmbus_fan_command_registers[id], command); + rv =_pmbus_write_word_data (client, page, + pmbus_fan_command_registers[id], command); + +out: +mutex_lock (&data->update_lock);
This has to be mutex_unlock()...
Quoted 3 lines
drivers/hwmon/pmbus/pmbus_core.c +1
-0+return rv; }EXPORT_SYMBOL_GPL (pmbus_update_fan);
Signature · 2 lines
Best regards, Alexander Sverdlin.
Guenter Roeck
maintainerQuoted 37 lines · Alexander (Nokia - DE/Ulm)
Hi!
Quoted 34 lines · Krzysztof (Nokia - PL/Wroclaw)
The operation done in the
pmbus_update_fan()function is a read-modify-write operation but it lacks any kind of lock protection which may cause problems if run more than once simultaneously. This patch uses an existingupdate_lockmutex to fix this problem.Signed-off-by Krzysztof Adamski <[email protected]>---
I'm resending this patch to proper recipients this time. Sorry if the previous submission confused anybody.
drivers/hwmon/pmbus/pmbus_core.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)drivers/hwmon/pmbus/pmbus_core.c +2
-1@@ -268,6 +268,7 @@ int pmbus_update_fan(struct i2c_client *client, int page, int id,int rv;u8 to; +mutex_lock (&data->update_lock); from =pmbus_read_byte_data (client, page, pmbus_fan_config_registers[id]);if (from <0 )@@ -278,11 +279,15 @@ int pmbus_update_fan(struct i2c_client *client, int page, int id, rv =pmbus_write_byte_data (client, page, pmbus_fan_config_registers[id], to);if (rv <0 ) -return rv; + goto out; }
Quoted 10 lines
drivers/hwmon/pmbus/pmbus_core.c int pmbus_update_fan(struct i2c_client *client, int page, int id, · line 289
Quoted 7 lines
drivers/hwmon/pmbus/pmbus_core.c +5
-2-return _pmbus_write_word_data (client, page, - pmbus_fan_command_registers[id], command); + rv =_pmbus_write_word_data (client, page, + pmbus_fan_command_registers[id], command); + +out: +mutex_lock (&data->update_lock);This has to be
mutex_unlock()...
Not only that - it is also recursive.
Guenter