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

hwmon: (max31827) 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>

+14 -46
+14 -46
drivers/hwmon/max31827.c
··· 10 10 #include <linux/delay.h> 11 11 #include <linux/hwmon.h> 12 12 #include <linux/i2c.h> 13 - #include <linux/mutex.h> 14 13 #include <linux/of_device.h> 15 14 #include <linux/regmap.h> 16 15 #include <linux/regulator/consumer.h> ··· 98 99 /* 99 100 * Prevent simultaneous access to the i2c client. 100 101 */ 101 - struct mutex lock; 102 102 struct regmap *regmap; 103 103 bool enable; 104 104 unsigned int resolution; ··· 121 123 * Before the Temperature Threshold Alarm, Alarm Hysteresis Threshold 122 124 * and Resolution bits from Configuration register are changed over I2C, 123 125 * the part must be in shutdown mode. 124 - * 125 - * Mutex is used to ensure, that some other process doesn't change the 126 - * configuration register. 127 126 */ 128 - mutex_lock(&st->lock); 129 - 130 127 if (!st->enable) { 131 128 if (!mask) 132 - ret = regmap_write(st->regmap, reg, val); 133 - else 134 - ret = regmap_update_bits(st->regmap, reg, mask, val); 135 - goto unlock; 129 + return regmap_write(st->regmap, reg, val); 130 + return regmap_update_bits(st->regmap, reg, mask, val); 136 131 } 137 132 138 133 ret = regmap_read(st->regmap, MAX31827_CONFIGURATION_REG, &cfg); 139 134 if (ret) 140 - goto unlock; 135 + return ret; 141 136 142 137 cnv_rate = MAX31827_CONFIGURATION_CNV_RATE_MASK & cfg; 143 138 cfg = cfg & ~(MAX31827_CONFIGURATION_1SHOT_MASK | 144 139 MAX31827_CONFIGURATION_CNV_RATE_MASK); 145 140 ret = regmap_write(st->regmap, MAX31827_CONFIGURATION_REG, cfg); 146 141 if (ret) 147 - goto unlock; 142 + return ret; 148 143 149 144 if (!mask) 150 145 ret = regmap_write(st->regmap, reg, val); ··· 145 154 ret = regmap_update_bits(st->regmap, reg, mask, val); 146 155 147 156 if (ret) 148 - goto unlock; 157 + return ret; 149 158 150 - ret = regmap_update_bits(st->regmap, MAX31827_CONFIGURATION_REG, 151 - MAX31827_CONFIGURATION_CNV_RATE_MASK, 152 - cnv_rate); 153 - 154 - unlock: 155 - mutex_unlock(&st->lock); 156 - return ret; 159 + return regmap_update_bits(st->regmap, MAX31827_CONFIGURATION_REG, 160 + MAX31827_CONFIGURATION_CNV_RATE_MASK, 161 + cnv_rate); 157 162 } 158 163 159 164 static int write_alarm_val(struct max31827_state *st, unsigned int reg, ··· 210 223 211 224 break; 212 225 case hwmon_temp_input: 213 - mutex_lock(&st->lock); 214 - 215 226 if (!st->enable) { 216 - /* 217 - * This operation requires mutex protection, 218 - * because the chip configuration should not 219 - * be changed during the conversion process. 220 - */ 221 - 222 227 ret = regmap_update_bits(st->regmap, 223 228 MAX31827_CONFIGURATION_REG, 224 229 MAX31827_CONFIGURATION_1SHOT_MASK, 225 230 1); 226 - if (ret) { 227 - mutex_unlock(&st->lock); 231 + if (ret) 228 232 return ret; 229 - } 230 233 msleep(max31827_conv_times[st->resolution]); 231 234 } 232 235 ··· 230 253 usleep_range(15000, 20000); 231 254 232 255 ret = regmap_read(st->regmap, MAX31827_T_REG, &uval); 233 - 234 - mutex_unlock(&st->lock); 235 256 236 257 if (ret) 237 258 break; ··· 327 352 if (val >> 1) 328 353 return -EINVAL; 329 354 330 - mutex_lock(&st->lock); 331 355 /** 332 356 * The chip should not be enabled while a conversion is 333 357 * performed. Neither should the chip be enabled when ··· 335 361 336 362 st->enable = val; 337 363 338 - ret = regmap_update_bits(st->regmap, 339 - MAX31827_CONFIGURATION_REG, 340 - MAX31827_CONFIGURATION_1SHOT_MASK | 341 - MAX31827_CONFIGURATION_CNV_RATE_MASK, 342 - MAX31827_DEVICE_ENABLE(val)); 343 - 344 - mutex_unlock(&st->lock); 345 - 346 - return ret; 364 + return regmap_update_bits(st->regmap, 365 + MAX31827_CONFIGURATION_REG, 366 + MAX31827_CONFIGURATION_1SHOT_MASK | 367 + MAX31827_CONFIGURATION_CNV_RATE_MASK, 368 + MAX31827_DEVICE_ENABLE(val)); 347 369 348 370 case hwmon_temp_max: 349 371 return write_alarm_val(st, MAX31827_TH_REG, val); ··· 592 622 st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL); 593 623 if (!st) 594 624 return -ENOMEM; 595 - 596 - mutex_init(&st->lock); 597 625 598 626 st->regmap = devm_regmap_init_i2c(client, &max31827_regmap); 599 627 if (IS_ERR(st->regmap))