Commit 1b8b2086 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman
Browse files

tty: fix return value for unsupported ioctls



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: d281da7f ("tty: Make tiocgicount a handler")
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20210407095208.31838-3-johan@kernel.org


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d09845e9
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -2529,14 +2529,14 @@ static int send_break(struct tty_struct *tty, unsigned int duration)
 *	@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);
@@ -2554,7 +2554,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)
 */
@@ -2566,7 +2566,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)
@@ -2606,7 +2606,7 @@ int tty_get_icount(struct tty_struct *tty,
	if (tty->ops->get_icount)
		return tty->ops->get_icount(tty, icount);
	else
		return -EINVAL;
		return -ENOTTY;
}
EXPORT_SYMBOL_GPL(tty_get_icount);

+1 −1
Original line number Diff line number Diff line
@@ -228,7 +228,7 @@
 *
 *	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>