OSDN Git Service

moxa: switch to ->[sg]et_serial()
authorAl Viro <viro@zeniv.linux.org.uk>
Wed, 12 Sep 2018 02:01:00 +0000 (22:01 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 13 Oct 2018 04:50:32 +0000 (00:50 -0400)
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>
drivers/tty/moxa.c

index 250a19f..3a1a5e0 100644 (file)
@@ -221,8 +221,8 @@ static int MoxaPortRxQueue(struct moxa_port *);
 static int MoxaPortTxFree(struct moxa_port *);
 static void MoxaPortTxDisable(struct moxa_port *);
 static void MoxaPortTxEnable(struct moxa_port *);
-static int moxa_get_serial_info(struct moxa_port *, struct serial_struct __user *);
-static int moxa_set_serial_info(struct moxa_port *, struct serial_struct __user *);
+static int moxa_get_serial_info(struct tty_struct *, struct serial_struct *);
+static int moxa_set_serial_info(struct tty_struct *, struct serial_struct *);
 static void MoxaSetFifo(struct moxa_port *port, int enable);
 
 /*
@@ -375,16 +375,6 @@ copy:
                }
                break;
        }
-       case TIOCGSERIAL:
-               mutex_lock(&ch->port.mutex);
-               ret = moxa_get_serial_info(ch, argp);
-               mutex_unlock(&ch->port.mutex);
-               break;
-       case TIOCSSERIAL:
-               mutex_lock(&ch->port.mutex);
-               ret = moxa_set_serial_info(ch, argp);
-               mutex_unlock(&ch->port.mutex);
-               break;
        default:
                ret = -ENOIOCTLCMD;
        }
@@ -415,6 +405,8 @@ static const struct tty_operations moxa_ops = {
        .break_ctl = moxa_break_ctl,
        .tiocmget = moxa_tiocmget,
        .tiocmset = moxa_tiocmset,
+       .set_serial = moxa_set_serial_info,
+       .get_serial = moxa_get_serial_info,
 };
 
 static const struct tty_port_operations moxa_port_ops = {
@@ -2034,46 +2026,55 @@ static void MoxaPortTxEnable(struct moxa_port *port)
        moxafunc(port->tableAddr, FC_SetXonState, Magic_code);
 }
 
-static int moxa_get_serial_info(struct moxa_port *info,
-               struct serial_struct __user *retinfo)
+static int moxa_get_serial_info(struct tty_struct *tty,
+               struct serial_struct *ss)
 {
-       struct serial_struct tmp = {
-               .type = info->type,
-               .line = info->port.tty->index,
-               .flags = info->port.flags,
-               .baud_base = 921600,
-               .close_delay = info->port.close_delay
-       };
-       return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
+       struct moxa_port *info = tty->driver_data;
+
+       if (tty->index == MAX_PORTS)
+               return -EINVAL;
+       if (!info)
+               return -ENODEV;
+       mutex_lock(&info->port.mutex);
+       ss->type = info->type,
+       ss->line = info->port.tty->index,
+       ss->flags = info->port.flags,
+       ss->baud_base = 921600,
+       ss->close_delay = info->port.close_delay;
+       mutex_unlock(&info->port.mutex);
+       return 0;
 }
 
 
-static int moxa_set_serial_info(struct moxa_port *info,
-               struct serial_struct __user *new_info)
+static int moxa_set_serial_info(struct tty_struct *tty,
+               struct serial_struct *ss)
 {
-       struct serial_struct new_serial;
+       struct moxa_port *info = tty->driver_data;
 
-       if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
-               return -EFAULT;
+       if (tty->index == MAX_PORTS)
+               return -EINVAL;
+       if (!info)
+               return -ENODEV;
 
-       if (new_serial.irq != 0 || new_serial.port != 0 ||
-                       new_serial.custom_divisor != 0 ||
-                       new_serial.baud_base != 921600)
+       if (ss->irq != 0 || ss->port != 0 ||
+                       ss->custom_divisor != 0 ||
+                       ss->baud_base != 921600)
                return -EPERM;
 
+       mutex_lock(&info->port.mutex);
        if (!capable(CAP_SYS_ADMIN)) {
-               if (((new_serial.flags & ~ASYNC_USR_MASK) !=
-                    (info->port.flags & ~ASYNC_USR_MASK)))
+               if (((ss->flags & ~ASYNC_USR_MASK) !=
+                    (info->port.flags & ~ASYNC_USR_MASK))) {
+                       mutex_unlock(&info->port.mutex);
                        return -EPERM;
-       } else
-               info->port.close_delay = new_serial.close_delay * HZ / 100;
-
-       new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS);
-       new_serial.flags |= (info->port.flags & ASYNC_FLAGS);
+               }
+       }
+       info->port.close_delay = ss->close_delay * HZ / 100;
 
-       MoxaSetFifo(info, new_serial.type == PORT_16550A);
+       MoxaSetFifo(info, ss->type == PORT_16550A);
 
-       info->type = new_serial.type;
+       info->type = ss->type;
+       mutex_unlock(&info->port.mutex);
        return 0;
 }