Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+18 -33
+18 -33
drivers/tty/pty.c
··· 589 589 #ifdef CONFIG_UNIX98_PTYS 590 590 static struct cdev ptmx_cdev; 591 591 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 + 592 609 /** 593 610 * ptm_open_peer - open the peer of a pty 594 611 * @master: the open struct file of the ptmx device node ··· 618 601 */ 619 602 int ptm_open_peer(struct file *master, struct tty_struct *tty, int flags) 620 603 { 621 - int fd; 622 - struct file *filp; 623 - int retval = -EINVAL; 624 - struct path path; 625 - 626 604 if (tty->driver != ptm_driver) 627 605 return -EIO; 628 606 629 - fd = get_unused_fd_flags(flags); 630 - if (fd < 0) { 631 - retval = fd; 632 - goto err; 633 - } 634 - 635 - /* Compute the slave's path */ 636 - path.mnt = devpts_mntget(master, tty->driver_data); 637 - if (IS_ERR(path.mnt)) { 638 - retval = PTR_ERR(path.mnt); 639 - goto err_put; 640 - } 641 - path.dentry = tty->link->driver_data; 642 - 643 - filp = dentry_open(&path, flags, current_cred()); 644 - mntput(path.mnt); 645 - if (IS_ERR(filp)) { 646 - retval = PTR_ERR(filp); 647 - goto err_put; 648 - } 649 - 650 - fd_install(fd, filp); 651 - return fd; 652 - 653 - err_put: 654 - put_unused_fd(fd); 655 - err: 656 - return retval; 607 + return FD_ADD(flags, ptm_open_peer_file(master, tty, flags)); 657 608 } 658 609 659 610 static int pty_unix98_ioctl(struct tty_struct *tty,