Skip to content

Commit f063a28

Browse files
lucaceresolijic23
authored andcommitted
iio: light: opt3001: fix deadlock due to concurrent flag access
The threaded IRQ function in this driver is reading the flag twice: once to lock a mutex and once to unlock it. Even though the code setting the flag is designed to prevent it, there are subtle cases where the flag could be true at the mutex_lock stage and false at the mutex_unlock stage. This results in the mutex not being unlocked, resulting in a deadlock. Fix it by making the opt3001_irq() code generally more robust, reading the flag into a variable and using the variable value at both stages. Fixes: 94a9b7b ("iio: light: add support for TI's opt3001 light sensor") Cc: stable@vger.kernel.org Signed-off-by: Luca Ceresoli <luca.ceresoli@bootlin.com> Link: https://patch.msgid.link/20250321-opt3001-irq-fix-v1-1-6c520d851562@bootlin.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 82c51ac commit f063a28

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/iio/light/opt3001.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,8 +788,9 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
788788
int ret;
789789
bool wake_result_ready_queue = false;
790790
enum iio_chan_type chan_type = opt->chip_info->chan_type;
791+
bool ok_to_ignore_lock = opt->ok_to_ignore_lock;
791792

792-
if (!opt->ok_to_ignore_lock)
793+
if (!ok_to_ignore_lock)
793794
mutex_lock(&opt->lock);
794795

795796
ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
@@ -826,7 +827,7 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
826827
}
827828

828829
out:
829-
if (!opt->ok_to_ignore_lock)
830+
if (!ok_to_ignore_lock)
830831
mutex_unlock(&opt->lock);
831832

832833
if (wake_result_ready_queue)

0 commit comments

Comments
 (0)