···21262126 tty = get_current_tty();21272127 if (tty) {21282128 file_list_lock();21292129- file = list_entry(tty->tty_files.next, typeof(*file), f_u.fu_list);21302130- if (file) {21292129+ if (!list_empty(&tty->tty_files)) {21302130+ struct inode *inode;21312131+21312132 /* Revalidate access to controlling tty.21322133 Use inode_has_perm on the tty inode directly rather21332134 than using file_has_perm, as this particular open21342135 file may belong to another process and we are only21352136 interested in the inode-based check here. */21362136- struct inode *inode = file->f_path.dentry->d_inode;21372137+ file = list_first_entry(&tty->tty_files, struct file, f_u.fu_list);21382138+ inode = file->f_path.dentry->d_inode;21372139 if (inode_has_perm(current, inode,21382140 FILE__READ | FILE__WRITE, NULL)) {21392141 drop_tty = 1;