1
0
Fork 0

amiserial: switch to ->[sg]et_serial()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
hifive-unleashed-5.1
Al Viro 2018-09-11 21:59:13 -04:00
parent 0aad5ad563
commit b129cbc99b
1 changed files with 33 additions and 45 deletions

View File

@ -996,63 +996,55 @@ static void rs_unthrottle(struct tty_struct * tty)
* ------------------------------------------------------------ * ------------------------------------------------------------
*/ */
static int get_serial_info(struct tty_struct *tty, struct serial_state *state, static int get_serial_info(struct tty_struct *tty, struct serial_struct *ss)
struct serial_struct __user * retinfo)
{ {
struct serial_struct tmp; struct serial_state *state = tty->driver_data;
memset(&tmp, 0, sizeof(tmp));
tty_lock(tty); tty_lock(tty);
tmp.line = tty->index; ss->line = tty->index;
tmp.port = state->port; ss->port = state->port;
tmp.flags = state->tport.flags; ss->flags = state->tport.flags;
tmp.xmit_fifo_size = state->xmit_fifo_size; ss->xmit_fifo_size = state->xmit_fifo_size;
tmp.baud_base = state->baud_base; ss->baud_base = state->baud_base;
tmp.close_delay = state->tport.close_delay; ss->close_delay = state->tport.close_delay;
tmp.closing_wait = state->tport.closing_wait; ss->closing_wait = state->tport.closing_wait;
tmp.custom_divisor = state->custom_divisor; ss->custom_divisor = state->custom_divisor;
tty_unlock(tty); tty_unlock(tty);
if (copy_to_user(retinfo,&tmp,sizeof(*retinfo)))
return -EFAULT;
return 0; return 0;
} }
static int set_serial_info(struct tty_struct *tty, struct serial_state *state, static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss)
struct serial_struct __user * new_info)
{ {
struct serial_state *state = tty->driver_data;
struct tty_port *port = &state->tport; struct tty_port *port = &state->tport;
struct serial_struct new_serial;
bool change_spd; bool change_spd;
int retval = 0; int retval = 0;
if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
return -EFAULT;
tty_lock(tty); tty_lock(tty);
change_spd = ((new_serial.flags ^ port->flags) & ASYNC_SPD_MASK) || change_spd = ((ss->flags ^ port->flags) & ASYNC_SPD_MASK) ||
new_serial.custom_divisor != state->custom_divisor; ss->custom_divisor != state->custom_divisor;
if (new_serial.irq || new_serial.port != state->port || if (ss->irq || ss->port != state->port ||
new_serial.xmit_fifo_size != state->xmit_fifo_size) { ss->xmit_fifo_size != state->xmit_fifo_size) {
tty_unlock(tty); tty_unlock(tty);
return -EINVAL; return -EINVAL;
} }
if (!serial_isroot()) { if (!serial_isroot()) {
if ((new_serial.baud_base != state->baud_base) || if ((ss->baud_base != state->baud_base) ||
(new_serial.close_delay != port->close_delay) || (ss->close_delay != port->close_delay) ||
(new_serial.xmit_fifo_size != state->xmit_fifo_size) || (ss->xmit_fifo_size != state->xmit_fifo_size) ||
((new_serial.flags & ~ASYNC_USR_MASK) != ((ss->flags & ~ASYNC_USR_MASK) !=
(port->flags & ~ASYNC_USR_MASK))) { (port->flags & ~ASYNC_USR_MASK))) {
tty_unlock(tty); tty_unlock(tty);
return -EPERM; return -EPERM;
} }
port->flags = ((port->flags & ~ASYNC_USR_MASK) | port->flags = ((port->flags & ~ASYNC_USR_MASK) |
(new_serial.flags & ASYNC_USR_MASK)); (ss->flags & ASYNC_USR_MASK));
state->custom_divisor = new_serial.custom_divisor; state->custom_divisor = ss->custom_divisor;
goto check_and_exit; goto check_and_exit;
} }
if (new_serial.baud_base < 9600) { if (ss->baud_base < 9600) {
tty_unlock(tty); tty_unlock(tty);
return -EINVAL; return -EINVAL;
} }
@ -1062,19 +1054,19 @@ static int set_serial_info(struct tty_struct *tty, struct serial_state *state,
* At this point, we start making changes..... * At this point, we start making changes.....
*/ */
state->baud_base = new_serial.baud_base; state->baud_base = ss->baud_base;
port->flags = ((port->flags & ~ASYNC_FLAGS) | port->flags = ((port->flags & ~ASYNC_FLAGS) |
(new_serial.flags & ASYNC_FLAGS)); (ss->flags & ASYNC_FLAGS));
state->custom_divisor = new_serial.custom_divisor; state->custom_divisor = ss->custom_divisor;
port->close_delay = new_serial.close_delay * HZ/100; port->close_delay = ss->close_delay * HZ/100;
port->closing_wait = new_serial.closing_wait * HZ/100; port->closing_wait = ss->closing_wait * HZ/100;
port->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0; port->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
check_and_exit: check_and_exit:
if (tty_port_initialized(port)) { if (tty_port_initialized(port)) {
if (change_spd) { if (change_spd) {
/* warn about deprecation unless clearing */ /* warn about deprecation unless clearing */
if (new_serial.flags & ASYNC_SPD_MASK) if (ss->flags & ASYNC_SPD_MASK)
dev_warn_ratelimited(tty->dev, "use of SPD flags is deprecated\n"); dev_warn_ratelimited(tty->dev, "use of SPD flags is deprecated\n");
change_speed(tty, state, NULL); change_speed(tty, state, NULL);
} }
@ -1084,7 +1076,6 @@ check_and_exit:
return retval; return retval;
} }
/* /*
* get_lsr_info - get line status register info * get_lsr_info - get line status register info
* *
@ -1224,18 +1215,13 @@ static int rs_ioctl(struct tty_struct *tty,
if (serial_paranoia_check(info, tty->name, "rs_ioctl")) if (serial_paranoia_check(info, tty->name, "rs_ioctl"))
return -ENODEV; return -ENODEV;
if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && if ((cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
(cmd != TIOCSERCONFIG) && (cmd != TIOCSERGSTRUCT) &&
(cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) { (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
if (tty_io_error(tty)) if (tty_io_error(tty))
return -EIO; return -EIO;
} }
switch (cmd) { switch (cmd) {
case TIOCGSERIAL:
return get_serial_info(tty, info, argp);
case TIOCSSERIAL:
return set_serial_info(tty, info, argp);
case TIOCSERCONFIG: case TIOCSERCONFIG:
return 0; return 0;
@ -1607,6 +1593,8 @@ static const struct tty_operations serial_ops = {
.tiocmget = rs_tiocmget, .tiocmget = rs_tiocmget,
.tiocmset = rs_tiocmset, .tiocmset = rs_tiocmset,
.get_icount = rs_get_icount, .get_icount = rs_get_icount,
.set_serial = set_serial_info,
.get_serial = get_serial_info,
.proc_show = rs_proc_show, .proc_show = rs_proc_show,
}; };