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

iio: adc: spear_adc: Replace indio_dev->mlock with own device lock

As part of the general cleanup of indio_dev->mlock, this change replaces
it with a local lock on the device's state structure.

This is part of a bigger cleanup.
Link: https://lore.kernel.org/linux-iio/CA+U=Dsoo6YABe5ODLp+eFNPGFDjk5ZeQEceGkqjxXcVEhLWubw@mail.gmail.com/

Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Signed-off-by: Mircea Caprioru <mircea.caprioru@analog.com>
Link: https://lore.kernel.org/r/20200928131333.36646-1-mircea.caprioru@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Sergiu Cuciurean and committed by
Jonathan Cameron
31e2d42a 2a94469f

+16 -4
+16 -4
drivers/iio/adc/spear_adc.c
··· 75 75 struct adc_regs_spear6xx __iomem *adc_base_spear6xx; 76 76 struct clk *clk; 77 77 struct completion completion; 78 + /* 79 + * Lock to protect the device state during a potential concurrent 80 + * read access from userspace. Reading a raw value requires a sequence 81 + * of register writes, then a wait for a completion callback, 82 + * and finally a register read, during which userspace could issue 83 + * another read request. This lock protects a read access from 84 + * ocurring before another one has finished. 85 + */ 86 + struct mutex lock; 78 87 u32 current_clk; 79 88 u32 sampling_freq; 80 89 u32 avg_samples; ··· 155 146 156 147 switch (mask) { 157 148 case IIO_CHAN_INFO_RAW: 158 - mutex_lock(&indio_dev->mlock); 149 + mutex_lock(&st->lock); 159 150 160 151 status = SPEAR_ADC_STATUS_CHANNEL_NUM(chan->channel) | 161 152 SPEAR_ADC_STATUS_AVG_SAMPLE(st->avg_samples) | ··· 168 159 wait_for_completion(&st->completion); /* set by ISR */ 169 160 *val = st->value; 170 161 171 - mutex_unlock(&indio_dev->mlock); 162 + mutex_unlock(&st->lock); 172 163 173 164 return IIO_VAL_INT; 174 165 ··· 196 187 if (mask != IIO_CHAN_INFO_SAMP_FREQ) 197 188 return -EINVAL; 198 189 199 - mutex_lock(&indio_dev->mlock); 190 + mutex_lock(&st->lock); 200 191 201 192 if ((val < SPEAR_ADC_CLK_MIN) || 202 193 (val > SPEAR_ADC_CLK_MAX) || ··· 208 199 spear_adc_set_clk(st, val); 209 200 210 201 out: 211 - mutex_unlock(&indio_dev->mlock); 202 + mutex_unlock(&st->lock); 212 203 return ret; 213 204 } 214 205 ··· 280 271 } 281 272 282 273 st = iio_priv(indio_dev); 274 + 275 + mutex_init(&st->lock); 276 + 283 277 st->np = np; 284 278 285 279 /*