Skip to content

Commit 82f3015

Browse files
dpfreyjic23
authored andcommitted
iio: light: opt3001: fix mutex unlock race
When an end-of-conversion interrupt is received after performing a single-shot reading of the light sensor, the driver was waking up the result ready queue before checking opt->ok_to_ignore_lock to determine if it should unlock the mutex. The problem occurred in the case where the other thread woke up and changed the value of opt->ok_to_ignore_lock to false prior to the interrupt thread performing its read of the variable. In this case, the mutex would be unlocked twice. Signed-off-by: David Frey <[email protected]> Reviewed-by: Andreas Dannenberg <[email protected]> Fixes: 94a9b7b ("iio: light: add support for TI's opt3001 light sensor") Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent c62dd44 commit 82f3015

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/iio/light/opt3001.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
686686
struct iio_dev *iio = _iio;
687687
struct opt3001 *opt = iio_priv(iio);
688688
int ret;
689+
bool wake_result_ready_queue = false;
689690

690691
if (!opt->ok_to_ignore_lock)
691692
mutex_lock(&opt->lock);
@@ -720,13 +721,16 @@ static irqreturn_t opt3001_irq(int irq, void *_iio)
720721
}
721722
opt->result = ret;
722723
opt->result_ready = true;
723-
wake_up(&opt->result_ready_queue);
724+
wake_result_ready_queue = true;
724725
}
725726

726727
out:
727728
if (!opt->ok_to_ignore_lock)
728729
mutex_unlock(&opt->lock);
729730

731+
if (wake_result_ready_queue)
732+
wake_up(&opt->result_ready_queue);
733+
730734
return IRQ_HANDLED;
731735
}
732736

0 commit comments

Comments
 (0)