| .. | .. |
|---|
| 638 | 638 | * This routine is called to set the UART divisor registers to match |
|---|
| 639 | 639 | * the specified baud rate for a serial port. |
|---|
| 640 | 640 | */ |
|---|
| 641 | | -static int mxser_change_speed(struct tty_struct *tty) |
|---|
| 641 | +static void mxser_change_speed(struct tty_struct *tty) |
|---|
| 642 | 642 | { |
|---|
| 643 | 643 | struct mxser_port *info = tty->driver_data; |
|---|
| 644 | 644 | unsigned cflag, cval, fcr; |
|---|
| 645 | | - int ret = 0; |
|---|
| 646 | 645 | unsigned char status; |
|---|
| 647 | 646 | |
|---|
| 648 | 647 | cflag = tty->termios.c_cflag; |
|---|
| 649 | 648 | if (!info->ioaddr) |
|---|
| 650 | | - return ret; |
|---|
| 649 | + return; |
|---|
| 651 | 650 | |
|---|
| 652 | 651 | if (mxser_set_baud_method[tty->index] == 0) |
|---|
| 653 | 652 | mxser_set_baud(tty, tty_get_baud_rate(tty)); |
|---|
| .. | .. |
|---|
| 803 | 802 | |
|---|
| 804 | 803 | outb(fcr, info->ioaddr + UART_FCR); /* set fcr */ |
|---|
| 805 | 804 | outb(cval, info->ioaddr + UART_LCR); |
|---|
| 806 | | - |
|---|
| 807 | | - return ret; |
|---|
| 808 | 805 | } |
|---|
| 809 | 806 | |
|---|
| 810 | 807 | static void mxser_check_modem_status(struct tty_struct *tty, |
|---|
| .. | .. |
|---|
| 861 | 858 | struct mxser_port *info = container_of(port, struct mxser_port, port); |
|---|
| 862 | 859 | unsigned long page; |
|---|
| 863 | 860 | unsigned long flags; |
|---|
| 861 | + int ret; |
|---|
| 864 | 862 | |
|---|
| 865 | 863 | page = __get_free_page(GFP_KERNEL); |
|---|
| 866 | 864 | if (!page) |
|---|
| .. | .. |
|---|
| 870 | 868 | |
|---|
| 871 | 869 | if (!info->ioaddr || !info->type) { |
|---|
| 872 | 870 | set_bit(TTY_IO_ERROR, &tty->flags); |
|---|
| 873 | | - free_page(page); |
|---|
| 874 | 871 | spin_unlock_irqrestore(&info->slock, flags); |
|---|
| 875 | | - return 0; |
|---|
| 872 | + ret = 0; |
|---|
| 873 | + goto err_free_xmit; |
|---|
| 876 | 874 | } |
|---|
| 877 | 875 | info->port.xmit_buf = (unsigned char *) page; |
|---|
| 878 | 876 | |
|---|
| .. | .. |
|---|
| 898 | 896 | if (capable(CAP_SYS_ADMIN)) { |
|---|
| 899 | 897 | set_bit(TTY_IO_ERROR, &tty->flags); |
|---|
| 900 | 898 | return 0; |
|---|
| 901 | | - } else |
|---|
| 902 | | - return -ENODEV; |
|---|
| 899 | + } |
|---|
| 900 | + |
|---|
| 901 | + ret = -ENODEV; |
|---|
| 902 | + goto err_free_xmit; |
|---|
| 903 | 903 | } |
|---|
| 904 | 904 | |
|---|
| 905 | 905 | /* |
|---|
| .. | .. |
|---|
| 944 | 944 | spin_unlock_irqrestore(&info->slock, flags); |
|---|
| 945 | 945 | |
|---|
| 946 | 946 | return 0; |
|---|
| 947 | +err_free_xmit: |
|---|
| 948 | + free_page(page); |
|---|
| 949 | + info->port.xmit_buf = NULL; |
|---|
| 950 | + return ret; |
|---|
| 947 | 951 | } |
|---|
| 948 | 952 | |
|---|
| 949 | 953 | /* |
|---|
| .. | .. |
|---|
| 1207 | 1211 | * ------------------------------------------------------------ |
|---|
| 1208 | 1212 | */ |
|---|
| 1209 | 1213 | static int mxser_get_serial_info(struct tty_struct *tty, |
|---|
| 1210 | | - struct serial_struct __user *retinfo) |
|---|
| 1214 | + struct serial_struct *ss) |
|---|
| 1211 | 1215 | { |
|---|
| 1212 | 1216 | struct mxser_port *info = tty->driver_data; |
|---|
| 1213 | | - struct serial_struct tmp = { |
|---|
| 1214 | | - .type = info->type, |
|---|
| 1215 | | - .line = tty->index, |
|---|
| 1216 | | - .port = info->ioaddr, |
|---|
| 1217 | | - .irq = info->board->irq, |
|---|
| 1218 | | - .flags = info->port.flags, |
|---|
| 1219 | | - .baud_base = info->baud_base, |
|---|
| 1220 | | - .close_delay = info->port.close_delay, |
|---|
| 1221 | | - .closing_wait = info->port.closing_wait, |
|---|
| 1222 | | - .custom_divisor = info->custom_divisor, |
|---|
| 1223 | | - }; |
|---|
| 1224 | | - if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) |
|---|
| 1225 | | - return -EFAULT; |
|---|
| 1217 | + struct tty_port *port = &info->port; |
|---|
| 1218 | + |
|---|
| 1219 | + if (tty->index == MXSER_PORTS) |
|---|
| 1220 | + return -ENOTTY; |
|---|
| 1221 | + |
|---|
| 1222 | + mutex_lock(&port->mutex); |
|---|
| 1223 | + ss->type = info->type, |
|---|
| 1224 | + ss->line = tty->index, |
|---|
| 1225 | + ss->port = info->ioaddr, |
|---|
| 1226 | + ss->irq = info->board->irq, |
|---|
| 1227 | + ss->flags = info->port.flags, |
|---|
| 1228 | + ss->baud_base = info->baud_base, |
|---|
| 1229 | + ss->close_delay = info->port.close_delay, |
|---|
| 1230 | + ss->closing_wait = info->port.closing_wait, |
|---|
| 1231 | + ss->custom_divisor = info->custom_divisor, |
|---|
| 1232 | + mutex_unlock(&port->mutex); |
|---|
| 1226 | 1233 | return 0; |
|---|
| 1227 | 1234 | } |
|---|
| 1228 | 1235 | |
|---|
| 1229 | 1236 | static int mxser_set_serial_info(struct tty_struct *tty, |
|---|
| 1230 | | - struct serial_struct __user *new_info) |
|---|
| 1237 | + struct serial_struct *ss) |
|---|
| 1231 | 1238 | { |
|---|
| 1232 | 1239 | struct mxser_port *info = tty->driver_data; |
|---|
| 1233 | 1240 | struct tty_port *port = &info->port; |
|---|
| 1234 | | - struct serial_struct new_serial; |
|---|
| 1235 | 1241 | speed_t baud; |
|---|
| 1236 | 1242 | unsigned long sl_flags; |
|---|
| 1237 | 1243 | unsigned int flags; |
|---|
| 1238 | 1244 | int retval = 0; |
|---|
| 1239 | 1245 | |
|---|
| 1240 | | - if (!new_info || !info->ioaddr) |
|---|
| 1241 | | - return -ENODEV; |
|---|
| 1242 | | - if (copy_from_user(&new_serial, new_info, sizeof(new_serial))) |
|---|
| 1243 | | - return -EFAULT; |
|---|
| 1246 | + if (tty->index == MXSER_PORTS) |
|---|
| 1247 | + return -ENOTTY; |
|---|
| 1248 | + if (tty_io_error(tty)) |
|---|
| 1249 | + return -EIO; |
|---|
| 1244 | 1250 | |
|---|
| 1245 | | - if (new_serial.irq != info->board->irq || |
|---|
| 1246 | | - new_serial.port != info->ioaddr) |
|---|
| 1251 | + mutex_lock(&port->mutex); |
|---|
| 1252 | + if (!info->ioaddr) { |
|---|
| 1253 | + mutex_unlock(&port->mutex); |
|---|
| 1254 | + return -ENODEV; |
|---|
| 1255 | + } |
|---|
| 1256 | + |
|---|
| 1257 | + if (ss->irq != info->board->irq || |
|---|
| 1258 | + ss->port != info->ioaddr) { |
|---|
| 1259 | + mutex_unlock(&port->mutex); |
|---|
| 1247 | 1260 | return -EINVAL; |
|---|
| 1261 | + } |
|---|
| 1248 | 1262 | |
|---|
| 1249 | 1263 | flags = port->flags & ASYNC_SPD_MASK; |
|---|
| 1250 | 1264 | |
|---|
| 1251 | 1265 | if (!capable(CAP_SYS_ADMIN)) { |
|---|
| 1252 | | - if ((new_serial.baud_base != info->baud_base) || |
|---|
| 1253 | | - (new_serial.close_delay != info->port.close_delay) || |
|---|
| 1254 | | - ((new_serial.flags & ~ASYNC_USR_MASK) != (info->port.flags & ~ASYNC_USR_MASK))) |
|---|
| 1266 | + if ((ss->baud_base != info->baud_base) || |
|---|
| 1267 | + (ss->close_delay != info->port.close_delay) || |
|---|
| 1268 | + ((ss->flags & ~ASYNC_USR_MASK) != (info->port.flags & ~ASYNC_USR_MASK))) { |
|---|
| 1269 | + mutex_unlock(&port->mutex); |
|---|
| 1255 | 1270 | return -EPERM; |
|---|
| 1271 | + } |
|---|
| 1256 | 1272 | info->port.flags = ((info->port.flags & ~ASYNC_USR_MASK) | |
|---|
| 1257 | | - (new_serial.flags & ASYNC_USR_MASK)); |
|---|
| 1273 | + (ss->flags & ASYNC_USR_MASK)); |
|---|
| 1258 | 1274 | } else { |
|---|
| 1259 | 1275 | /* |
|---|
| 1260 | 1276 | * OK, past this point, all the error checking has been done. |
|---|
| 1261 | 1277 | * At this point, we start making changes..... |
|---|
| 1262 | 1278 | */ |
|---|
| 1263 | 1279 | port->flags = ((port->flags & ~ASYNC_FLAGS) | |
|---|
| 1264 | | - (new_serial.flags & ASYNC_FLAGS)); |
|---|
| 1265 | | - port->close_delay = new_serial.close_delay * HZ / 100; |
|---|
| 1266 | | - port->closing_wait = new_serial.closing_wait * HZ / 100; |
|---|
| 1280 | + (ss->flags & ASYNC_FLAGS)); |
|---|
| 1281 | + port->close_delay = ss->close_delay * HZ / 100; |
|---|
| 1282 | + port->closing_wait = ss->closing_wait * HZ / 100; |
|---|
| 1267 | 1283 | port->low_latency = (port->flags & ASYNC_LOW_LATENCY) ? 1 : 0; |
|---|
| 1268 | 1284 | if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST && |
|---|
| 1269 | | - (new_serial.baud_base != info->baud_base || |
|---|
| 1270 | | - new_serial.custom_divisor != |
|---|
| 1285 | + (ss->baud_base != info->baud_base || |
|---|
| 1286 | + ss->custom_divisor != |
|---|
| 1271 | 1287 | info->custom_divisor)) { |
|---|
| 1272 | | - if (new_serial.custom_divisor == 0) |
|---|
| 1288 | + if (ss->custom_divisor == 0) { |
|---|
| 1289 | + mutex_unlock(&port->mutex); |
|---|
| 1273 | 1290 | return -EINVAL; |
|---|
| 1274 | | - baud = new_serial.baud_base / new_serial.custom_divisor; |
|---|
| 1291 | + } |
|---|
| 1292 | + baud = ss->baud_base / ss->custom_divisor; |
|---|
| 1275 | 1293 | tty_encode_baud_rate(tty, baud, baud); |
|---|
| 1276 | 1294 | } |
|---|
| 1277 | 1295 | } |
|---|
| 1278 | 1296 | |
|---|
| 1279 | | - info->type = new_serial.type; |
|---|
| 1297 | + info->type = ss->type; |
|---|
| 1280 | 1298 | |
|---|
| 1281 | 1299 | process_txrx_fifo(info); |
|---|
| 1282 | 1300 | |
|---|
| .. | .. |
|---|
| 1291 | 1309 | if (retval == 0) |
|---|
| 1292 | 1310 | tty_port_set_initialized(port, 1); |
|---|
| 1293 | 1311 | } |
|---|
| 1312 | + mutex_unlock(&port->mutex); |
|---|
| 1294 | 1313 | return retval; |
|---|
| 1295 | 1314 | } |
|---|
| 1296 | 1315 | |
|---|
| .. | .. |
|---|
| 1660 | 1679 | unsigned int cmd, unsigned long arg) |
|---|
| 1661 | 1680 | { |
|---|
| 1662 | 1681 | struct mxser_port *info = tty->driver_data; |
|---|
| 1663 | | - struct tty_port *port = &info->port; |
|---|
| 1664 | 1682 | struct async_icount cnow; |
|---|
| 1665 | 1683 | unsigned long flags; |
|---|
| 1666 | 1684 | void __user *argp = (void __user *)arg; |
|---|
| 1667 | | - int retval; |
|---|
| 1668 | 1685 | |
|---|
| 1669 | 1686 | if (tty->index == MXSER_PORTS) |
|---|
| 1670 | 1687 | return mxser_ioctl_special(cmd, argp); |
|---|
| .. | .. |
|---|
| 1708 | 1725 | return 0; |
|---|
| 1709 | 1726 | } |
|---|
| 1710 | 1727 | |
|---|
| 1711 | | - if (cmd != TIOCGSERIAL && cmd != TIOCMIWAIT && tty_io_error(tty)) |
|---|
| 1728 | + if (cmd != TIOCMIWAIT && tty_io_error(tty)) |
|---|
| 1712 | 1729 | return -EIO; |
|---|
| 1713 | 1730 | |
|---|
| 1714 | 1731 | switch (cmd) { |
|---|
| 1715 | | - case TIOCGSERIAL: |
|---|
| 1716 | | - mutex_lock(&port->mutex); |
|---|
| 1717 | | - retval = mxser_get_serial_info(tty, argp); |
|---|
| 1718 | | - mutex_unlock(&port->mutex); |
|---|
| 1719 | | - return retval; |
|---|
| 1720 | | - case TIOCSSERIAL: |
|---|
| 1721 | | - mutex_lock(&port->mutex); |
|---|
| 1722 | | - retval = mxser_set_serial_info(tty, argp); |
|---|
| 1723 | | - mutex_unlock(&port->mutex); |
|---|
| 1724 | | - return retval; |
|---|
| 1725 | 1732 | case TIOCSERGETLSR: /* Get line status register */ |
|---|
| 1726 | 1733 | return mxser_get_lsr_info(info, argp); |
|---|
| 1727 | 1734 | /* |
|---|
| .. | .. |
|---|
| 2325 | 2332 | .wait_until_sent = mxser_wait_until_sent, |
|---|
| 2326 | 2333 | .tiocmget = mxser_tiocmget, |
|---|
| 2327 | 2334 | .tiocmset = mxser_tiocmset, |
|---|
| 2335 | + .set_serial = mxser_set_serial_info, |
|---|
| 2336 | + .get_serial = mxser_get_serial_info, |
|---|
| 2328 | 2337 | .get_icount = mxser_get_icount, |
|---|
| 2329 | 2338 | }; |
|---|
| 2330 | 2339 | |
|---|