diff options
| author | Guenter Roeck <linux@roeck-us.net> | 2026-08-21 07:49:15 -0700 |
|---|---|---|
| committer | Guenter Roeck <linux@roeck-us.net> | 2026-08-30 14:40:47 -0700 |
| commit | cf7865ca31bf75c35f53f3a03b2fb4e89c3d78a2 (patch) | |
| tree | be6277af053aa615c74971bcfcc6787c096be5a2 /drivers | |
| parent | 59c212ba59b2a3e85bd3327e1db6b9fbf114353d (diff) | |
| download | linux-next-cf7865ca31bf75c35f53f3a03b2fb4e89c3d78a2.tar.gz linux-next-cf7865ca31bf75c35f53f3a03b2fb4e89c3d78a2.zip | |
hwmon: (sht4x) Add missing locks
Sashiko reports:
Heater sysfs callbacks (heater_enable_store, heater_power_store, and
heater_time_store) are exposed to data races without the hwmon lock.
If a user-space process reads hwmon data while another process enables
the heater, heater_enable_store() executes without holding
hwmon_lock(dev). This can interleave I2C commands and mutate shared
state (data->heating_complete and data->data_pending) concurrently
with sht4x_read_values(), leading to corrupted I2C sequences.
Fixes: 53dfa12299c1 ("hwmon: (sht4x) Rely on subsystem locking")
Cc: Alessandro Zini <alessandro.zini@siemens.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Link: https://patch.msgid.link/20260821144916.2889031-1-linux@roeck-us.net
Diffstat (limited to 'drivers')
| -rw-r--r-- | drivers/hwmon/sht4x.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/hwmon/sht4x.c b/drivers/hwmon/sht4x.c index 9cace0e8acda..7a0dc2ed723d 100644 --- a/drivers/hwmon/sht4x.c +++ b/drivers/hwmon/sht4x.c @@ -277,6 +277,8 @@ static ssize_t heater_enable_store(struct device *dev, heating_time_bound = 1100; } + guard(hwmon_lock)(dev); + if (time_before(jiffies, data->heating_complete)) return -EBUSY; @@ -314,6 +316,8 @@ static ssize_t heater_power_store(struct device *dev, if (power != 20 && power != 110 && power != 200) return -EINVAL; + guard(hwmon_lock)(dev); + data->heater_power = power; return count; @@ -344,6 +348,8 @@ static ssize_t heater_time_store(struct device *dev, if (time != 100 && time != 1000) return -EINVAL; + guard(hwmon_lock)(dev); + data->heater_time = time; return count; |
