Skip to content

Commit 60e893d

Browse files
notrosmb49
authored andcommitted
iio: dln2-adc: Fix lockdep complaint
BugLink: https://bugs.launchpad.net/bugs/1957007 commit 59f9286 upstream. When reading the voltage: $ cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw Lockdep complains: [ 153.910616] ====================================================== [ 153.916918] WARNING: possible circular locking dependency detected [ 153.923221] 5.14.0+ #5 Not tainted [ 153.926692] ------------------------------------------------------ [ 153.932992] cat/717 is trying to acquire lock: [ 153.937525] c2585358 (&indio_dev->mlock){+.+.}-{3:3}, at: iio_device_claim_direct_mode+0x28/0x44 [ 153.946541] but task is already holding lock: [ 153.952487] c2585860 (&dln2->mutex){+.+.}-{3:3}, at: dln2_adc_read_raw+0x94/0x2bc [dln2_adc] [ 153.961152] which lock already depends on the new lock. Fix this by not calling into the iio core underneath the dln2->mutex lock. Fixes: 7c0299e ("iio: adc: Add support for DLN2 ADC") Cc: Jack Andersen <[email protected]> Signed-off-by: Noralf Trønnes <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Stefan Bader <[email protected]>
1 parent aea52f9 commit 60e893d

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

drivers/iio/adc/dln2-adc.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ static int dln2_adc_set_chan_period(struct dln2_adc *dln2,
248248
static int dln2_adc_read(struct dln2_adc *dln2, unsigned int channel)
249249
{
250250
int ret, i;
251-
struct iio_dev *indio_dev = platform_get_drvdata(dln2->pdev);
252251
u16 conflict;
253252
__le16 value;
254253
int olen = sizeof(value);
@@ -257,13 +256,9 @@ static int dln2_adc_read(struct dln2_adc *dln2, unsigned int channel)
257256
.chan = channel,
258257
};
259258

260-
ret = iio_device_claim_direct_mode(indio_dev);
261-
if (ret < 0)
262-
return ret;
263-
264259
ret = dln2_adc_set_chan_enabled(dln2, channel, true);
265260
if (ret < 0)
266-
goto release_direct;
261+
return ret;
267262

268263
ret = dln2_adc_set_port_enabled(dln2, true, &conflict);
269264
if (ret < 0) {
@@ -300,8 +295,6 @@ static int dln2_adc_read(struct dln2_adc *dln2, unsigned int channel)
300295
dln2_adc_set_port_enabled(dln2, false, NULL);
301296
disable_chan:
302297
dln2_adc_set_chan_enabled(dln2, channel, false);
303-
release_direct:
304-
iio_device_release_direct_mode(indio_dev);
305298

306299
return ret;
307300
}
@@ -337,10 +330,16 @@ static int dln2_adc_read_raw(struct iio_dev *indio_dev,
337330

338331
switch (mask) {
339332
case IIO_CHAN_INFO_RAW:
333+
ret = iio_device_claim_direct_mode(indio_dev);
334+
if (ret < 0)
335+
return ret;
336+
340337
mutex_lock(&dln2->mutex);
341338
ret = dln2_adc_read(dln2, chan->channel);
342339
mutex_unlock(&dln2->mutex);
343340

341+
iio_device_release_direct_mode(indio_dev);
342+
344343
if (ret < 0)
345344
return ret;
346345

0 commit comments

Comments
 (0)