Skip to content

Commit 809d605

Browse files
jonathannsjic23
authored andcommitted
iio: adc: ad7768-1: remove unnecessary locking
The current locking is only preventing a triggered buffer Transfer and a debugfs register access from happening at the same time. If a register access happens during a buffered read, the action is doomed to fail anyway, since we need to write a magic value to exit continuous read mode. Remove locking from the trigger handler and use iio_device_claim_direct() instead in the register access function. Reviewed-by: David Lechner <[email protected]> Signed-off-by: Jonathan Santos <[email protected]> Link: https://patch.msgid.link/d0450b7c5d8467e54913ef905f6147baa2b866b3.1741268122.git.Jonathan.Santos@analog.com Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 2018214 commit 809d605

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

drivers/iio/adc/ad7768-1.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ static const struct iio_chan_spec ad7768_channels[] = {
154154
struct ad7768_state {
155155
struct spi_device *spi;
156156
struct regulator *vref;
157-
struct mutex lock;
158157
struct clk *mclk;
159158
unsigned int mclk_freq;
160159
unsigned int samp_freq;
@@ -256,18 +255,20 @@ static int ad7768_reg_access(struct iio_dev *indio_dev,
256255
struct ad7768_state *st = iio_priv(indio_dev);
257256
int ret;
258257

259-
mutex_lock(&st->lock);
258+
if (!iio_device_claim_direct(indio_dev))
259+
return -EBUSY;
260+
260261
if (readval) {
261262
ret = ad7768_spi_reg_read(st, reg, 1);
262263
if (ret < 0)
263-
goto err_unlock;
264+
goto err_release;
264265
*readval = ret;
265266
ret = 0;
266267
} else {
267268
ret = ad7768_spi_reg_write(st, reg, writeval);
268269
}
269-
err_unlock:
270-
mutex_unlock(&st->lock);
270+
err_release:
271+
iio_device_release_direct(indio_dev);
271272

272273
return ret;
273274
}
@@ -469,18 +470,15 @@ static irqreturn_t ad7768_trigger_handler(int irq, void *p)
469470
struct ad7768_state *st = iio_priv(indio_dev);
470471
int ret;
471472

472-
mutex_lock(&st->lock);
473-
474473
ret = spi_read(st->spi, &st->data.scan.chan, 3);
475474
if (ret < 0)
476-
goto err_unlock;
475+
goto out;
477476

478477
iio_push_to_buffers_with_timestamp(indio_dev, &st->data.scan,
479478
iio_get_time_ns(indio_dev));
480479

481-
err_unlock:
480+
out:
482481
iio_trigger_notify_done(indio_dev->trig);
483-
mutex_unlock(&st->lock);
484482

485483
return IRQ_HANDLED;
486484
}
@@ -609,8 +607,6 @@ static int ad7768_probe(struct spi_device *spi)
609607

610608
st->mclk_freq = clk_get_rate(st->mclk);
611609

612-
mutex_init(&st->lock);
613-
614610
indio_dev->channels = ad7768_channels;
615611
indio_dev->num_channels = ARRAY_SIZE(ad7768_channels);
616612
indio_dev->name = spi_get_device_id(spi)->name;

0 commit comments

Comments
 (0)