return pty_common_install(driver, tty, false);
  }
  
 -static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
 -{
 -}
 -
  /* this is called once with whichever end is closed last */
 -static void pty_unix98_shutdown(struct tty_struct *tty)
 +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 = {
 
        if (WARN(tty->magic != TTY_MAGIC, "L Bad %p\n", tty))
                return -EIO;
        tty_kref_get(tty);
-       return mutex_lock_interruptible(&tty->legacy_mutex);
+       ret = mutex_lock_interruptible(&tty->legacy_mutex);
+       if (ret)
+               tty_kref_put(tty);
+       return ret;
  }
  
 -void __lockfunc tty_unlock(struct tty_struct *tty)
 +void tty_unlock(struct tty_struct *tty)
  {
        if (WARN(tty->magic != TTY_MAGIC, "U Bad %p\n", tty))
                return;