Skip to content

Commit 3fd5edf

Browse files
committed
tty: convert ptm_open_peer() to FD_ADD()
Christian Brauner <brauner@kernel.org> says: The fix sent in [1] was squashed into this commit. Fixes: https://lore.kernel.org/37ac7af5-584f-4768-a462-4d1071c43eaf@sirena.org.uk [1] Reported-by: Mark Brown <broonie@kernel.org> [1] Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> [1] Link: https://patch.msgid.link/20251123-work-fd-prepare-v4-42-b6efa1706cfd@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent af66279 commit 3fd5edf

1 file changed

Lines changed: 18 additions & 33 deletions

File tree

drivers/tty/pty.c

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,23 @@ static inline void legacy_pty_init(void) { }
589589
#ifdef CONFIG_UNIX98_PTYS
590590
static struct cdev ptmx_cdev;
591591

592+
static struct file *ptm_open_peer_file(struct file *master,
593+
struct tty_struct *tty, int flags)
594+
{
595+
struct path path;
596+
struct file *file;
597+
598+
/* Compute the slave's path */
599+
path.mnt = devpts_mntget(master, tty->driver_data);
600+
if (IS_ERR(path.mnt))
601+
return ERR_CAST(path.mnt);
602+
path.dentry = tty->link->driver_data;
603+
604+
file = dentry_open(&path, flags, current_cred());
605+
mntput(path.mnt);
606+
return file;
607+
}
608+
592609
/**
593610
* ptm_open_peer - open the peer of a pty
594611
* @master: the open struct file of the ptmx device node
@@ -601,42 +618,10 @@ static struct cdev ptmx_cdev;
601618
*/
602619
int ptm_open_peer(struct file *master, struct tty_struct *tty, int flags)
603620
{
604-
int fd;
605-
struct file *filp;
606-
int retval = -EINVAL;
607-
struct path path;
608-
609621
if (tty->driver != ptm_driver)
610622
return -EIO;
611623

612-
fd = get_unused_fd_flags(flags);
613-
if (fd < 0) {
614-
retval = fd;
615-
goto err;
616-
}
617-
618-
/* Compute the slave's path */
619-
path.mnt = devpts_mntget(master, tty->driver_data);
620-
if (IS_ERR(path.mnt)) {
621-
retval = PTR_ERR(path.mnt);
622-
goto err_put;
623-
}
624-
path.dentry = tty->link->driver_data;
625-
626-
filp = dentry_open(&path, flags, current_cred());
627-
mntput(path.mnt);
628-
if (IS_ERR(filp)) {
629-
retval = PTR_ERR(filp);
630-
goto err_put;
631-
}
632-
633-
fd_install(fd, filp);
634-
return fd;
635-
636-
err_put:
637-
put_unused_fd(fd);
638-
err:
639-
return retval;
624+
return FD_ADD(flags, ptm_open_peer_file(master, tty, flags));
640625
}
641626

642627
static int pty_unix98_ioctl(struct tty_struct *tty,

0 commit comments

Comments
 (0)