From 21cea58e49cf59e7c77ce2a01be432458e9f99a9 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Sun, 29 Nov 2009 23:40:58 -0800 Subject: Input: keyboard - add locking around event handling Keyboard input handler is multiplexing events form all keyboard-like devices in the system. Because of that per-device lock provided by input core is not enough to prevent clashes in ked_event() and we need our own lock to ensure that only one thread at a time executing kbd_event(). Signed-off-by: Dmitry Torokhov --- drivers/char/keyboard.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers/char') diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c index 747683f055ed..ca090e57e161 100644 --- a/drivers/char/keyboard.c +++ b/drivers/char/keyboard.c @@ -132,6 +132,7 @@ int shift_state = 0; */ static struct input_handler kbd_handler; +static DEFINE_SPINLOCK(kbd_event_lock); static unsigned long key_down[BITS_TO_LONGS(KEY_CNT)]; /* keyboard key bitmap */ static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */ static int dead_key_next; @@ -1296,10 +1297,16 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw) static void kbd_event(struct input_handle *handle, unsigned int event_type, unsigned int event_code, int value) { + /* We are called with interrupts disabled, just take the lock */ + spin_lock(&kbd_event_lock); + if (event_type == EV_MSC && event_code == MSC_RAW && HW_RAW(handle->dev)) kbd_rawcode(value); if (event_type == EV_KEY) kbd_keycode(event_code, value, HW_RAW(handle->dev)); + + spin_unlock(&kbd_event_lock); + tasklet_schedule(&keyboard_tasklet); do_poke_blanked_console = 1; schedule_console_callback(); -- cgit v1.2.3-59-g8ed1b