Input: atkbd - fix canceling event_work in disconnect
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 6 Jan 2010 01:56:02 +0000 (17:56 -0800)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Wed, 6 Jan 2010 08:16:14 +0000 (00:16 -0800)
We need to first unregister input device and only then cancel event work
since events can arrive (and cause event work to get scheduled again)
until input_unregister_device() returns.

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
drivers/input/keyboard/atkbd.c

index 1cf32a7814d05604c79000541dfa477acc597da4..7b4056292eaf9387b95fe80c147ad6c9a65920e5 100644 (file)
@@ -855,10 +855,16 @@ static void atkbd_disconnect(struct serio *serio)
 
        atkbd_disable(atkbd);
 
-       /* make sure we don't have a command in flight */
+       input_unregister_device(atkbd->dev);
+
+       /*
+        * Make sure we don't have a command in flight.
+        * Note that since atkbd->enabled is false event work will keep
+        * rescheduling itself until it gets canceled and will not try
+        * accessing freed input device or serio port.
+        */
        cancel_delayed_work_sync(&atkbd->event_work);
 
-       input_unregister_device(atkbd->dev);
        serio_close(serio);
        serio_set_drvdata(serio, NULL);
        kfree(atkbd);