From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752155AbdFTUeu (ORCPT ); Tue, 20 Jun 2017 16:34:50 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:57311 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751036AbdFTUet (ORCPT ); Tue, 20 Jun 2017 16:34:49 -0400 From: Arnd Bergmann To: Greg Kroah-Hartman , Jiri Slaby Cc: Arnd Bergmann , Aleksa Sarai , Kees Cook , Colin Ian King , linux-kernel@vger.kernel.org Subject: [PATCH] tty: hide unused pty_get_peer function Date: Tue, 20 Jun 2017 22:34:13 +0200 Message-Id: <20170620203436.630727-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:oLiHzI4aEgkQPIXEVJyIBthT4HELD+E/4FdBAH7DL69g9i9JlPy WGOVNfArWhNIj7DScYvxMPXhjLRfn8CCdafzZqhmK+irsAUtHYmi4Vtya9mr6nFMo+rSVRc 3Ij56pIaLeJbDcOMmkz+4+vIaFBYptyRVtoXZklywUJQgJ3JcqfzMYrU4aze9BmHCae1JE2 tYyg5PVMY8McjMlHflWUg== X-UI-Out-Filterresults: notjunk:1;V01:K0:8Hm170/n2VI=:/qr9xi4JfTDVACwyXKDqD4 q1qeaFDVjqmDj0volGYHHWSqzjUgH8S4p/Oec87IxYlaoki2bz1r5Ha6+jkXlRS/Ur4LkBe2W Oxr2W1DkZ3hE9OgbzKgQEszHjFT6XyhZgh+miHS9LW0CcU1+dqdodPjSh4Rau3HdW17fh3zbl 8iVWK+zpa3WgbOJQC8flKxmRdOZGZnjPzu3Hb7i7sf+iPH7mRNlLBnpwfwODjuwI8msvhHXAm K76q1C3WZmkZojKl2THYm0is8S6CztxZ5fEJHWJgtSa2WRwyv6pu2UpQpDZo85n3av2HzX6/G a5CJTxrEpwgOYxn0NV9Rl9FaK94GGIzL/LmaSEY1tH9uFGtFJkBLd4sFDuAZmxDAZWGUqy0bS 0ksUsWW0ezfbU7VHRnzYPdzaJ2XNesJDwZoykY6pjaPwc1qnVOp6QMsJirfE0MeMDqnKpCutK GeKGVMjFhAxEWAw3SD7XYgAMOna3pck9uVQxTi5OwaydanJ7cEcQFK5HswZmF1nAO7CyReVo3 VaIJIQcr7irV0dDURKyNxV+xJD5N4l8dg7Zoy0UXNv6qFU1D0RNlMzgwcoG6OKQfT3KGtWe1Z DZiOIeM0tovq23GCyqgek+dbdSSP+gyTVwB1rKzMAgzrcJ5ogHTo2vZ1DrLIjkBQv48AJtXRM jpkUN55esa3Qcnx3kG7/V/sb2xgs+wqGhSskCvAo2obVFwn0da/RXl51+qIfXrOiEKFY= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org TIOCGPTPEER is only used for unix98 PTYs, and we get a warning when those are disabled: drivers/tty/pty.c:466:12: error: 'pty_get_peer' defined but not used [-Werror=unused-function] This moves the respective functions inside of the existing #ifdef. Fixes: 54ebbfb16034 ("tty: add TIOCGPTPEER ioctl") Signed-off-by: Arnd Bergmann --- drivers/tty/pty.c | 85 +++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c index d1399aac05a1..284749fb0f6b 100644 --- a/drivers/tty/pty.c +++ b/drivers/tty/pty.c @@ -448,48 +448,6 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty, return retval; } -/** - * pty_open_peer - open the peer of a pty - * @tty: the peer of the pty being opened - * - * Open the cached dentry in tty->link, providing a safe way for userspace - * to get the slave end of a pty (where they have the master fd and cannot - * access or trust the mount namespace /dev/pts was mounted inside). - */ -static struct file *pty_open_peer(struct tty_struct *tty, int flags) -{ - if (tty->driver->subtype != PTY_TYPE_MASTER) - return ERR_PTR(-EIO); - return dentry_open(tty->link->driver_data, flags, current_cred()); -} - -static int pty_get_peer(struct tty_struct *tty, int flags) -{ - int fd = -1; - struct file *filp = NULL; - int retval = -EINVAL; - - fd = get_unused_fd_flags(0); - if (fd < 0) { - retval = fd; - goto err; - } - - filp = pty_open_peer(tty, flags); - if (IS_ERR(filp)) { - retval = PTR_ERR(filp); - goto err_put; - } - - fd_install(fd, filp); - return fd; - -err_put: - put_unused_fd(fd); -err: - return retval; -} - static void pty_cleanup(struct tty_struct *tty) { tty_port_put(tty->port); @@ -646,9 +604,50 @@ static inline void legacy_pty_init(void) { } /* Unix98 devices */ #ifdef CONFIG_UNIX98_PTYS - static struct cdev ptmx_cdev; +/** + * pty_open_peer - open the peer of a pty + * @tty: the peer of the pty being opened + * + * Open the cached dentry in tty->link, providing a safe way for userspace + * to get the slave end of a pty (where they have the master fd and cannot + * access or trust the mount namespace /dev/pts was mounted inside). + */ +static struct file *pty_open_peer(struct tty_struct *tty, int flags) +{ + if (tty->driver->subtype != PTY_TYPE_MASTER) + return ERR_PTR(-EIO); + return dentry_open(tty->link->driver_data, flags, current_cred()); +} + +static int pty_get_peer(struct tty_struct *tty, int flags) +{ + int fd = -1; + struct file *filp = NULL; + int retval = -EINVAL; + + fd = get_unused_fd_flags(0); + if (fd < 0) { + retval = fd; + goto err; + } + + filp = pty_open_peer(tty, flags); + if (IS_ERR(filp)) { + retval = PTR_ERR(filp); + goto err_put; + } + + fd_install(fd, filp); + return fd; + +err_put: + put_unused_fd(fd); +err: + return retval; +} + static int pty_unix98_ioctl(struct tty_struct *tty, unsigned int cmd, unsigned long arg) { -- 2.9.0