Commit 38463721 authored by Adamski, Krzysztof (Nokia - PL/Wroclaw)'s avatar Adamski, Krzysztof (Nokia - PL/Wroclaw) Committed by Guenter Roeck

hwmon: (pmbus/core) mutex_lock write in pmbus_set_samples

update_lock is a mutex intended to protect write operations. It was not
taken, however, when _pmbus_write_word_data is called from
pmbus_set_samples() function which may cause problems especially when
some PMBUS_VIRT_* operation is implemented as a read-modify-write cycle.

This patch makes sure the lock is held during the operation.

Fixes: 49c4455d ("hwmon: (pmbus) Introduce PMBUS_VIRT_*_SAMPLES registers")
Signed-off-by: default avatarKrzysztof Adamski <krzysztof.adamski@nokia.com>
Reviewed-by: default avatarAlexander Sverdlin <alexander.sverdlin@nokia.com>
[groeck: Declared and initialized missing 'data' variable]
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent c41dd48e
...@@ -1942,11 +1942,14 @@ static ssize_t pmbus_set_samples(struct device *dev, ...@@ -1942,11 +1942,14 @@ static ssize_t pmbus_set_samples(struct device *dev,
long val; long val;
struct i2c_client *client = to_i2c_client(dev->parent); struct i2c_client *client = to_i2c_client(dev->parent);
struct pmbus_samples_reg *reg = to_samples_reg(devattr); struct pmbus_samples_reg *reg = to_samples_reg(devattr);
struct pmbus_data *data = i2c_get_clientdata(client);
if (kstrtol(buf, 0, &val) < 0) if (kstrtol(buf, 0, &val) < 0)
return -EINVAL; return -EINVAL;
mutex_lock(&data->update_lock);
ret = _pmbus_write_word_data(client, reg->page, reg->attr->reg, val); ret = _pmbus_write_word_data(client, reg->page, reg->attr->reg, val);
mutex_unlock(&data->update_lock);
return ret ? : count; return ret ? : count;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment