Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (sht4x) Rely on subsystem locking

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>

+11 -29
+11 -29
drivers/hwmon/sht4x.c
··· 55 55 /** 56 56 * struct sht4x_data - All the data required to operate an SHT4X chip 57 57 * @client: the i2c client associated with the SHT4X 58 - * @lock: a mutex that is used to prevent parallel access to the i2c client 59 58 * @heating_complete: the time that the last heating finished 60 59 * @data_pending: true if and only if there are measurements to retrieve after heating 61 60 * @heater_power: the power at which the heater will be started ··· 67 68 */ 68 69 struct sht4x_data { 69 70 struct i2c_client *client; 70 - struct mutex lock; /* atomic read data updates */ 71 71 unsigned long heating_complete; /* in jiffies */ 72 72 bool data_pending; 73 73 u32 heater_power; /* in milli-watts */ ··· 85 87 */ 86 88 static int sht4x_read_values(struct sht4x_data *data) 87 89 { 88 - int ret = 0; 90 + int ret; 89 91 u16 t_ticks, rh_ticks; 90 92 unsigned long next_update; 91 93 struct i2c_client *client = data->client; ··· 93 95 u8 cmd[SHT4X_CMD_LEN] = {SHT4X_CMD_MEASURE_HPM}; 94 96 u8 raw_data[SHT4X_RESPONSE_LENGTH]; 95 97 unsigned long curr_jiffies; 96 - 97 - mutex_lock(&data->lock); 98 98 99 99 curr_jiffies = jiffies; 100 100 if (time_before(curr_jiffies, data->heating_complete)) ··· 106 110 msecs_to_jiffies(data->update_interval); 107 111 108 112 if (data->valid && time_before_eq(jiffies, next_update)) 109 - goto unlock; 113 + return 0; 110 114 111 115 ret = i2c_master_send(client, cmd, SHT4X_CMD_LEN); 112 116 if (ret < 0) 113 - goto unlock; 117 + return ret; 114 118 115 119 usleep_range(SHT4X_MEAS_DELAY_HPM, SHT4X_MEAS_DELAY_HPM + SHT4X_DELAY_EXTRA); 116 120 } ··· 119 123 if (ret != SHT4X_RESPONSE_LENGTH) { 120 124 if (ret >= 0) 121 125 ret = -ENODATA; 122 - goto unlock; 126 + return ret; 123 127 } 124 128 125 129 t_ticks = raw_data[0] << 8 | raw_data[1]; ··· 128 132 crc = crc8(sht4x_crc8_table, &raw_data[0], SHT4X_WORD_LEN, CRC8_INIT_VALUE); 129 133 if (crc != raw_data[2]) { 130 134 dev_err(&client->dev, "data integrity check failed\n"); 131 - ret = -EIO; 132 - goto unlock; 135 + return -EIO; 133 136 } 134 137 135 138 crc = crc8(sht4x_crc8_table, &raw_data[3], SHT4X_WORD_LEN, CRC8_INIT_VALUE); 136 139 if (crc != raw_data[5]) { 137 140 dev_err(&client->dev, "data integrity check failed\n"); 138 - ret = -EIO; 139 - goto unlock; 141 + return -EIO; 140 142 } 141 143 142 144 data->temperature = ((21875 * (int32_t)t_ticks) >> 13) - 45000; 143 145 data->humidity = ((15625 * (int32_t)rh_ticks) >> 13) - 6000; 144 146 data->last_updated = jiffies; 145 147 data->valid = true; 146 - ret = 0; 147 - 148 - unlock: 149 - mutex_unlock(&data->lock); 150 - return ret; 148 + return 0; 151 149 } 152 150 153 151 static ssize_t sht4x_interval_write(struct sht4x_data *data, long val) ··· 277 287 heating_time_bound = 1100; 278 288 } 279 289 280 - mutex_lock(&data->lock); 281 - 282 - if (time_before(jiffies, data->heating_complete)) { 283 - ret = -EBUSY; 284 - goto unlock; 285 - } 290 + if (time_before(jiffies, data->heating_complete)) 291 + return -EBUSY; 286 292 287 293 ret = i2c_master_send(data->client, &cmd, SHT4X_CMD_LEN); 288 294 if (ret < 0) 289 - goto unlock; 295 + return ret; 290 296 291 297 data->heating_complete = jiffies + msecs_to_jiffies(heating_time_bound); 292 298 data->data_pending = true; 293 - unlock: 294 - mutex_unlock(&data->lock); 295 - return ret; 299 + return 0; 296 300 } 297 301 298 302 static ssize_t heater_power_show(struct device *dev, ··· 405 421 data->heater_power = 200; 406 422 data->heater_time = 1000; 407 423 data->heating_complete = jiffies; 408 - 409 - mutex_init(&data->lock); 410 424 411 425 crc8_populate_msb(sht4x_crc8_table, SHT4X_CRC8_POLYNOMIAL); 412 426