mirror-linux/include/linux/iio
Rasmus Villemoes 9910159f06 iio: core: add separate lockdep class for info_exist_lock
When one iio device is a consumer of another, it is possible that
the ->info_exist_lock of both ends up being taken when reading the
value of the consumer device.

Since they currently belong to the same lockdep class (being
initialized in a single location with mutex_init()), that results in a
lockdep warning

         CPU0
         ----
    lock(&iio_dev_opaque->info_exist_lock);
    lock(&iio_dev_opaque->info_exist_lock);

   *** DEADLOCK ***

   May be due to missing lock nesting notation

  4 locks held by sensors/414:
   #0: c31fd6dc (&p->lock){+.+.}-{3:3}, at: seq_read_iter+0x44/0x4e4
   #1: c4f5a1c4 (&of->mutex){+.+.}-{3:3}, at: kernfs_seq_start+0x1c/0xac
   #2: c2827548 (kn->active#34){.+.+}-{0:0}, at: kernfs_seq_start+0x30/0xac
   #3: c1dd2b68 (&iio_dev_opaque->info_exist_lock){+.+.}-{3:3}, at: iio_read_channel_processed_scale+0x24/0xd8

  stack backtrace:
  CPU: 0 UID: 0 PID: 414 Comm: sensors Not tainted 6.17.11 #5 NONE
  Hardware name: Generic AM33XX (Flattened Device Tree)
  Call trace:
   unwind_backtrace from show_stack+0x10/0x14
   show_stack from dump_stack_lvl+0x44/0x60
   dump_stack_lvl from print_deadlock_bug+0x2b8/0x334
   print_deadlock_bug from __lock_acquire+0x13a4/0x2ab0
   __lock_acquire from lock_acquire+0xd0/0x2c0
   lock_acquire from __mutex_lock+0xa0/0xe8c
   __mutex_lock from mutex_lock_nested+0x1c/0x24
   mutex_lock_nested from iio_read_channel_raw+0x20/0x6c
   iio_read_channel_raw from rescale_read_raw+0x128/0x1c4
   rescale_read_raw from iio_channel_read+0xe4/0xf4
   iio_channel_read from iio_read_channel_processed_scale+0x6c/0xd8
   iio_read_channel_processed_scale from iio_hwmon_read_val+0x68/0xbc
   iio_hwmon_read_val from dev_attr_show+0x18/0x48
   dev_attr_show from sysfs_kf_seq_show+0x80/0x110
   sysfs_kf_seq_show from seq_read_iter+0xdc/0x4e4
   seq_read_iter from vfs_read+0x238/0x2e4
   vfs_read from ksys_read+0x6c/0xec
   ksys_read from ret_fast_syscall+0x0/0x1c

Just as the mlock_key already has its own lockdep class, add a
lock_class_key for the info_exist mutex.

Note that this has in theory been a problem since before IIO first
left staging, but it only occurs when a chain of consumers is in use
and that is not often done.

Fixes: ac917a8111 ("staging:iio:core set the iio_dev.info pointer to null on unregister under lock.")
Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
Reviewed-by: Peter Rosin <peda@axentia.se>
Cc: <stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2025-12-27 14:56:33 +00:00
..
accel
adc iio: adc: qcom-vadc-common: fix vadc_scale_fn_type kernel-doc 2025-10-20 18:51:04 +01:00
afe
common iio: cros_ec_sensors: add cros_ec_activity driver 2025-06-26 19:32:51 +01:00
dac
frequency iio: frequency: adf4350: Fix ADF4350_REG3_12BIT_CLKDIV_MODE 2025-08-31 16:46:36 +01:00
gyro
imu iio: imu: adis: fix all kernel-doc warnings in header file 2025-11-09 12:57:04 +00:00
timer
adc-helpers.h
backend.h iio: backend: update iio_backend_oversampling_ratio_set 2025-06-26 19:32:51 +01:00
buffer-dma.h iio: buffer-dma: support getting the DMA channel 2025-10-13 08:38:08 +01:00
buffer-dmaengine.h
buffer.h iio: buffer: deprecated iio_push_to_buffers_with_timestamp() 2025-10-13 08:37:23 +01:00
buffer_impl.h Char/Misc/IIO driver updates for 6.19-rc1 2025-12-06 18:34:24 -08:00
configfs.h
consumer.h iio: buffer: document that buffer callback must be context safe 2025-10-13 08:37:24 +01:00
driver.h
events.h
hw-consumer.h
iio-gts-helper.h
iio-opaque.h iio: core: add separate lockdep class for info_exist_lock 2025-12-27 14:56:33 +00:00
iio.h iio: core: switch info_mask fields to unsigned long to match find_bit helpers 2025-08-25 11:07:17 +01:00
kfifo_buf.h
machine.h
sw_device.h
sw_trigger.h
sysfs.h
trigger.h
trigger_consumer.h
triggered_buffer.h
triggered_event.h
types.h iio: add power and energy measurement modifiers 2025-09-13 13:47:19 +01:00