Commit 36b3c070 authored by Alan Cox's avatar Alan Cox Committed by Greg Kroah-Hartman

tty: Move the handling of the tty release logic

Now that we don't have tty->termios tied to drivers->tty we can untangle
the logic here. In addition we can push the removal logic out of the
destructor path.

At that point we can think about sorting out tty_port and console and all
the other ugly hangovers.
Signed-off-by: default avatarAlan Cox <alan@linux.intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3db1ddb7
...@@ -527,12 +527,6 @@ static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver, ...@@ -527,12 +527,6 @@ static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver,
return tty; return tty;
} }
static void pty_unix98_shutdown(struct tty_struct *tty)
{
tty_driver_remove_tty(tty->driver, tty);
/* We have our own method as we don't use the tty index */
}
/* We have no need to install and remove our tty objects as devpts does all /* We have no need to install and remove our tty objects as devpts does all
the work for us */ the work for us */
...@@ -558,9 +552,8 @@ static const struct tty_operations ptm_unix98_ops = { ...@@ -558,9 +552,8 @@ static const struct tty_operations ptm_unix98_ops = {
.unthrottle = pty_unthrottle, .unthrottle = pty_unthrottle,
.set_termios = pty_set_termios, .set_termios = pty_set_termios,
.ioctl = pty_unix98_ioctl, .ioctl = pty_unix98_ioctl,
.shutdown = pty_unix98_shutdown, .resize = pty_resize,
.cleanup = pty_cleanup, .cleanup = pty_cleanup
.resize = pty_resize
}; };
static const struct tty_operations pty_unix98_ops = { static const struct tty_operations pty_unix98_ops = {
...@@ -575,7 +568,6 @@ static const struct tty_operations pty_unix98_ops = { ...@@ -575,7 +568,6 @@ static const struct tty_operations pty_unix98_ops = {
.chars_in_buffer = pty_chars_in_buffer, .chars_in_buffer = pty_chars_in_buffer,
.unthrottle = pty_unthrottle, .unthrottle = pty_unthrottle,
.set_termios = pty_set_termios, .set_termios = pty_set_termios,
.shutdown = pty_unix98_shutdown,
.cleanup = pty_cleanup, .cleanup = pty_cleanup,
}; };
......
...@@ -1249,16 +1249,16 @@ int tty_init_termios(struct tty_struct *tty) ...@@ -1249,16 +1249,16 @@ int tty_init_termios(struct tty_struct *tty)
struct ktermios *tp; struct ktermios *tp;
int idx = tty->index; int idx = tty->index;
tp = tty->driver->termios[idx]; if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS)
if (tp == NULL) { tty->termios = tty->driver->init_termios;
tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL); else {
if (tp == NULL) /* Check for lazy saved data */
return -ENOMEM; tp = tty->driver->termios[idx];
*tp = tty->driver->init_termios; if (tp != NULL)
tty->driver->termios[idx] = tp; tty->termios = *tp;
else
tty->termios = tty->driver->init_termios;
} }
tty->termios = *tp;
/* Compatibility until drivers always set this */ /* Compatibility until drivers always set this */
tty->termios.c_ispeed = tty_termios_input_baud_rate(&tty->termios); tty->termios.c_ispeed = tty_termios_input_baud_rate(&tty->termios);
tty->termios.c_ospeed = tty_termios_baud_rate(&tty->termios); tty->termios.c_ospeed = tty_termios_baud_rate(&tty->termios);
...@@ -1437,24 +1437,24 @@ void tty_free_termios(struct tty_struct *tty) ...@@ -1437,24 +1437,24 @@ void tty_free_termios(struct tty_struct *tty)
{ {
struct ktermios *tp; struct ktermios *tp;
int idx = tty->index; int idx = tty->index;
/* Kill this flag and push into drivers for locking etc */
if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) { /* If the port is going to reset then it has no termios to save */
/* FIXME: Locking on ->termios array */ if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS)
tp = tty->driver->termios[idx]; return;
tty->driver->termios[idx] = NULL;
kfree(tp); /* Stash the termios data */
tp = tty->driver->termios[idx];
if (tp == NULL) {
tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
if (tp == NULL) {
pr_warn("tty: no memory to save termios state.\n");
return;
}
} }
else *tp = tty->termios;
*tty->driver->termios[idx] = tty->termios;
} }
EXPORT_SYMBOL(tty_free_termios); EXPORT_SYMBOL(tty_free_termios);
void tty_shutdown(struct tty_struct *tty)
{
tty_driver_remove_tty(tty->driver, tty);
tty_free_termios(tty);
}
EXPORT_SYMBOL(tty_shutdown);
/** /**
* release_one_tty - release tty structure memory * release_one_tty - release tty structure memory
...@@ -1498,11 +1498,6 @@ static void queue_release_one_tty(struct kref *kref) ...@@ -1498,11 +1498,6 @@ static void queue_release_one_tty(struct kref *kref)
{ {
struct tty_struct *tty = container_of(kref, struct tty_struct, kref); struct tty_struct *tty = container_of(kref, struct tty_struct, kref);
if (tty->ops->shutdown)
tty->ops->shutdown(tty);
else
tty_shutdown(tty);
/* The hangup queue is now free so we can reuse it rather than /* The hangup queue is now free so we can reuse it rather than
waste a chunk of memory for each port */ waste a chunk of memory for each port */
INIT_WORK(&tty->hangup_work, release_one_tty); INIT_WORK(&tty->hangup_work, release_one_tty);
...@@ -1542,6 +1537,11 @@ static void release_tty(struct tty_struct *tty, int idx) ...@@ -1542,6 +1537,11 @@ static void release_tty(struct tty_struct *tty, int idx)
/* This should always be true but check for the moment */ /* This should always be true but check for the moment */
WARN_ON(tty->index != idx); WARN_ON(tty->index != idx);
if (tty->ops->shutdown)
tty->ops->shutdown(tty);
tty_free_termios(tty);
tty_driver_remove_tty(tty->driver, tty);
if (tty->link) if (tty->link)
tty_kref_put(tty->link); tty_kref_put(tty->link);
tty_kref_put(tty); tty_kref_put(tty);
......
...@@ -2850,7 +2850,6 @@ static void con_shutdown(struct tty_struct *tty) ...@@ -2850,7 +2850,6 @@ static void con_shutdown(struct tty_struct *tty)
console_lock(); console_lock();
vc->port.tty = NULL; vc->port.tty = NULL;
console_unlock(); console_unlock();
tty_shutdown(tty);
} }
static int default_italic_color = 2; // green (ASCII) static int default_italic_color = 2; // green (ASCII)
......
...@@ -305,8 +305,7 @@ static void serial_close(struct tty_struct *tty, struct file *filp) ...@@ -305,8 +305,7 @@ static void serial_close(struct tty_struct *tty, struct file *filp)
* Do the resource freeing and refcount dropping for the port. * Do the resource freeing and refcount dropping for the port.
* Avoid freeing the console. * Avoid freeing the console.
* *
* Called asynchronously after the last tty kref is dropped, * Called asynchronously after the last tty kref is dropped.
* and the tty layer has already done the tty_shutdown(tty);
*/ */
static void serial_cleanup(struct tty_struct *tty) static void serial_cleanup(struct tty_struct *tty)
{ {
......
...@@ -423,7 +423,6 @@ extern void tty_unthrottle(struct tty_struct *tty); ...@@ -423,7 +423,6 @@ extern void tty_unthrottle(struct tty_struct *tty);
extern int tty_do_resize(struct tty_struct *tty, struct winsize *ws); extern int tty_do_resize(struct tty_struct *tty, struct winsize *ws);
extern void tty_driver_remove_tty(struct tty_driver *driver, extern void tty_driver_remove_tty(struct tty_driver *driver,
struct tty_struct *tty); struct tty_struct *tty);
extern void tty_shutdown(struct tty_struct *tty);
extern void tty_free_termios(struct tty_struct *tty); extern void tty_free_termios(struct tty_struct *tty);
extern int is_current_pgrp_orphaned(void); extern int is_current_pgrp_orphaned(void);
extern struct pid *tty_get_pgrp(struct tty_struct *tty); extern struct pid *tty_get_pgrp(struct tty_struct *tty);
......
...@@ -45,14 +45,9 @@ ...@@ -45,14 +45,9 @@
* *
* void (*shutdown)(struct tty_struct * tty); * void (*shutdown)(struct tty_struct * tty);
* *
* This routine is called synchronously when a particular tty device * This routine is called under the tty lock when a particular tty device
* is closed for the last time freeing up the resources. * is closed for the last time. It executes before the tty resources
* Note that tty_shutdown() is not called if ops->shutdown is defined. * are freed so may execute while another function holds a tty kref.
* This means one is responsible to take care of calling ops->remove (e.g.
* via tty_driver_remove_tty) and releasing tty->termios.
* Note that this hook may be called from *all* the contexts where one
* uses tty refcounting (e.g. tty_port_tty_get).
*
* *
* void (*cleanup)(struct tty_struct * tty); * void (*cleanup)(struct tty_struct * tty);
* *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment