Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

Al Viro 1c729ab1 b60f38c6

+40 -39
+40 -39
drivers/tty/moxa.c
··· 221 221 static int MoxaPortTxFree(struct moxa_port *); 222 222 static void MoxaPortTxDisable(struct moxa_port *); 223 223 static void MoxaPortTxEnable(struct moxa_port *); 224 - static int moxa_get_serial_info(struct moxa_port *, struct serial_struct __user *); 225 - static int moxa_set_serial_info(struct moxa_port *, struct serial_struct __user *); 224 + static int moxa_get_serial_info(struct tty_struct *, struct serial_struct *); 225 + static int moxa_set_serial_info(struct tty_struct *, struct serial_struct *); 226 226 static void MoxaSetFifo(struct moxa_port *port, int enable); 227 227 228 228 /* ··· 375 375 } 376 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 378 default: 389 379 ret = -ENOIOCTLCMD; 390 380 } ··· 405 415 .break_ctl = moxa_break_ctl, 406 416 .tiocmget = moxa_tiocmget, 407 417 .tiocmset = moxa_tiocmset, 418 + .set_serial = moxa_set_serial_info, 419 + .get_serial = moxa_get_serial_info, 408 420 }; 409 421 410 422 static const struct tty_port_operations moxa_port_ops = { ··· 2026 2034 moxafunc(port->tableAddr, FC_SetXonState, Magic_code); 2027 2035 } 2028 2036 2029 - static int moxa_get_serial_info(struct moxa_port *info, 2030 - struct serial_struct __user *retinfo) 2037 + static int moxa_get_serial_info(struct tty_struct *tty, 2038 + struct serial_struct *ss) 2031 2039 { 2032 - struct serial_struct tmp = { 2033 - .type = info->type, 2034 - .line = info->port.tty->index, 2035 - .flags = info->port.flags, 2036 - .baud_base = 921600, 2037 - .close_delay = info->port.close_delay 2038 - }; 2039 - return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0; 2040 + struct moxa_port *info = tty->driver_data; 2041 + 2042 + if (tty->index == MAX_PORTS) 2043 + return -EINVAL; 2044 + if (!info) 2045 + return -ENODEV; 2046 + mutex_lock(&info->port.mutex); 2047 + ss->type = info->type, 2048 + ss->line = info->port.tty->index, 2049 + ss->flags = info->port.flags, 2050 + ss->baud_base = 921600, 2051 + ss->close_delay = info->port.close_delay; 2052 + mutex_unlock(&info->port.mutex); 2053 + return 0; 2040 2054 } 2041 2055 2042 2056 2043 - static int moxa_set_serial_info(struct moxa_port *info, 2044 - struct serial_struct __user *new_info) 2057 + static int moxa_set_serial_info(struct tty_struct *tty, 2058 + struct serial_struct *ss) 2045 2059 { 2046 - struct serial_struct new_serial; 2060 + struct moxa_port *info = tty->driver_data; 2047 2061 2048 - if (copy_from_user(&new_serial, new_info, sizeof(new_serial))) 2049 - return -EFAULT; 2062 + if (tty->index == MAX_PORTS) 2063 + return -EINVAL; 2064 + if (!info) 2065 + return -ENODEV; 2050 2066 2051 - if (new_serial.irq != 0 || new_serial.port != 0 || 2052 - new_serial.custom_divisor != 0 || 2053 - new_serial.baud_base != 921600) 2067 + if (ss->irq != 0 || ss->port != 0 || 2068 + ss->custom_divisor != 0 || 2069 + ss->baud_base != 921600) 2054 2070 return -EPERM; 2055 2071 2072 + mutex_lock(&info->port.mutex); 2056 2073 if (!capable(CAP_SYS_ADMIN)) { 2057 - if (((new_serial.flags & ~ASYNC_USR_MASK) != 2058 - (info->port.flags & ~ASYNC_USR_MASK))) 2074 + if (((ss->flags & ~ASYNC_USR_MASK) != 2075 + (info->port.flags & ~ASYNC_USR_MASK))) { 2076 + mutex_unlock(&info->port.mutex); 2059 2077 return -EPERM; 2060 - } else 2061 - info->port.close_delay = new_serial.close_delay * HZ / 100; 2078 + } 2079 + } 2080 + info->port.close_delay = ss->close_delay * HZ / 100; 2062 2081 2063 - new_serial.flags = (new_serial.flags & ~ASYNC_FLAGS); 2064 - new_serial.flags |= (info->port.flags & ASYNC_FLAGS); 2082 + MoxaSetFifo(info, ss->type == PORT_16550A); 2065 2083 2066 - MoxaSetFifo(info, new_serial.type == PORT_16550A); 2067 - 2068 - info->type = new_serial.type; 2084 + info->type = ss->type; 2085 + mutex_unlock(&info->port.mutex); 2069 2086 return 0; 2070 2087 } 2071 2088