aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/mxser.c
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2008-07-25 04:48:20 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-25 13:53:43 -0400
commit72800df9ba3199df02a95b3830c49fbf16ec4a6d (patch)
tree0c51326b74d052134019735a3c0da76a13ae0068 /drivers/char/mxser.c
parent41aee9a121fd0c31ae22dfe57e8f9ee9d6d85c25 (diff)
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>
Diffstat (limited to 'drivers/char/mxser.c')
-rw-r--r--drivers/char/mxser.c130
1 files changed, 55 insertions, 75 deletions
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index e5029b149c5b..3d7f2a970495 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -286,8 +286,6 @@ struct mxser_mstatus {
286 int dcd; 286 int dcd;
287}; 287};
288 288
289static struct mxser_mstatus GMStatus[MXSER_PORTS];
290
291static int mxserBoardCAP[MXSER_BOARDS] = { 289static int mxserBoardCAP[MXSER_BOARDS] = {
292 0, 0, 0, 0 290 0, 0, 0, 0
293 /* 0x180, 0x280, 0x200, 0x320 */ 291 /* 0x180, 0x280, 0x200, 0x320 */
@@ -296,9 +294,6 @@ static int mxserBoardCAP[MXSER_BOARDS] = {
296static struct mxser_board mxser_boards[MXSER_BOARDS]; 294static struct mxser_board mxser_boards[MXSER_BOARDS];
297static struct tty_driver *mxvar_sdriver; 295static struct tty_driver *mxvar_sdriver;
298static struct mxser_log mxvar_log; 296static struct mxser_log mxvar_log;
299static int mxvar_diagflag;
300static unsigned char mxser_msr[MXSER_PORTS + 1];
301static struct mxser_mon_ext mon_data_ext;
302static int mxser_set_baud_method[MXSER_PORTS + 1]; 297static int mxser_set_baud_method[MXSER_PORTS + 1];
303 298
304static void mxser_enable_must_enchance_mode(unsigned long baseio) 299static void mxser_enable_must_enchance_mode(unsigned long baseio)
@@ -542,6 +537,7 @@ static void process_txrx_fifo(struct mxser_port *info)
542 537
543static unsigned char mxser_get_msr(int baseaddr, int mode, int port) 538static unsigned char mxser_get_msr(int baseaddr, int mode, int port)
544{ 539{
540 static unsigned char mxser_msr[MXSER_PORTS + 1];
545 unsigned char status = 0; 541 unsigned char status = 0;
546 542
547 status = inb(baseaddr + UART_MSR); 543 status = inb(baseaddr + UART_MSR);
@@ -1652,62 +1648,60 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1652 ret = -EFAULT; 1648 ret = -EFAULT;
1653 unlock_kernel(); 1649 unlock_kernel();
1654 return ret; 1650 return ret;
1655 case MOXA_GETMSTATUS: 1651 case MOXA_GETMSTATUS: {
1652 struct mxser_mstatus ms, __user *msu = argp;
1656 lock_kernel(); 1653 lock_kernel();
1657 for (i = 0; i < MXSER_BOARDS; i++) 1654 for (i = 0; i < MXSER_BOARDS; i++)
1658 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) { 1655 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) {
1659 port = &mxser_boards[i].ports[j]; 1656 port = &mxser_boards[i].ports[j];
1657 memset(&ms, 0, sizeof(ms));
1660 1658
1661 GMStatus[i].ri = 0; 1659 if (!port->ioaddr)
1662 if (!port->ioaddr) { 1660 goto copy;
1663 GMStatus[i].dcd = 0;
1664 GMStatus[i].dsr = 0;
1665 GMStatus[i].cts = 0;
1666 continue;
1667 }
1668 1661
1669 if (!port->port.tty || !port->port.tty->termios) 1662 if (!port->port.tty || !port->port.tty->termios)
1670 GMStatus[i].cflag = 1663 ms.cflag = port->normal_termios.c_cflag;
1671 port->normal_termios.c_cflag;
1672 else 1664 else
1673 GMStatus[i].cflag = 1665 ms.cflag = port->port.tty->termios->c_cflag;
1674 port->port.tty->termios->c_cflag;
1675 1666
1676 status = inb(port->ioaddr + UART_MSR); 1667 status = inb(port->ioaddr + UART_MSR);
1677 if (status & 0x80 /*UART_MSR_DCD */ ) 1668 if (status & UART_MSR_DCD)
1678 GMStatus[i].dcd = 1; 1669 ms.dcd = 1;
1679 else 1670 if (status & UART_MSR_DSR)
1680 GMStatus[i].dcd = 0; 1671 ms.dsr = 1;
1681 1672 if (status & UART_MSR_CTS)
1682 if (status & 0x20 /*UART_MSR_DSR */ ) 1673 ms.cts = 1;
1683 GMStatus[i].dsr = 1; 1674 copy:
1684 else 1675 if (copy_to_user(msu, &ms, sizeof(ms))) {
1685 GMStatus[i].dsr = 0; 1676 unlock_kernel();
1686 1677 return -EFAULT;
1687 1678 }
1688 if (status & 0x10 /*UART_MSR_CTS */ ) 1679 msu++;
1689 GMStatus[i].cts = 1;
1690 else
1691 GMStatus[i].cts = 0;
1692 } 1680 }
1693 unlock_kernel(); 1681 unlock_kernel();
1694 if (copy_to_user(argp, GMStatus,
1695 sizeof(struct mxser_mstatus) * MXSER_PORTS))
1696 return -EFAULT;
1697 return 0; 1682 return 0;
1683 }
1698 case MOXA_ASPP_MON_EXT: { 1684 case MOXA_ASPP_MON_EXT: {
1699 int p, shiftbit; 1685 struct mxser_mon_ext *me; /* it's 2k, stack unfriendly */
1700 unsigned long opmode; 1686 unsigned int cflag, iflag, p;
1701 unsigned cflag, iflag; 1687 u8 opmode;
1688
1689 me = kzalloc(sizeof(*me), GFP_KERNEL);
1690 if (!me)
1691 return -ENOMEM;
1702 1692
1703 lock_kernel(); 1693 lock_kernel();
1704 for (i = 0; i < MXSER_BOARDS; i++) { 1694 for (i = 0, p = 0; i < MXSER_BOARDS; i++) {
1705 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++) { 1695 for (j = 0; j < MXSER_PORTS_PER_BOARD; j++, p++) {
1696 if (p >= ARRAY_SIZE(me->rx_cnt)) {
1697 i = MXSER_BOARDS;
1698 break;
1699 }
1706 port = &mxser_boards[i].ports[j]; 1700 port = &mxser_boards[i].ports[j];
1707 if (!port->ioaddr) 1701 if (!port->ioaddr)
1708 continue; 1702 continue;
1709 1703
1710 status = mxser_get_msr(port->ioaddr, 0, i); 1704 status = mxser_get_msr(port->ioaddr, 0, p);
1711 1705
1712 if (status & UART_MSR_TERI) 1706 if (status & UART_MSR_TERI)
1713 port->icount.rng++; 1707 port->icount.rng++;
@@ -1719,16 +1713,13 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1719 port->icount.cts++; 1713 port->icount.cts++;
1720 1714
1721 port->mon_data.modem_status = status; 1715 port->mon_data.modem_status = status;
1722 mon_data_ext.rx_cnt[i] = port->mon_data.rxcnt; 1716 me->rx_cnt[p] = port->mon_data.rxcnt;
1723 mon_data_ext.tx_cnt[i] = port->mon_data.txcnt; 1717 me->tx_cnt[p] = port->mon_data.txcnt;
1724 mon_data_ext.up_rxcnt[i] = 1718 me->up_rxcnt[p] = port->mon_data.up_rxcnt;
1725 port->mon_data.up_rxcnt; 1719 me->up_txcnt[p] = port->mon_data.up_txcnt;
1726 mon_data_ext.up_txcnt[i] = 1720 me->modem_status[p] =
1727 port->mon_data.up_txcnt;
1728 mon_data_ext.modem_status[i] =
1729 port->mon_data.modem_status; 1721 port->mon_data.modem_status;
1730 mon_data_ext.baudrate[i] = 1722 me->baudrate[p] = tty_get_baud_rate(port->port.tty);
1731 tty_get_baud_rate(port->port.tty);
1732 1723
1733 if (!port->port.tty || !port->port.tty->termios) { 1724 if (!port->port.tty || !port->port.tty->termios) {
1734 cflag = port->normal_termios.c_cflag; 1725 cflag = port->normal_termios.c_cflag;
@@ -1738,40 +1729,31 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1738 iflag = port->port.tty->termios->c_iflag; 1729 iflag = port->port.tty->termios->c_iflag;
1739 } 1730 }
1740 1731
1741 mon_data_ext.databits[i] = cflag & CSIZE; 1732 me->databits[p] = cflag & CSIZE;
1742 1733 me->stopbits[p] = cflag & CSTOPB;
1743 mon_data_ext.stopbits[i] = cflag & CSTOPB; 1734 me->parity[p] = cflag & (PARENB | PARODD |
1744 1735 CMSPAR);
1745 mon_data_ext.parity[i] =
1746 cflag & (PARENB | PARODD | CMSPAR);
1747
1748 mon_data_ext.flowctrl[i] = 0x00;
1749 1736
1750 if (cflag & CRTSCTS) 1737 if (cflag & CRTSCTS)
1751 mon_data_ext.flowctrl[i] |= 0x03; 1738 me->flowctrl[p] |= 0x03;
1752 1739
1753 if (iflag & (IXON | IXOFF)) 1740 if (iflag & (IXON | IXOFF))
1754 mon_data_ext.flowctrl[i] |= 0x0C; 1741 me->flowctrl[p] |= 0x0C;
1755 1742
1756 if (port->type == PORT_16550A) 1743 if (port->type == PORT_16550A)
1757 mon_data_ext.fifo[i] = 1; 1744 me->fifo[p] = 1;
1758 else
1759 mon_data_ext.fifo[i] = 0;
1760 1745
1761 p = i % 4; 1746 opmode = inb(port->opmode_ioaddr) >>
1762 shiftbit = p * 2; 1747 ((p % 4) * 2);
1763 opmode = inb(port->opmode_ioaddr) >> shiftbit;
1764 opmode &= OP_MODE_MASK; 1748 opmode &= OP_MODE_MASK;
1765 1749 me->iftype[p] = opmode;
1766 mon_data_ext.iftype[i] = opmode;
1767
1768 } 1750 }
1769 } 1751 }
1770 unlock_kernel(); 1752 unlock_kernel();
1771 if (copy_to_user(argp, &mon_data_ext, 1753 if (copy_to_user(argp, me, sizeof(*me)))
1772 sizeof(mon_data_ext))) 1754 ret = -EFAULT;
1773 return -EFAULT; 1755 kfree(me);
1774 return 0; 1756 return ret;
1775 } 1757 }
1776 default: 1758 default:
1777 return -ENOIOCTLCMD; 1759 return -ENOIOCTLCMD;
@@ -2802,8 +2784,6 @@ static int __init mxser_module_init(void)
2802 goto err_put; 2784 goto err_put;
2803 } 2785 }
2804 2786
2805 mxvar_diagflag = 0;
2806
2807 m = 0; 2787 m = 0;
2808 /* Start finding ISA boards here */ 2788 /* Start finding ISA boards here */
2809 for (isaloop = 0; isaloop < 2; isaloop++) 2789 for (isaloop = 0; isaloop < 2; isaloop++)