Skip to content

Commit 3e3f215

Browse files
lucaceresolijfvogel
authored andcommitted
iio: light: opt3001: fix deadlock due to concurrent flag access
commit f063a28002e3350088b4577c5640882bf4ea17ea upstream. 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: [email protected] Signed-off-by: Luca Ceresoli <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jonathan Cameron <[email protected]> [Fixed conflict while applying on 6.12] Signed-off-by: Luca Ceresoli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 7ca84f6a22d50bf8b31efe9eb05f9859947266d7) Signed-off-by: Jack Vogel <[email protected]>
1 parent 6fca30d commit 3e3f215

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
@@ -692,8 +692,9 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
692692
struct opt3001 *opt = iio_priv(iio);
693693
int ret;
694694
bool wake_result_ready_queue = false;
695+
bool ok_to_ignore_lock = opt->ok_to_ignore_lock;
695696

696-
if (!opt->ok_to_ignore_lock)
697+
if (!ok_to_ignore_lock)
697698
mutex_lock(&opt->lock);
698699

699700
ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION);
@@ -730,7 +731,7 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
730731
}
731732

732733
out:
733-
if (!opt->ok_to_ignore_lock)
734+
if (!ok_to_ignore_lock)
734735
mutex_unlock(&opt->lock);
735736

736737
if (wake_result_ready_queue)

0 commit comments

Comments
 (0)