TTY: add port -> tty link
authorJiri Slaby <jslaby@suse.cz>
Thu, 18 Oct 2012 20:26:46 +0000 (22:26 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 22 Oct 2012 23:53:40 +0000 (16:53 -0700)
For that purpose we have to temporarily introduce a second tty back
pointer into tty_port. It is because serial layer, and maybe others,
still do not use tty_port_tty_set/get. So that we cannot set the
tty_port->tty to NULL at will now.

Yes, the fix would be to convert whole serial layer and all its users
to tty_port_tty_set/get. However we are in the process of removing the
need of tty in most of the call sites, so this would lead to a
duplicated work.

Instead we have now tty_port->itty (internal tty) which will be used
only in flush_to_ldisc. For that one it is ensured that itty is valid
wherever the work is run. IOW, the work is synchronously cancelled
before we set itty to NULL and also before hangup is processed.

After we need only tty_port and not tty_struct in most code, this
shall be changed to tty_port_tty_set/get and itty removed completely.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Acked-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/pty.c
drivers/tty/tty_io.c
include/linux/tty.h

index 2728afe52eeae73b5e7b08992de22b118949bb1d..c32690862671f859bbdb3c6a0c3f3b4f75f33eb4 100644 (file)
@@ -345,6 +345,7 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
        tty_port_init(ports[1]);
        o_tty->port = ports[0];
        tty->port = ports[1];
+       o_tty->port->itty = o_tty;
 
        tty_driver_kref_get(driver);
        tty->count++;
@@ -371,6 +372,7 @@ static void pty_unix98_shutdown(struct tty_struct *tty)
 
 static void pty_cleanup(struct tty_struct *tty)
 {
+       tty->port->itty = NULL;
        kfree(tty->port);
 }
 
index f90b6217b3ba0d23f1740d90dcccdc464406b276..202008f38ca343d74b182fa89b40292863431dc8 100644 (file)
@@ -1417,6 +1417,8 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
                        "%s: %s driver does not set tty->port. This will crash the kernel later. Fix the driver!\n",
                        __func__, tty->driver->name);
 
+       tty->port->itty = tty;
+
        /*
         * Structures all installed ... call the ldisc open routines.
         * If we fail here just call release_tty to clean up.  No need
@@ -1552,6 +1554,7 @@ 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;
 
        if (tty->link)
                tty_kref_put(tty->link);
index b4b3c568d242762481bc869b136df8a393d47612..9be74d649a51f3ab05135bacf839e91473375959 100644 (file)
@@ -189,6 +189,7 @@ struct tty_port_operations {
        
 struct tty_port {
        struct tty_struct       *tty;           /* Back pointer */
+       struct tty_struct       *itty;          /* internal back ptr */
        const struct tty_port_operations *ops;  /* Port operations */
        spinlock_t              lock;           /* Lock protecting tty field */
        int                     blocked_open;   /* Waiting to open */