]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
hwmon: (sht4x) Rely on subsystem locking
authorGuenter Roeck <linux@roeck-us.net>
Sun, 7 Sep 2025 22:12:01 +0000 (15:12 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Fri, 17 Oct 2025 12:59:12 +0000 (05:59 -0700)
Attribute access is now serialized in the hardware monitoring core,
so locking in the driver code is no longer necessary. Drop it.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/sht4x.c

index 6c9b776237c236c059bd0f307aa580c6ab84acb3..5abe1227e109ed87e07295348014e1249aa821ee 100644 (file)
@@ -55,7 +55,6 @@ DECLARE_CRC8_TABLE(sht4x_crc8_table);
 /**
  * struct sht4x_data - All the data required to operate an SHT4X chip
  * @client: the i2c client associated with the SHT4X
- * @lock: a mutex that is used to prevent parallel access to the i2c client
  * @heating_complete: the time that the last heating finished
  * @data_pending: true if and only if there are measurements to retrieve after heating
  * @heater_power: the power at which the heater will be started
@@ -68,7 +67,6 @@ DECLARE_CRC8_TABLE(sht4x_crc8_table);
  */
 struct sht4x_data {
        struct i2c_client       *client;
-       struct mutex            lock;   /* atomic read data updates */
        unsigned long           heating_complete;       /* in jiffies */
        bool                    data_pending;
        u32                     heater_power;   /* in milli-watts */
@@ -87,7 +85,7 @@ struct sht4x_data {
  */
 static int sht4x_read_values(struct sht4x_data *data)
 {
-       int ret = 0;
+       int ret;
        u16 t_ticks, rh_ticks;
        unsigned long next_update;
        struct i2c_client *client = data->client;
@@ -96,8 +94,6 @@ static int sht4x_read_values(struct sht4x_data *data)
        u8 raw_data[SHT4X_RESPONSE_LENGTH];
        unsigned long curr_jiffies;
 
-       mutex_lock(&data->lock);
-
        curr_jiffies = jiffies;
        if (time_before(curr_jiffies, data->heating_complete))
                msleep(jiffies_to_msecs(data->heating_complete - curr_jiffies));
@@ -110,11 +106,11 @@ static int sht4x_read_values(struct sht4x_data *data)
                        msecs_to_jiffies(data->update_interval);
 
                if (data->valid && time_before_eq(jiffies, next_update))
-                       goto unlock;
+                       return 0;
 
                ret = i2c_master_send(client, cmd, SHT4X_CMD_LEN);
                if (ret < 0)
-                       goto unlock;
+                       return ret;
 
                usleep_range(SHT4X_MEAS_DELAY_HPM, SHT4X_MEAS_DELAY_HPM + SHT4X_DELAY_EXTRA);
        }
@@ -123,7 +119,7 @@ static int sht4x_read_values(struct sht4x_data *data)
        if (ret != SHT4X_RESPONSE_LENGTH) {
                if (ret >= 0)
                        ret = -ENODATA;
-               goto unlock;
+               return ret;
        }
 
        t_ticks = raw_data[0] << 8 | raw_data[1];
@@ -132,26 +128,20 @@ static int sht4x_read_values(struct sht4x_data *data)
        crc = crc8(sht4x_crc8_table, &raw_data[0], SHT4X_WORD_LEN, CRC8_INIT_VALUE);
        if (crc != raw_data[2]) {
                dev_err(&client->dev, "data integrity check failed\n");
-               ret = -EIO;
-               goto unlock;
+               return -EIO;
        }
 
        crc = crc8(sht4x_crc8_table, &raw_data[3], SHT4X_WORD_LEN, CRC8_INIT_VALUE);
        if (crc != raw_data[5]) {
                dev_err(&client->dev, "data integrity check failed\n");
-               ret = -EIO;
-               goto unlock;
+               return -EIO;
        }
 
        data->temperature = ((21875 * (int32_t)t_ticks) >> 13) - 45000;
        data->humidity = ((15625 * (int32_t)rh_ticks) >> 13) - 6000;
        data->last_updated = jiffies;
        data->valid = true;
-       ret = 0;
-
-unlock:
-       mutex_unlock(&data->lock);
-       return ret;
+       return 0;
 }
 
 static ssize_t sht4x_interval_write(struct sht4x_data *data, long val)
@@ -287,22 +277,16 @@ static ssize_t heater_enable_store(struct device *dev,
                heating_time_bound = 1100;
        }
 
-       mutex_lock(&data->lock);
-
-       if (time_before(jiffies, data->heating_complete)) {
-               ret = -EBUSY;
-               goto unlock;
-       }
+       if (time_before(jiffies, data->heating_complete))
+               return -EBUSY;
 
        ret = i2c_master_send(data->client, &cmd, SHT4X_CMD_LEN);
        if (ret < 0)
-               goto unlock;
+               return ret;
 
        data->heating_complete = jiffies + msecs_to_jiffies(heating_time_bound);
        data->data_pending = true;
-unlock:
-       mutex_unlock(&data->lock);
-       return ret;
+       return 0;
 }
 
 static ssize_t heater_power_show(struct device *dev,
@@ -422,8 +406,6 @@ static int sht4x_probe(struct i2c_client *client)
        data->heater_time = 1000;
        data->heating_complete = jiffies;
 
-       mutex_init(&data->lock);
-
        crc8_populate_msb(sht4x_crc8_table, SHT4X_CRC8_POLYNOMIAL);
 
        ret = i2c_master_send(client, cmd, SHT4X_CMD_LEN);