tty: refactor TIOCSSERIAL handling
Factor out the deprecated serial flags handling and tty-operation check shared with the compat TIOCSSERIAL handler. Signed-off-by: Johan Hovold <johan@kernel.org> Link: https://lore.kernel.org/r/20210407095208.31838-6-johan@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
1b7bc6b10a
commit
885c77d528
@ -2624,23 +2624,31 @@ static int tty_tiocgicount(struct tty_struct *tty, void __user *arg)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tty_tiocsserial(struct tty_struct *tty, struct serial_struct __user *ss)
|
static int tty_set_serial(struct tty_struct *tty, struct serial_struct *ss)
|
||||||
{
|
{
|
||||||
char comm[TASK_COMM_LEN];
|
char comm[TASK_COMM_LEN];
|
||||||
struct serial_struct v;
|
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
if (copy_from_user(&v, ss, sizeof(*ss)))
|
flags = ss->flags & ASYNC_DEPRECATED;
|
||||||
return -EFAULT;
|
|
||||||
|
|
||||||
flags = v.flags & ASYNC_DEPRECATED;
|
|
||||||
|
|
||||||
if (flags)
|
if (flags)
|
||||||
pr_warn_ratelimited("%s: '%s' is using deprecated serial flags (with no effect): %.8x\n",
|
pr_warn_ratelimited("%s: '%s' is using deprecated serial flags (with no effect): %.8x\n",
|
||||||
__func__, get_task_comm(comm, current), flags);
|
__func__, get_task_comm(comm, current), flags);
|
||||||
|
|
||||||
if (!tty->ops->set_serial)
|
if (!tty->ops->set_serial)
|
||||||
return -ENOTTY;
|
return -ENOTTY;
|
||||||
return tty->ops->set_serial(tty, &v);
|
|
||||||
|
return tty->ops->set_serial(tty, ss);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int tty_tiocsserial(struct tty_struct *tty, struct serial_struct __user *ss)
|
||||||
|
{
|
||||||
|
struct serial_struct v;
|
||||||
|
|
||||||
|
if (copy_from_user(&v, ss, sizeof(*ss)))
|
||||||
|
return -EFAULT;
|
||||||
|
|
||||||
|
return tty_set_serial(tty, &v);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tty_tiocgserial(struct tty_struct *tty, struct serial_struct __user *ss)
|
static int tty_tiocgserial(struct tty_struct *tty, struct serial_struct __user *ss)
|
||||||
@ -2838,10 +2846,8 @@ struct serial_struct32 {
|
|||||||
static int compat_tty_tiocsserial(struct tty_struct *tty,
|
static int compat_tty_tiocsserial(struct tty_struct *tty,
|
||||||
struct serial_struct32 __user *ss)
|
struct serial_struct32 __user *ss)
|
||||||
{
|
{
|
||||||
char comm[TASK_COMM_LEN];
|
|
||||||
struct serial_struct32 v32;
|
struct serial_struct32 v32;
|
||||||
struct serial_struct v;
|
struct serial_struct v;
|
||||||
int flags;
|
|
||||||
|
|
||||||
if (copy_from_user(&v32, ss, sizeof(*ss)))
|
if (copy_from_user(&v32, ss, sizeof(*ss)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
@ -2852,14 +2858,7 @@ static int compat_tty_tiocsserial(struct tty_struct *tty,
|
|||||||
v.port_high = v32.port_high;
|
v.port_high = v32.port_high;
|
||||||
v.iomap_base = 0;
|
v.iomap_base = 0;
|
||||||
|
|
||||||
flags = v.flags & ASYNC_DEPRECATED;
|
return tty_set_serial(tty, &v);
|
||||||
|
|
||||||
if (flags)
|
|
||||||
pr_warn_ratelimited("%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 -ENOTTY;
|
|
||||||
return tty->ops->set_serial(tty, &v);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compat_tty_tiocgserial(struct tty_struct *tty,
|
static int compat_tty_tiocgserial(struct tty_struct *tty,
|
||||||
|
Loading…
Reference in New Issue
Block a user