[PATCH 1/1] tty BUF DEBUG

From: Jiri Slaby
Date: Sun Oct 28 2012 - 16:42:02 EST


Signed-off-by: Jiri Slaby <jslaby@xxxxxxx>
---
drivers/tty/pty.c | 1 +
drivers/tty/tty_buffer.c | 1 +
drivers/tty/tty_io.c | 4 ++--
drivers/tty/tty_ldisc.c | 1 +
drivers/tty/tty_port.c | 4 ++--
drivers/tty/vt/keyboard.c | 2 +-
6 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 26dcb3b60fb9..644db78bb035 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -445,6 +445,7 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,

static void pty_cleanup(struct tty_struct *tty)
{
+ tty->port->itty = ERR_PTR(-2);
tty_port_put(tty->port);
}

diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
index f8eba1c5412f..642a7fc50aa5 100644
--- a/drivers/tty/tty_buffer.c
+++ b/drivers/tty/tty_buffer.c
@@ -404,6 +404,7 @@ void tty_schedule_flip(struct tty_port *port)
* flush_to_ldisc() sees buffer data.
*/
smp_store_release(&buf->tail->commit, buf->tail->used);
+ WARN_RATELIMIT(IS_ERR_OR_NULL(port->itty), "HUH %p\n", port->itty);
queue_work(system_unbound_wq, &buf->work);
}
EXPORT_SYMBOL(tty_schedule_flip);
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 94cccb6efa32..7dd81d3e0917 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -1471,9 +1471,9 @@ static void release_tty(struct tty_struct *tty, int idx)
tty->ops->shutdown(tty);
tty_free_termios(tty);
tty_driver_remove_tty(tty->driver, tty);
- tty->port->itty = NULL;
+ tty->port->itty = ERR_PTR(-1);
if (tty->link)
- tty->link->port->itty = NULL;
+ tty->link->port->itty = ERR_PTR(-1);
tty_buffer_cancel_work(tty->port);

tty_kref_put(tty->link);
diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
index 84a8ac2a779f..8b2ac1216205 100644
--- a/drivers/tty/tty_ldisc.c
+++ b/drivers/tty/tty_ldisc.c
@@ -615,6 +615,7 @@ int tty_set_ldisc(struct tty_struct *tty, int disc)

/* Restart the work queue in case no characters kick it off. Safe if
already running */
+ WARN_ON(IS_ERR_OR_NULL(tty->port->itty));
tty_buffer_restart_work(tty->port);
err:
tty_ldisc_put(new_ldisc); /* drop the extra reference */
diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
index 1286f2478bce..70661417dc17 100644
--- a/drivers/tty/tty_port.c
+++ b/drivers/tty/tty_port.c
@@ -27,7 +27,7 @@ static int tty_port_default_receive_buf(struct tty_port *port,
struct tty_ldisc *disc;

tty = READ_ONCE(port->itty);
- if (!tty)
+ if (IS_ERR_OR_NULL(tty))
return 0;

disc = tty_ldisc_ref(tty);
@@ -253,7 +253,7 @@ static void tty_port_destructor(struct kref *kref)
struct tty_port *port = container_of(kref, struct tty_port, kref);

/* check if last port ref was dropped before tty release */
- if (WARN_ON(port->itty))
+ if (WARN_ON(!IS_ERR_OR_NULL(port->itty)))
return;
if (port->xmit_buf)
free_page((unsigned long)port->xmit_buf);
diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
index f974d6340d04..f0e3e6869908 100644
--- a/drivers/tty/vt/keyboard.c
+++ b/drivers/tty/vt/keyboard.c
@@ -1325,7 +1325,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)

tty = vc->port.tty;

- if (tty && (!tty->driver_data)) {
+ if (WARN_ON(tty && (!tty->driver_data))) {
/* No driver data? Strange. Okay we fix it then. */
tty->driver_data = vc;
}
--
2.14.3


--------------D4E9AE82A9A0433D997408CD--