aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2018-09-11 22:01:00 -0400
committerAl Viro <viro@zeniv.linux.org.uk>2018-10-13 00:50:32 -0400
commit1c729ab15a0eeff57aafab704161f8d3663b2854 (patch)
tree9d49d20040bba4ba67ed4ac49cf65e00ec24e463
parentb60f38c6640f3b0e15f37c63167df9560fe00e6a (diff)
moxa: switch to ->[sg]et_serial()
Pointless dead assignments in moxa_set_serial_info() killed off; they would've been a bug, if not for the fact that user-settable flags had never been used in that driver. Bogus from day 1, though... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--drivers/tty/moxa.c79
1 files changed, 40 insertions, 39 deletions
diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
index 250a19f042d7..3a1a5e0ee93f 100644
--- a/drivers/tty/moxa.c
+++ b/drivers/tty/moxa.c
@@ -221,8 +221,8 @@ static int MoxaPortRxQueue(struct moxa_port *);
221static int MoxaPortTxFree(struct moxa_port *); 221static int MoxaPortTxFree(struct moxa_port *);
222static void MoxaPortTxDisable(struct moxa_port *); 222static void MoxaPortTxDisable(struct moxa_port *);
223static void MoxaPortTxEnable(struct moxa_port *); 223static void MoxaPortTxEnable(struct moxa_port *);
224static int moxa_get_serial_info(struct moxa_port *, struct serial_struct __user *); 224static int moxa_get_serial_info(struct tty_struct *, struct serial_struct *);
225static int moxa_set_serial_info(struct moxa_port *, struct serial_struct __user *); 225static int moxa_set_serial_info(struct tty_struct *, struct serial_struct *);
226static void MoxaSetFifo(struct moxa_port *port, int enable); 226static void MoxaSetFifo(struct moxa_port *port, int enable);
227 227
228/* 228/*
@@ -375,16 +375,6 @@ copy:
375 } 375 }
376 break; 376 break;
377 } 377 }
378 case TIOCGSERIAL:
379 mutex_lock(&ch->port.mutex);
380 ret = moxa_get_serial_info(ch, argp);
381 mutex_unlock(&ch->port.mutex);
382 break;
383 case TIOCSSERIAL:
384 mutex_lock(&ch->port.mutex);
385 ret = moxa_set_serial_info(ch, argp);
386 mutex_unlock(&ch->port.mutex);
387 break;
388 default: 378 default:
389 ret = -ENOIOCTLCMD; 379 ret = -ENOIOCTLCMD;
390 } 380 }
@@ -415,6 +405,8 @@ static const struct tty_operations moxa_ops = {
415 .break_ctl = moxa_break_ctl, 405 .break_ctl = moxa_break_ctl,
416 .tiocmget = moxa_tiocmget, 406 .tiocmget = moxa_tiocmget,
417 .tiocmset = moxa_tiocmset, 407 .tiocmset = moxa_tiocmset,
408 .set_serial = moxa_set_serial_info,
409 .get_serial = moxa_get_serial_info,
418}; 410};
419 411
420static const struct tty_port_operations moxa_port_ops = { 412static const struct tty_port_operations moxa_port_ops = {
@@ -2034,46 +2026,55 @@ static void MoxaPortTxEnable(struct moxa_port *port)
2034 moxafunc(port->tableAddr, FC_SetXonState, Magic_code); 2026 moxafunc(port->tableAddr, FC_SetXonState, Magic_code);
2035} 2027}
2036 2028
2037static int moxa_get_serial_info(struct moxa_port *info, 2029static int moxa_get_serial_info(struct tty_struct *tty,
2038 struct serial_struct __user *retinfo) 2030 struct serial_struct *ss)
2039{ 2031{
2040 struct serial_struct tmp = { 2032 struct moxa_port *info = tty->driver_data;
2041 .type = info->type, 2033
2042 .line = info->port.tty->index, 2034 if (tty->index == MAX_PORTS)
2043 .flags = info->port.flags, 2035 return -EINVAL;
2044 .baud_base = 921600, 2036 if (!info)
2045 .close_delay = info->port.close_delay 2037 return -ENODEV;
2046 }; 2038 mutex_lock(&info->port.mutex);
2047 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0; 2039 ss->type = info->type,
2040 ss->line = info->port.tty->index,
2041 ss->flags = info->port.flags,
2042 ss->baud_base = 921600,
2043 ss->close_delay = info->port.close_delay;
2044 mutex_unlock(&info->port.mutex);
2045 return 0;
2048} 2046}
2049 2047
2050 2048
2051static int moxa_set_serial_info(struct moxa_port *info, 2049static int moxa_set_serial_info(struct tty_struct *tty,
2052 struct serial_struct __user *new_info) 2050 struct serial_struct *ss)
2053{ 2051{
2054 struct serial_struct new_serial; 2052 struct moxa_port *info = tty->driver_data;
2055 2053
2056 if (copy_from_user(&new_serial, new_info, sizeof(new_serial))) 2054 if (tty->index == MAX_PORTS)
2057 return -EFAULT; 2055 return -EINVAL;
2056 if (!info)
2057 return -ENODEV;
2058 2058
2059 if (new_serial.irq != 0 || new_serial.port != 0 || 2059 if (ss->irq != 0 || ss->port != 0 ||
2060 new_serial.custom_divisor != 0 || 2060 ss->custom_divisor != 0 ||
2061 new_serial.baud_base != 921600) 2061 ss->baud_base != 921600)
2062 return -EPERM; 2062 return -EPERM;
2063 2063
2064 mutex_lock(&info->port.mutex);
2064 if (!capable(CAP_SYS_ADMIN)) { 2065 if (!capable(CAP_SYS_ADMIN)) {
2065 if (((new_serial.flags & ~ASYNC_USR_MASK) != 2066 if (((ss->flags & ~ASYNC_USR_MASK) !=
2066 (info->port.flags & ~ASYNC_USR_MASK))) 2067 (info->port.flags & ~ASYNC_USR_MASK))) {
2068 mutex_unlock(&info->port.mutex);
2067 return -EPERM; 2069 return -EPERM;
2068 } else 2070 }
2069 info->port.close_delay = new_serial.close_delay * HZ / 100; 2071 }
2070 2072 info->port.close_delay = ss->close_delay * HZ / 100;
2071 new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS);
2072 new_serial.flags |= (info->port.flags & ASYNC_FLAGS);
2073 2073
2074 MoxaSetFifo(info, new_serial.type == PORT_16550A); 2074 MoxaSetFifo(info, ss->type == PORT_16550A);
2075 2075
2076 info->type = new_serial.type; 2076 info->type = ss->type;
2077 mutex_unlock(&info->port.mutex);
2077 return 0; 2078 return 0;
2078} 2079}
2079 2080