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

staging: iio: adc: ad7192: use driver private lock to protect hardware state changes

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 driver private lock.

Also, as there are state changes in the ad7192_ write_raw function, a lock
is added to prevent the concurrent state changes.

Signed-off-by: Aastha Gupta <aastha.gupta4104@gmail.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Aastha Gupta and committed by
Jonathan Cameron
2db82e32 103f3afe

+7 -2
+7 -2
drivers/staging/iio/adc/ad7192.c
··· 162 162 u32 scale_avail[8][2]; 163 163 u8 gpocon; 164 164 u8 devid; 165 + struct mutex lock; /* protect sensor state */ 165 166 166 167 struct ad_sigma_delta sd; 167 168 }; ··· 462 461 case IIO_CHAN_INFO_SCALE: 463 462 switch (chan->type) { 464 463 case IIO_VOLTAGE: 465 - mutex_lock(&indio_dev->mlock); 464 + mutex_lock(&st->lock); 466 465 *val = st->scale_avail[AD7192_CONF_GAIN(st->conf)][0]; 467 466 *val2 = st->scale_avail[AD7192_CONF_GAIN(st->conf)][1]; 468 - mutex_unlock(&indio_dev->mlock); 467 + mutex_unlock(&st->lock); 469 468 return IIO_VAL_INT_PLUS_NANO; 470 469 case IIO_TEMP: 471 470 *val = 0; ··· 509 508 switch (mask) { 510 509 case IIO_CHAN_INFO_SCALE: 511 510 ret = -EINVAL; 511 + mutex_lock(&st->lock); 512 512 for (i = 0; i < ARRAY_SIZE(st->scale_avail); i++) 513 513 if (val2 == st->scale_avail[i][1]) { 514 514 ret = 0; ··· 523 521 ad7192_calibrate_all(st); 524 522 break; 525 523 } 524 + mutex_unlock(&st->lock); 526 525 break; 527 526 case IIO_CHAN_INFO_SAMP_FREQ: 528 527 if (!val) { ··· 632 629 return -ENOMEM; 633 630 634 631 st = iio_priv(indio_dev); 632 + 633 + mutex_init(&st->lock); 635 634 636 635 st->avdd = devm_regulator_get(&spi->dev, "avdd"); 637 636 if (IS_ERR(st->avdd))