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

staging: iio: ad9834: Use private driver lock instead of mlock

iio_dev->mlock should be used by the IIO core only for protecting
device operating mode changes. ie. Changes between INDIO_DIRECT_MODE,
INDIO_BUFFER_* modes.
Replace mlock with a lock in the device's global data to protect
hardware state changes.

Signed-off-by: sayli karnik <karniksayli1995@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

sayli karnik and committed by
Jonathan Cameron
c63313c6 8fa06c90

+7 -4
+7 -4
drivers/staging/iio/frequency/ad9834.c
··· 63 63 * @msg: default spi message 64 64 * @freq_xfer: tuning word spi transfer 65 65 * @freq_msg: tuning word spi message 66 + * @lock: protect sensor state 66 67 * @data: spi transmit buffer 67 68 * @freq_data: tuning word spi transmit buffer 68 69 */ ··· 78 77 struct spi_message msg; 79 78 struct spi_transfer freq_xfer[2]; 80 79 struct spi_message freq_msg; 80 + struct mutex lock; /* protect sensor state */ 81 81 82 82 /* 83 83 * DMA (thus cache coherency maintenance) requires the ··· 151 149 if (ret) 152 150 goto error_ret; 153 151 154 - mutex_lock(&indio_dev->mlock); 152 + mutex_lock(&st->lock); 155 153 switch ((u32)this_attr->address) { 156 154 case AD9834_REG_FREQ0: 157 155 case AD9834_REG_FREQ1: ··· 209 207 default: 210 208 ret = -ENODEV; 211 209 } 212 - mutex_unlock(&indio_dev->mlock); 210 + mutex_unlock(&st->lock); 213 211 214 212 error_ret: 215 213 return ret ? ret : len; ··· 226 224 int ret = 0; 227 225 bool is_ad9833_7 = (st->devid == ID_AD9833) || (st->devid == ID_AD9837); 228 226 229 - mutex_lock(&indio_dev->mlock); 227 + mutex_lock(&st->lock); 230 228 231 229 switch ((u32)this_attr->address) { 232 230 case 0: ··· 269 267 st->data = cpu_to_be16(AD9834_REG_CMD | st->control); 270 268 ret = spi_sync(st->spi, &st->msg); 271 269 } 272 - mutex_unlock(&indio_dev->mlock); 270 + mutex_unlock(&st->lock); 273 271 274 272 return ret ? ret : len; 275 273 } ··· 420 418 } 421 419 spi_set_drvdata(spi, indio_dev); 422 420 st = iio_priv(indio_dev); 421 + mutex_init(&st->lock); 423 422 st->mclk = pdata->mclk; 424 423 st->spi = spi; 425 424 st->devid = spi_get_device_id(spi)->driver_data;