Skip to contentSkip to conversation

FIx race on tty close

PATCH New Benjamin Herrenschmidt 1 participant 1 message May 6, 2004 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 FIx race on tty close

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 =====

drivers/char/tty_io.c +13 -13
@@ -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