X-Git-Url: https://git.karo-electronics.de/?a=blobdiff_plain;f=drivers%2Ftty%2Fpty.c;fp=drivers%2Ftty%2Fpty.c;h=e16a49b507efbd57734b0b8f522d0e2a5dfe03ce;hb=2292705bd6c27b3ed2f83db8d2268d8006c027d7;hp=78170e7aa3a31acd8c2bb1592bb2064775215b8b;hpb=54573c4a073ff510d028f423ed3074573c7d9437;p=karo-tx-linux.git diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index 78170e7aa3a3..e16a49b507ef 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c @@ -663,7 +663,14 @@ static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty) /* this is called once with whichever end is closed last */ static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty) { - devpts_kill_index(tty->driver_data, tty->index); + struct inode *ptmx_inode; + + if (tty->driver->subtype == PTY_TYPE_MASTER) + ptmx_inode = tty->driver_data; + else + ptmx_inode = tty->link->driver_data; + devpts_kill_index(ptmx_inode, tty->index); + devpts_del_ref(ptmx_inode); } static const struct tty_operations ptm_unix98_ops = { @@ -753,6 +760,18 @@ static int ptmx_open(struct inode *inode, struct file *filp) set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ tty->driver_data = inode; + /* + * In the case where all references to ptmx inode are dropped and we + * still have /dev/tty opened pointing to the master/slave pair (ptmx + * is closed/released before /dev/tty), we must make sure that the inode + * is still valid when we call the final pty_unix98_shutdown, thus we + * hold an additional reference to the ptmx inode. For the same /dev/tty + * last close case, we also need to make sure the super_block isn't + * destroyed (devpts instance unmounted), before /dev/tty is closed and + * on its release devpts_kill_index is called. + */ + devpts_add_ref(inode); + tty_add_file(tty, filp); slave_inode = devpts_pty_new(inode,