]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hwmon: (pmbus/core) mutex_lock write in pmbus_set_samples
authorAdamski, Krzysztof (Nokia - PL/Wroclaw) <krzysztof.adamski@nokia.com>
Wed, 29 May 2019 14:33:52 +0000 (14:33 +0000)
committerGuenter Roeck <linux@roeck-us.net>
Thu, 6 Jun 2019 01:36:27 +0000 (18:36 -0700)
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: 49c4455dccf2 ("hwmon: (pmbus) Introduce PMBUS_VIRT_*_SAMPLES registers")
Signed-off-by: Krzysztof Adamski <krzysztof.adamski@nokia.com>
Reviewed-by: Alexander Sverdlin <alexander.sverdlin@nokia.com>
[groeck: Declared and initialized missing 'data' variable]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/pmbus/pmbus_core.c

index ef7ee90ee785d6a42088796a2dbe20f40848339f..48c2d5ae42a6f3bb7b9a3aa18b5a4d4035676dfd 100644 (file)
@@ -1942,11 +1942,14 @@ static ssize_t pmbus_set_samples(struct device *dev,
        long val;
        struct i2c_client *client = to_i2c_client(dev->parent);
        struct pmbus_samples_reg *reg = to_samples_reg(devattr);
+       struct pmbus_data *data = i2c_get_clientdata(client);
 
        if (kstrtol(buf, 0, &val) < 0)
                return -EINVAL;
 
+       mutex_lock(&data->update_lock);
        ret = _pmbus_write_word_data(client, reg->page, reg->attr->reg, val);
+       mutex_unlock(&data->update_lock);
 
        return ret ? : count;
 }