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

staging: ad7606: Replace mlock with driver private lock

The IIO subsystem is redefining iio_dev->mlock to be used by
the IIO core only for protecting device operating mode changes.
ie. Changes between INDIO_DIRECT_MODE, INDIO_BUFFER_* modes.

In this driver, mlock was being used to protect hardware state
changes. Replace it with a lock in the devices global data.

Signed-off-by: Arushi Singhal <arushisinghal19971997@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Arushi Singhal and committed by
Jonathan Cameron
755d0da4 64822be4

+8 -4
+5 -4
drivers/staging/iio/adc/ad7606.c
··· 208 208 switch (mask) { 209 209 case IIO_CHAN_INFO_SCALE: 210 210 ret = -EINVAL; 211 - mutex_lock(&indio_dev->mlock); 211 + mutex_lock(&st->lock); 212 212 for (i = 0; i < ARRAY_SIZE(scale_avail); i++) 213 213 if (val2 == scale_avail[i][1]) { 214 214 gpiod_set_value(st->gpio_range, i); ··· 217 217 ret = 0; 218 218 break; 219 219 } 220 - mutex_unlock(&indio_dev->mlock); 220 + mutex_unlock(&st->lock); 221 221 222 222 return ret; 223 223 case IIO_CHAN_INFO_OVERSAMPLING_RATIO: ··· 231 231 values[1] = (ret >> 1) & 1; 232 232 values[2] = (ret >> 2) & 1; 233 233 234 - mutex_lock(&indio_dev->mlock); 234 + mutex_lock(&st->lock); 235 235 gpiod_set_array_value(ARRAY_SIZE(values), st->gpio_os->desc, 236 236 values); 237 237 st->oversampling = val; 238 - mutex_unlock(&indio_dev->mlock); 238 + mutex_unlock(&st->lock); 239 239 240 240 return 0; 241 241 default: ··· 413 413 st = iio_priv(indio_dev); 414 414 415 415 st->dev = dev; 416 + mutex_init(&st->lock); 416 417 st->bops = bops; 417 418 st->base_address = base_address; 418 419 /* tied to logic low, analog input range is +/- 5V */
+3
drivers/staging/iio/adc/ad7606.h
··· 14 14 * @name: identification string for chip 15 15 * @channels: channel specification 16 16 * @num_channels: number of channels 17 + * @lock protect sensor state 17 18 */ 18 19 19 20 struct ad7606_chip_info { ··· 24 23 25 24 /** 26 25 * struct ad7606_state - driver instance specific data 26 + * @lock protect sensor state 27 27 */ 28 28 29 29 struct ad7606_state { ··· 39 37 bool done; 40 38 void __iomem *base_address; 41 39 40 + struct mutex lock; /* protect sensor state */ 42 41 struct gpio_desc *gpio_convst; 43 42 struct gpio_desc *gpio_reset; 44 43 struct gpio_desc *gpio_range;