tty: Fix race between tty release and echo_delayed_work

Fix potential race between tty release and echo_delayed_work,
which could result in use after free scenario for tty struct.

Change-Id: I1ea0f2a17d1131c686b3fe387a3576f3d037a3a5
Signed-off-by: Neeraj Upadhyay <neeraju@codeaurora.org>
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index e6429d4..4305524 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1663,6 +1663,10 @@
 
 	put_pid(tty->pgrp);
 	put_pid(tty->session);
+#if defined(CONFIG_TTY_FLUSH_LOCAL_ECHO)
+	if (tty->echo_delayed_work.work.func)
+		cancel_delayed_work_sync(&tty->echo_delayed_work);
+#endif
 	free_tty_struct(tty);
 }