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

Char: mxser, globals cleanup

- remove unused mxvar_diagflag
- move mxser_msr into the only user/function
- GMStatus, hmm, fix race-prone access to it. We need only one instance for
real, not MXSER_PORTS. Move it to MOXA_GETMSTATUS ioctl.
- mxser_mon_ext, almost the same, but alloc it on heap, since it has more than
2 kilos.
- fix indexing, `i' is not the index value, `i * MXSER_PORTS_PER_BOARD + j' is

Signed-off-by: Jiri Slaby <jirislaby@gmail.com>
Acked-by: Alan Cox <alan@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Jiri Slaby and committed by
Linus Torvalds
72800df9 41aee9a1

+55 -75
+55 -75
drivers/char/mxser.c
··· 286 286 int dcd; 287 287 }; 288 288 289 - static struct mxser_mstatus GMStatus[MXSER_PORTS]; 290 - 291 289 static int mxserBoardCAP[MXSER_BOARDS] = { 292 290 0, 0, 0, 0 293 291 /* 0x180, 0x280, 0x200, 0x320 */ ··· 294 296 static struct mxser_board mxser_boards[MXSER_BOARDS]; 295 297 static struct tty_driver *mxvar_sdriver; 296 298 static struct mxser_log mxvar_log; 297 - static int mxvar_diagflag; 298 - static unsigned char mxser_msr[MXSER_PORTS + 1]; 299 - static struct mxser_mon_ext mon_data_ext; 300 299 static int mxser_set_baud_method[MXSER_PORTS + 1]; 301 300 302 301 static void mxser_enable_must_enchance_mode(unsigned long baseio) ··· 537 542 538 543 static unsigned char mxser_get_msr(int baseaddr, int mode, int port) 539 544 { 545 + static unsigned char mxser_msr[MXSER_PORTS + 1]; 540 546 unsigned char status = 0; 541 547 542 548 status = inb(baseaddr + UART_MSR); ··· 1648 1652 ret = -EFAULT; 1649 1653 unlock_kernel(); 1650 1654 return ret; 1651 - case MOXA_GETMSTATUS: 1655 + case MOXA_GETMSTATUS: { 1656 + struct mxser_mstatus ms, __user *msu = argp; 1652 1657 lock_kernel(); 1653 1658 for (i = 0; i < MXSER_BOARDS; i++) 1654 1659 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) { 1655 1660 port = &mxser_boards[i].ports[j]; 1661 + memset(&ms, 0, sizeof(ms)); 1656 1662 1657 - GMStatus[i].ri = 0; 1658 - if (!port->ioaddr) { 1659 - GMStatus[i].dcd = 0; 1660 - GMStatus[i].dsr = 0; 1661 - GMStatus[i].cts = 0; 1662 - continue; 1663 - } 1663 + if (!port->ioaddr) 1664 + goto copy; 1664 1665 1665 1666 if (!port->port.tty || !port->port.tty->termios) 1666 - GMStatus[i].cflag = 1667 - port->normal_termios.c_cflag; 1667 + ms.cflag = port->normal_termios.c_cflag; 1668 1668 else 1669 - GMStatus[i].cflag = 1670 - port->port.tty->termios->c_cflag; 1669 + ms.cflag = port->port.tty->termios->c_cflag; 1671 1670 1672 1671 status = inb(port->ioaddr + UART_MSR); 1673 - if (status & 0x80 /*UART_MSR_DCD */ ) 1674 - GMStatus[i].dcd = 1; 1675 - else 1676 - GMStatus[i].dcd = 0; 1677 - 1678 - if (status & 0x20 /*UART_MSR_DSR */ ) 1679 - GMStatus[i].dsr = 1; 1680 - else 1681 - GMStatus[i].dsr = 0; 1682 - 1683 - 1684 - if (status & 0x10 /*UART_MSR_CTS */ ) 1685 - GMStatus[i].cts = 1; 1686 - else 1687 - GMStatus[i].cts = 0; 1672 + if (status & UART_MSR_DCD) 1673 + ms.dcd = 1; 1674 + if (status & UART_MSR_DSR) 1675 + ms.dsr = 1; 1676 + if (status & UART_MSR_CTS) 1677 + ms.cts = 1; 1678 + copy: 1679 + if (copy_to_user(msu, &ms, sizeof(ms))) { 1680 + unlock_kernel(); 1681 + return -EFAULT; 1682 + } 1683 + msu++; 1688 1684 } 1689 1685 unlock_kernel(); 1690 - if (copy_to_user(argp, GMStatus, 1691 - sizeof(struct mxser_mstatus) * MXSER_PORTS)) 1692 - return -EFAULT; 1693 1686 return 0; 1687 + } 1694 1688 case MOXA_ASPP_MON_EXT: { 1695 - int p, shiftbit; 1696 - unsigned long opmode; 1697 - unsigned cflag, iflag; 1689 + struct mxser_mon_ext *me; /* it's 2k, stack unfriendly */ 1690 + unsigned int cflag, iflag, p; 1691 + u8 opmode; 1692 + 1693 + me = kzalloc(sizeof(*me), GFP_KERNEL); 1694 + if (!me) 1695 + return -ENOMEM; 1698 1696 1699 1697 lock_kernel(); 1700 - for (i = 0; i < MXSER_BOARDS; i++) { 1701 - for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) { 1698 + for (i = 0, p = 0; i < MXSER_BOARDS; i++) { 1699 + for (j = 0; j < MXSER_PORTS_PER_BOARD; j++, p++) { 1700 + if (p >= ARRAY_SIZE(me->rx_cnt)) { 1701 + i = MXSER_BOARDS; 1702 + break; 1703 + } 1702 1704 port = &mxser_boards[i].ports[j]; 1703 1705 if (!port->ioaddr) 1704 1706 continue; 1705 1707 1706 - status = mxser_get_msr(port->ioaddr, 0, i); 1708 + status = mxser_get_msr(port->ioaddr, 0, p); 1707 1709 1708 1710 if (status & UART_MSR_TERI) 1709 1711 port->icount.rng++; ··· 1713 1719 port->icount.cts++; 1714 1720 1715 1721 port->mon_data.modem_status = status; 1716 - mon_data_ext.rx_cnt[i] = port->mon_data.rxcnt; 1717 - mon_data_ext.tx_cnt[i] = port->mon_data.txcnt; 1718 - mon_data_ext.up_rxcnt[i] = 1719 - port->mon_data.up_rxcnt; 1720 - mon_data_ext.up_txcnt[i] = 1721 - port->mon_data.up_txcnt; 1722 - mon_data_ext.modem_status[i] = 1722 + me->rx_cnt[p] = port->mon_data.rxcnt; 1723 + me->tx_cnt[p] = port->mon_data.txcnt; 1724 + me->up_rxcnt[p] = port->mon_data.up_rxcnt; 1725 + me->up_txcnt[p] = port->mon_data.up_txcnt; 1726 + me->modem_status[p] = 1723 1727 port->mon_data.modem_status; 1724 - mon_data_ext.baudrate[i] = 1725 - tty_get_baud_rate(port->port.tty); 1728 + me->baudrate[p] = tty_get_baud_rate(port->port.tty); 1726 1729 1727 1730 if (!port->port.tty || !port->port.tty->termios) { 1728 1731 cflag = port->normal_termios.c_cflag; ··· 1729 1738 iflag = port->port.tty->termios->c_iflag; 1730 1739 } 1731 1740 1732 - mon_data_ext.databits[i] = cflag & CSIZE; 1733 - 1734 - mon_data_ext.stopbits[i] = cflag & CSTOPB; 1735 - 1736 - mon_data_ext.parity[i] = 1737 - cflag & (PARENB | PARODD | CMSPAR); 1738 - 1739 - mon_data_ext.flowctrl[i] = 0x00; 1741 + me->databits[p] = cflag & CSIZE; 1742 + me->stopbits[p] = cflag & CSTOPB; 1743 + me->parity[p] = cflag & (PARENB | PARODD | 1744 + CMSPAR); 1740 1745 1741 1746 if (cflag & CRTSCTS) 1742 - mon_data_ext.flowctrl[i] |= 0x03; 1747 + me->flowctrl[p] |= 0x03; 1743 1748 1744 1749 if (iflag & (IXON | IXOFF)) 1745 - mon_data_ext.flowctrl[i] |= 0x0C; 1750 + me->flowctrl[p] |= 0x0C; 1746 1751 1747 1752 if (port->type == PORT_16550A) 1748 - mon_data_ext.fifo[i] = 1; 1749 - else 1750 - mon_data_ext.fifo[i] = 0; 1753 + me->fifo[p] = 1; 1751 1754 1752 - p = i % 4; 1753 - shiftbit = p * 2; 1754 - opmode = inb(port->opmode_ioaddr) >> shiftbit; 1755 + opmode = inb(port->opmode_ioaddr) >> 1756 + ((p % 4) * 2); 1755 1757 opmode &= OP_MODE_MASK; 1756 - 1757 - mon_data_ext.iftype[i] = opmode; 1758 - 1758 + me->iftype[p] = opmode; 1759 1759 } 1760 1760 } 1761 1761 unlock_kernel(); 1762 - if (copy_to_user(argp, &mon_data_ext, 1763 - sizeof(mon_data_ext))) 1764 - return -EFAULT; 1765 - return 0; 1762 + if (copy_to_user(argp, me, sizeof(*me))) 1763 + ret = -EFAULT; 1764 + kfree(me); 1765 + return ret; 1766 1766 } 1767 1767 default: 1768 1768 return -ENOIOCTLCMD; ··· 2783 2801 "tty driver !\n"); 2784 2802 goto err_put; 2785 2803 } 2786 - 2787 - mxvar_diagflag = 0; 2788 2804 2789 2805 m = 0; 2790 2806 /* Start finding ISA boards here */