Skip to content

Commit 967fab6

Browse files
Jiri Slabygregkh
authored andcommitted
TTY: add port -> tty link
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>
1 parent 5cff39c commit 967fab6

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

drivers/tty/pty.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
345345
tty_port_init(ports[1]);
346346
o_tty->port = ports[0];
347347
tty->port = ports[1];
348+
o_tty->port->itty = o_tty;
348349

349350
tty_driver_kref_get(driver);
350351
tty->count++;
@@ -371,6 +372,7 @@ static void pty_unix98_shutdown(struct tty_struct *tty)
371372

372373
static void pty_cleanup(struct tty_struct *tty)
373374
{
375+
tty->port->itty = NULL;
374376
kfree(tty->port);
375377
}
376378

drivers/tty/tty_io.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,6 +1417,8 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
14171417
"%s: %s driver does not set tty->port. This will crash the kernel later. Fix the driver!\n",
14181418
__func__, tty->driver->name);
14191419

1420+
tty->port->itty = tty;
1421+
14201422
/*
14211423
* Structures all installed ... call the ldisc open routines.
14221424
* 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)
15521554
tty->ops->shutdown(tty);
15531555
tty_free_termios(tty);
15541556
tty_driver_remove_tty(tty->driver, tty);
1557+
tty->port->itty = NULL;
15551558

15561559
if (tty->link)
15571560
tty_kref_put(tty->link);

include/linux/tty.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ struct tty_port_operations {
189189

190190
struct tty_port {
191191
struct tty_struct *tty; /* Back pointer */
192+
struct tty_struct *itty; /* internal back ptr */
192193
const struct tty_port_operations *ops; /* Port operations */
193194
spinlock_t lock; /* Lock protecting tty field */
194195
int blocked_open; /* Waiting to open */

0 commit comments

Comments
 (0)