Input: mac mouse emulation - add locking
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 12 Nov 2010 06:03:59 +0000 (22:03 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 12 Nov 2010 06:22:19 +0000 (22:22 -0800)
We need to add appropriate locking when toggling mac mouse emulation
on and off to ensure that input device and handler are in consistent
state.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
drivers/macintosh/mac_hid.c

index 067f996..6a82388 100644 (file)
@@ -23,6 +23,8 @@ static int mouse_button3_keycode = KEY_RIGHTALT;      /* right option key */
 
 static struct input_dev *mac_hid_emumouse_dev;
 
+static DEFINE_MUTEX(mac_hid_emumouse_mutex);
+
 static int mac_hid_create_emumouse(void)
 {
        static struct lock_class_key mac_hid_emumouse_dev_event_class;
@@ -187,6 +189,10 @@ static int mac_hid_toggle_emumouse(ctl_table *table, int write,
        int old_val = *valp;
        int rc;
 
+       rc = mutex_lock_killable(&mac_hid_emumouse_mutex);
+       if (rc)
+               return rc;
+
        rc = proc_dointvec(table, write, buffer, lenp, ppos);
 
        if (rc == 0 && write && *valp != old_val) {
@@ -202,6 +208,8 @@ static int mac_hid_toggle_emumouse(ctl_table *table, int write,
        if (rc)
                *valp = old_val;
 
+       mutex_unlock(&mac_hid_emumouse_mutex);
+
        return rc;
 }