linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hwmon: pmbus: protect read-modify-write with lock
@ 2019-05-28  9:08 Adamski, Krzysztof (Nokia - PL/Wroclaw)
  2019-06-07 22:32 ` Wolfram Sang
  0 siblings, 1 reply; 4+ messages in thread
From: Adamski, Krzysztof (Nokia - PL/Wroclaw) @ 2019-05-28  9:08 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org

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.

Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
---
 drivers/hwmon/pmbus/pmbus_core.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index ef7ee90ee785..94adbede7912 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -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);
 
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-06-10  7:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-28  9:08 [PATCH] hwmon: pmbus: protect read-modify-write with lock Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-06-07 22:32 ` Wolfram Sang
2019-06-10  6:36   ` Adamski, Krzysztof (Nokia - PL/Wroclaw)
2019-06-10  7:04     ` Wolfram Sang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).