linux-stable/include/linux/iio
Vincent Whitchurch a47cd740b1 iio: Use per-device lockdep class for mlock
[ Upstream commit 2bc9cd66eb ]

If an IIO driver uses callbacks from another IIO driver and calls
iio_channel_start_all_cb() from one of its buffer setup ops, then
lockdep complains due to the lock nesting, as in the below example with
lmp91000.

Since the locks are being taken on different IIO devices, there is no
actual deadlock.  Fix the warning by telling lockdep to use a different
class for each iio_device.

 ============================================
 WARNING: possible recursive locking detected
 --------------------------------------------
 python3/23 is trying to acquire lock:
 (&indio_dev->mlock){+.+.}-{3:3}, at: iio_update_buffers

 but task is already holding lock:
 (&indio_dev->mlock){+.+.}-{3:3}, at: enable_store

 other info that might help us debug this:
  Possible unsafe locking scenario:

        CPU0
        ----
   lock(&indio_dev->mlock);
   lock(&indio_dev->mlock);

  *** DEADLOCK ***

  May be due to missing lock nesting notation

 5 locks held by python3/23:
  #0: (sb_writers#5){.+.+}-{0:0}, at: ksys_write
  #1: (&of->mutex){+.+.}-{3:3}, at: kernfs_fop_write_iter
  #2: (kn->active#14){.+.+}-{0:0}, at: kernfs_fop_write_iter
  #3: (&indio_dev->mlock){+.+.}-{3:3}, at: enable_store
  #4: (&iio_dev_opaque->info_exist_lock){+.+.}-{3:3}, at: iio_update_buffers

 Call Trace:
  __mutex_lock
  iio_update_buffers
  iio_channel_start_all_cb
  lmp91000_buffer_postenable
  __iio_update_buffers
  enable_store

Fixes: 67e17300dc ("iio: potentiostat: add LMP91000 support")
Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20220829091840.2791846-1-vincent.whitchurch@axis.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-10-21 12:38:43 +02:00
..
accel
adc Char / Misc / Other smaller driver subsystem updates for 5.19-rc1 2022-06-03 11:36:34 -07:00
afe iio: afe: rescale: add offset support 2022-02-27 13:38:10 +00:00
common iio: cros: Register FIFO callback after sensor is registered 2022-07-18 18:29:13 +01:00
dac
frequency
gyro
imu iio: adis: stylistic changes 2022-01-23 18:03:37 +00:00
timer
buffer-dma.h iio: buffer-dma: Remove unused iio_buffer_block struct 2021-11-27 15:12:01 +00:00
buffer-dmaengine.h
buffer.h iio: Add output buffer support 2021-10-19 08:30:44 +01:00
buffer_impl.h iio: Add output buffer support 2021-10-19 08:30:44 +01:00
configfs.h
consumer.h
driver.h iio: inkern: introduce devm_iio_map_array_register() short-hand function 2021-10-19 08:27:34 +01:00
events.h
hw-consumer.h
iio-opaque.h iio: Use per-device lockdep class for mlock 2022-10-21 12:38:43 +02:00
iio.h iio: trigger: move trig->owner init to trigger allocate() stage 2022-07-16 16:24:19 +01:00
kfifo_buf.h iio: core: Simplify the registration of kfifo buffers 2022-04-10 16:25:46 +01:00
machine.h
sw_device.h
sw_trigger.h
sysfs.h
trigger.h iio: trigger: move trig->owner init to trigger allocate() stage 2022-07-16 16:24:19 +01:00
trigger_consumer.h
triggered_buffer.h iio: triggered-buffer: extend support to configure output buffers 2021-10-19 08:30:45 +01:00
triggered_event.h
types.h iio: core: Introduce IIO_VAL_INT_64. 2021-11-17 17:51:34 +00:00