Input: matrix_keypad - fix race when disabling interrupts
authorZhang Bo <zbsdta@126.com>
Mon, 5 Feb 2018 22:56:21 +0000 (14:56 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Sat, 10 Feb 2018 00:15:45 +0000 (16:15 -0800)
If matrix_keypad_stop() is executing and the keypad interrupt is triggered,
disable_row_irqs() may be called by both matrix_keypad_interrupt() and
matrix_keypad_stop() at the same time, causing interrupts to be disabled
twice and the keypad being "stuck" after resuming.

Take lock when setting keypad->stopped to ensure that ISR will not race
with matrix_keypad_stop() disabling interrupts.

Signed-off-by: Zhang Bo <zbsdta@126.com>
Cc: stable@vger.kernel.org
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
drivers/input/keyboard/matrix_keypad.c

index 1f316d66e6f71eaa232b295c9ba161be4c6a5a9d..41614c185918259d54546a50125601270f3852d7 100644 (file)
@@ -218,8 +218,10 @@ static void matrix_keypad_stop(struct input_dev *dev)
 {
        struct matrix_keypad *keypad = input_get_drvdata(dev);
 
+       spin_lock_irq(&keypad->lock);
        keypad->stopped = true;
-       mb();
+       spin_unlock_irq(&keypad->lock);
+
        flush_work(&keypad->work.work);
        /*
         * matrix_keypad_scan() will leave IRQs enabled;