]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tty: fix return value for unsupported ioctls
authorJohan Hovold <johan@kernel.org>
Wed, 7 Apr 2021 09:52:02 +0000 (11:52 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 22 May 2021 08:38:23 +0000 (10:38 +0200)
[ Upstream commit 1b8b20868a6d64cfe8174a21b25b74367bdf0560 ]

Drivers should return -ENOTTY ("Inappropriate I/O control operation")
when an ioctl isn't supported, while -EINVAL is used for invalid
arguments.

Fix up the TIOCMGET, TIOCMSET and TIOCGICOUNT helpers which returned
-EINVAL when a tty driver did not implement the corresponding
operations.

Note that the TIOCMGET and TIOCMSET helpers predate git and do not get a
corresponding Fixes tag below.

Fixes: d281da7ff6f7 ("tty: Make tiocgicount a handler")
Signed-off-by: Johan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20210407095208.31838-3-johan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/tty/tty_io.c
include/linux/tty_driver.h

index dff507cd0250f54c690f47d0d2456a4be7b17608..bdb25b23e8d3a18d3ab48cb17b6451908caa0c12 100644 (file)
@@ -2762,14 +2762,14 @@ out:
  *     @p: pointer to result
  *
  *     Obtain the modem status bits from the tty driver if the feature
- *     is supported. Return -EINVAL if it is not available.
+ *     is supported. Return -ENOTTY if it is not available.
  *
  *     Locking: none (up to the driver)
  */
 
 static int tty_tiocmget(struct tty_struct *tty, int __user *p)
 {
-       int retval = -EINVAL;
+       int retval = -ENOTTY;
 
        if (tty->ops->tiocmget) {
                retval = tty->ops->tiocmget(tty);
@@ -2787,7 +2787,7 @@ static int tty_tiocmget(struct tty_struct *tty, int __user *p)
  *     @p: pointer to desired bits
  *
  *     Set the modem status bits from the tty driver if the feature
- *     is supported. Return -EINVAL if it is not available.
+ *     is supported. Return -ENOTTY if it is not available.
  *
  *     Locking: none (up to the driver)
  */
@@ -2799,7 +2799,7 @@ static int tty_tiocmset(struct tty_struct *tty, unsigned int cmd,
        unsigned int set, clear, val;
 
        if (tty->ops->tiocmset == NULL)
-               return -EINVAL;
+               return -ENOTTY;
 
        retval = get_user(val, p);
        if (retval)
index 161052477f77009e59744339ac5377e4a9b03356..6d8db155526041ed8118deb8e6d71b266568d0ab 100644 (file)
  *
  *     Called when the device receives a TIOCGICOUNT ioctl. Passed a kernel
  *     structure to complete. This method is optional and will only be called
- *     if provided (otherwise EINVAL will be returned).
+ *     if provided (otherwise ENOTTY will be returned).
  */
 
 #include <linux/export.h>