[PATCH] FIx race on tty close

From: Benjamin Herrenschmidt
Date: Wed May 05 2004 - 22:31:55 EST


Hi Russell !

Here's the patch fixing the race we talked about on irc, where the ldisc
close can race with the flush_to_ldisc workqueue.

This patch fixes it by killing the workqueue first.

Please bounce to Andrew if you are happy with it.

Ben.

===== drivers/char/tty_io.c 1.136 vs edited =====
--- 1.136/drivers/char/tty_io.c Tue Apr 13 03:54:18 2004
+++ edited/drivers/char/tty_io.c Mon May 3 11:50:46 2004
@@ -1267,6 +1267,18 @@
#endif

/*
+ * Prevent flush_to_ldisc() from rescheduling the work for later. Then
+ * kill any delayed work.
+ */
+ clear_bit(TTY_DONT_FLIP, &tty->flags);
+ cancel_delayed_work(&tty->flip.work);
+
+ /*
+ * Wait for ->hangup_work and ->flip.work handlers to terminate
+ */
+ flush_scheduled_work();
+
+ /*
* Shutdown the current line discipline, and reset it to N_TTY.
* N.B. why reset ldisc when we're releasing the memory??
*/
@@ -1281,19 +1293,7 @@
(o_tty->ldisc.close)(o_tty);
module_put(o_tty->ldisc.owner);
o_tty->ldisc = ldiscs[N_TTY];
- }
-
- /*
- * Prevent flush_to_ldisc() from rescheduling the work for later. Then
- * kill any delayed work.
- */
- clear_bit(TTY_DONT_FLIP, &tty->flags);
- cancel_delayed_work(&tty->flip.work);
-
- /*
- * Wait for ->hangup_work and ->flip.work handlers to terminate
- */
- flush_scheduled_work();
+ }

/*
* The release_mem function takes care of the details of clearing


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/