Input: matrix_keypad - fix keypad does not response
Subsystems (2)
PATCH v3 1/1 Input: matrix_keypad - fix keypad does not response
If matrix_keypad_stop() is calling and the keypad interrupt is triggered, disable_row_irqs() is called by both matrix_keypad_interrupt() and matrix_keypad_stop() at the same time. then disable_row_irqs() is called twice, and the device enter suspend state before keypad->work is executed. At this condition the device will start keypad and enable irq once after resume. and then irqs are disabled yet because irqs are disabled twice and only enable once.
Take lock around keypad->stopped to ensure irqs operation is in atomic operation.
---
Changes in v3:
- delete no needed lock protection, only add lock in matrix_keypad_stop().
Changes in v2:
- Change commit message and full name in the signed-off-by tag.
drivers/input/keyboard/matrix_keypad.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/input/keyboard/matrix_keypad.c +3 -1
@@ -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;
Signature · 1 line
2.14.3
Quoted 8 lines · Zhang Bo
If
matrix_keypad_stop()is calling and the keypad interrupt is triggered,disable_row_irqs()is called by bothmatrix_keypad_interrupt()andmatrix_keypad_stop()at the same time. thendisable_row_irqs()is called twice, and the device enter suspend state beforekeypad->workis executed. At this condition the device will start keypad and enable irq once after resume. and then irqs are disabled yet because irqs are disabled twice and only enable once.
Quoted 4 lines
Take lock around
keypad->stoppedto ensure irqs operation is in atomic operation.Signed-off-by Zhang Bo <[email protected]>
Applied, thank you.
Quoted 29 lines
---
Changes in v3:
- delete no needed lock protection, only add lock inmatrix_keypad_stop().
Changes in v2:
- Change commit message and full name in the signed-off-by tag.drivers/input/keyboard/matrix_keypad.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/input/keyboard/matrix_keypad.c +3
-1@@ -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; Signature · 1 line
2.14.3
Signature · 1 line
Dmitry