summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2018-09-12 04:53:32 +0300
committerAl Viro <viro@zeniv.linux.org.uk>2018-09-14 18:19:30 +0300
commit2f46a2c1d4eb982b82c199e1bd5cddab12681275 (patch)
treece7fa422b1ca208a6c9f2cbaae41741cb44a7e7f /drivers
parent7eaec37e04616136915ad2207417beb29445fc35 (diff)
downloadlinux-2f46a2c1d4eb982b82c199e1bd5cddab12681275.tar.xz
tty_ioctl(): start taking TIOC[SG]SERIAL into separate methods
->set_serial() and ->get_serial() resp., both taking tty and a kernel pointer to serial_struct. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/tty/tty_io.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index ef2a8766d34f..b96bfd051d59 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -2456,22 +2456,40 @@ static int tty_tiocgicount(struct tty_struct *tty, void __user *arg)
return 0;
}
-static void tty_warn_deprecated_flags(struct serial_struct __user *ss)
+static int tty_tiocsserial(struct tty_struct *tty, struct serial_struct __user *ss)
{
static DEFINE_RATELIMIT_STATE(depr_flags,
DEFAULT_RATELIMIT_INTERVAL,
DEFAULT_RATELIMIT_BURST);
char comm[TASK_COMM_LEN];
+ struct serial_struct v;
int flags;
- if (get_user(flags, &ss->flags))
- return;
+ if (copy_from_user(&v, ss, sizeof(struct serial_struct)))
+ return -EFAULT;
- flags &= ASYNC_DEPRECATED;
+ flags = v.flags & ASYNC_DEPRECATED;
if (flags && __ratelimit(&depr_flags))
pr_warn("%s: '%s' is using deprecated serial flags (with no effect): %.8x\n",
__func__, get_task_comm(comm, current), flags);
+ if (!tty->ops->set_serial)
+ return -ENOIOCTLCMD;
+ return tty->ops->set_serial(tty, &v);
+}
+
+static int tty_tiocgserial(struct tty_struct *tty, struct serial_struct __user *ss)
+{
+ struct serial_struct v;
+ int err;
+
+ memset(&v, 0, sizeof(struct serial_struct));
+ if (!tty->ops->get_serial)
+ return -ENOIOCTLCMD;
+ err = tty->ops->get_serial(tty, &v);
+ if (!err && copy_to_user(ss, &v, sizeof(struct serial_struct)))
+ err = -EFAULT;
+ return err;
}
/*
@@ -2603,7 +2621,14 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
}
break;
case TIOCSSERIAL:
- tty_warn_deprecated_flags(p);
+ retval = tty_tiocsserial(tty, p);
+ if (retval != -ENOIOCTLCMD)
+ return retval;
+ break;
+ case TIOCGSERIAL:
+ retval = tty_tiocgserial(tty, p);
+ if (retval != -ENOIOCTLCMD)
+ return retval;
break;
case TIOCGPTPEER:
/* Special because the struct file is needed */