Skip to content

Commit 527b3e4

Browse files
Sukadev Bhattiprolutorvalds
authored andcommitted
Simplify devpts_get_tty()
As pointed out by H. Peter Anvin, since the inode for the pty is known, we don't need to look it up. Signed-off-by: Sukadev Bhattiprolu <sukadev@us.ibm.com> Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 15f1a63 commit 527b3e4

1 file changed

Lines changed: 5 additions & 12 deletions

File tree

‎fs/devpts/inode.c‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#define DEVPTS_SUPER_MAGIC 0x1cd1
2828

2929
#define DEVPTS_DEFAULT_MODE 0600
30+
#define PTMX_MINOR 2
3031

3132
extern int pty_limit; /* Config limit on Unix98 ptys */
3233
static DEFINE_IDA(allocated_ptys);
@@ -247,19 +248,11 @@ int devpts_pty_new(struct inode *ptmx_inode, struct tty_struct *tty)
247248

248249
struct tty_struct *devpts_get_tty(struct inode *pts_inode, int number)
249250
{
250-
struct dentry *dentry = get_node(number);
251-
struct tty_struct *tty;
252-
253-
tty = NULL;
254-
if (!IS_ERR(dentry)) {
255-
if (dentry->d_inode)
256-
tty = dentry->d_inode->i_private;
257-
dput(dentry);
258-
}
259-
260-
mutex_unlock(&devpts_root->d_inode->i_mutex);
251+
BUG_ON(pts_inode->i_rdev == MKDEV(TTYAUX_MAJOR, PTMX_MINOR));
261252

262-
return tty;
253+
if (pts_inode->i_sb->s_magic == DEVPTS_SUPER_MAGIC)
254+
return (struct tty_struct *)pts_inode->i_private;
255+
return NULL;
263256
}
264257

265258
void devpts_pty_kill(struct tty_struct *tty)

0 commit comments

Comments
 (0)