use-after-free races have been seen due to the workqueue timer in the tty
structure going off after the tty was freed.
Fix that up by using cancel_scheduled_work() and flush_scheduled_work().
}
/*
- * Make sure that the tty's task queue isn't activated.
+ * 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();