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

iio: gyro: itg3200_core: do not use internal iio_dev lock

The iio_device lock is only meant for internal use. Hence define a
device local lock to protect against concurrent accesses.

While at it, properly include "mutex.h" for mutex related APIs.

Signed-off-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20221004134909.1692021-13-nuno.sa@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Nuno Sá and committed by
Jonathan Cameron
3cc36cab d711a5a7

+9 -3
+7 -3
drivers/iio/gyro/itg3200_core.c
··· 18 18 #include <linux/slab.h> 19 19 #include <linux/stat.h> 20 20 #include <linux/module.h> 21 + #include <linux/mutex.h> 21 22 #include <linux/delay.h> 22 23 23 24 #include <linux/iio/iio.h> ··· 132 131 int val2, 133 132 long mask) 134 133 { 134 + struct itg3200 *st = iio_priv(indio_dev); 135 135 int ret; 136 136 u8 t; 137 137 ··· 141 139 if (val == 0 || val2 != 0) 142 140 return -EINVAL; 143 141 144 - mutex_lock(&indio_dev->mlock); 142 + mutex_lock(&st->lock); 145 143 146 144 ret = itg3200_read_reg_8(indio_dev, ITG3200_REG_DLPF, &t); 147 145 if (ret) { 148 - mutex_unlock(&indio_dev->mlock); 146 + mutex_unlock(&st->lock); 149 147 return ret; 150 148 } 151 149 t = ((t & ITG3200_DLPF_CFG_MASK) ? 1000u : 8000u) / val - 1; ··· 154 152 ITG3200_REG_SAMPLE_RATE_DIV, 155 153 t); 156 154 157 - mutex_unlock(&indio_dev->mlock); 155 + mutex_unlock(&st->lock); 158 156 return ret; 159 157 160 158 default: ··· 337 335 ret = itg3200_initial_setup(indio_dev); 338 336 if (ret) 339 337 goto error_remove_trigger; 338 + 339 + mutex_init(&st->lock); 340 340 341 341 ret = iio_device_register(indio_dev); 342 342 if (ret)
+2
include/linux/iio/gyro/itg3200.h
··· 102 102 struct i2c_client *i2c; 103 103 struct iio_trigger *trig; 104 104 struct iio_mount_matrix orientation; 105 + /* lock to protect against multiple access to the device */ 106 + struct mutex lock; 105 107 }; 106 108 107 109 enum ITG3200_SCAN_INDEX {