aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2008-02-07 03:16:45 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-07 11:42:34 -0500
commitf122bfb5a43c6b57733eb7a76ad4ed392be6a910 (patch)
treec16e50c8d703250da8028998a27ba93da5eb28db /drivers/char
parentf83bb2d40a879c21c5085ee8cfc426f9936901ee (diff)
Char: mxser, ioctl cleanup
- remove dead MOXA_GET_CONF (always returned -ENXIO) - remove useless MOXA_GET_CUMAJOR (unused) - use get/put_user instead of copy_from/to_user for simple types - cleanup TIOCMIWAIT -- return -ERESTARTSYS on signal, move condition into separate function Signed-off-by: Jiri Slaby <jirislaby@gmail.com> Cc: Alan Cox <alan@lxorguk.ukuu.org.uk> Reviewed-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')
-rw-r--r--drivers/char/mxser_new.c74
-rw-r--r--drivers/char/mxser_new.h2
2 files changed, 31 insertions, 45 deletions
diff --git a/drivers/char/mxser_new.c b/drivers/char/mxser_new.c
index 937c101db905..5c5d246a4261 100644
--- a/drivers/char/mxser_new.c
+++ b/drivers/char/mxser_new.c
@@ -175,7 +175,6 @@ MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
175 175
176static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 }; 176static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 };
177static int ttymajor = MXSERMAJOR; 177static int ttymajor = MXSERMAJOR;
178static int calloutmajor = MXSERCUMAJOR;
179 178
180/* Variables for insmod */ 179/* Variables for insmod */
181 180
@@ -1454,21 +1453,8 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1454 unsigned int i, j; 1453 unsigned int i, j;
1455 1454
1456 switch (cmd) { 1455 switch (cmd) {
1457 case MOXA_GET_CONF:
1458/* if (copy_to_user(argp, mxsercfg,
1459 sizeof(struct mxser_hwconf) * 4))
1460 return -EFAULT;
1461 return 0;*/
1462 return -ENXIO;
1463 case MOXA_GET_MAJOR: 1456 case MOXA_GET_MAJOR:
1464 if (copy_to_user(argp, &ttymajor, sizeof(int))) 1457 return put_user(ttymajor, (int __user *)argp);
1465 return -EFAULT;
1466 return 0;
1467
1468 case MOXA_GET_CUMAJOR:
1469 if (copy_to_user(argp, &calloutmajor, sizeof(int)))
1470 return -EFAULT;
1471 return 0;
1472 1458
1473 case MOXA_CHKPORTENABLE: 1459 case MOXA_CHKPORTENABLE:
1474 result = 0; 1460 result = 0;
@@ -1606,13 +1592,33 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1606 return 0; 1592 return 0;
1607} 1593}
1608 1594
1595static int mxser_cflags_changed(struct mxser_port *info, unsigned long arg,
1596 struct async_icount *cprev)
1597{
1598 struct async_icount cnow;
1599 unsigned long flags;
1600 int ret;
1601
1602 spin_lock_irqsave(&info->slock, flags);
1603 cnow = info->icount; /* atomic copy */
1604 spin_unlock_irqrestore(&info->slock, flags);
1605
1606 ret = ((arg & TIOCM_RNG) && (cnow.rng != cprev->rng)) ||
1607 ((arg & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) ||
1608 ((arg & TIOCM_CD) && (cnow.dcd != cprev->dcd)) ||
1609 ((arg & TIOCM_CTS) && (cnow.cts != cprev->cts));
1610
1611 *cprev = cnow;
1612
1613 return ret;
1614}
1615
1609static int mxser_ioctl(struct tty_struct *tty, struct file *file, 1616static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1610 unsigned int cmd, unsigned long arg) 1617 unsigned int cmd, unsigned long arg)
1611{ 1618{
1612 struct mxser_port *info = tty->driver_data; 1619 struct mxser_port *info = tty->driver_data;
1613 struct async_icount cprev, cnow; /* kernel counter temps */ 1620 struct async_icount cnow;
1614 struct serial_icounter_struct __user *p_cuser; 1621 struct serial_icounter_struct __user *p_cuser;
1615 unsigned long templ;
1616 unsigned long flags; 1622 unsigned long flags;
1617 void __user *argp = (void __user *)arg; 1623 void __user *argp = (void __user *)arg;
1618 int retval; 1624 int retval;
@@ -1646,7 +1652,7 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1646 shiftbit = p * 2; 1652 shiftbit = p * 2;
1647 opmode = inb(info->opmode_ioaddr) >> shiftbit; 1653 opmode = inb(info->opmode_ioaddr) >> shiftbit;
1648 opmode &= OP_MODE_MASK; 1654 opmode &= OP_MODE_MASK;
1649 if (copy_to_user(argp, &opmode, sizeof(int))) 1655 if (put_user(opmode, (int __user *)argp))
1650 return -EFAULT; 1656 return -EFAULT;
1651 } 1657 }
1652 return 0; 1658 return 0;
@@ -1673,11 +1679,10 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1673 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4); 1679 mxser_send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1674 return 0; 1680 return 0;
1675 case TIOCGSOFTCAR: 1681 case TIOCGSOFTCAR:
1676 return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp); 1682 return put_user(!!C_CLOCAL(tty), (unsigned long __user *)argp);
1677 case TIOCSSOFTCAR: 1683 case TIOCSSOFTCAR:
1678 if (get_user(templ, (unsigned long __user *) argp)) 1684 if (get_user(arg, (unsigned long __user *)argp))
1679 return -EFAULT; 1685 return -EFAULT;
1680 arg = templ;
1681 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0)); 1686 tty->termios->c_cflag = ((tty->termios->c_cflag & ~CLOCAL) | (arg ? CLOCAL : 0));
1682 return 0; 1687 return 0;
1683 case TIOCGSERIAL: 1688 case TIOCGSERIAL:
@@ -1697,18 +1702,8 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1697 cnow = info->icount; /* note the counters on entry */ 1702 cnow = info->icount; /* note the counters on entry */
1698 spin_unlock_irqrestore(&info->slock, flags); 1703 spin_unlock_irqrestore(&info->slock, flags);
1699 1704
1700 wait_event_interruptible(info->delta_msr_wait, ({ 1705 return wait_event_interruptible(info->delta_msr_wait,
1701 cprev = cnow; 1706 mxser_cflags_changed(info, arg, &cnow));
1702 spin_lock_irqsave(&info->slock, flags);
1703 cnow = info->icount; /* atomic copy */
1704 spin_unlock_irqrestore(&info->slock, flags);
1705
1706 ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
1707 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
1708 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
1709 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts));
1710 }));
1711 break;
1712 /* 1707 /*
1713 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) 1708 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
1714 * Return: write counters to the user passed counter struct 1709 * Return: write counters to the user passed counter struct
@@ -1755,10 +1750,7 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1755 1750
1756 len += (lsr ? 0 : 1); 1751 len += (lsr ? 0 : 1);
1757 1752
1758 if (copy_to_user(argp, &len, sizeof(int))) 1753 return put_user(len, (int __user *)argp);
1759 return -EFAULT;
1760
1761 return 0;
1762 } 1754 }
1763 case MOXA_ASPP_MON: { 1755 case MOXA_ASPP_MON: {
1764 int mcr, status; 1756 int mcr, status;
@@ -1789,8 +1781,7 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1789 return 0; 1781 return 0;
1790 } 1782 }
1791 case MOXA_ASPP_LSTATUS: { 1783 case MOXA_ASPP_LSTATUS: {
1792 if (copy_to_user(argp, &info->err_shadow, 1784 if (put_user(info->err_shadow, (unsigned char __user *)argp))
1793 sizeof(unsigned char)))
1794 return -EFAULT; 1785 return -EFAULT;
1795 1786
1796 info->err_shadow = 0; 1787 info->err_shadow = 0;
@@ -1802,10 +1793,7 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1802 if (get_user(method, (int __user *)argp)) 1793 if (get_user(method, (int __user *)argp))
1803 return -EFAULT; 1794 return -EFAULT;
1804 mxser_set_baud_method[tty->index] = method; 1795 mxser_set_baud_method[tty->index] = method;
1805 if (copy_to_user(argp, &method, sizeof(int))) 1796 return put_user(method, (int __user *)argp);
1806 return -EFAULT;
1807
1808 return 0;
1809 } 1797 }
1810 default: 1798 default:
1811 return -ENOIOCTLCMD; 1799 return -ENOIOCTLCMD;
diff --git a/drivers/char/mxser_new.h b/drivers/char/mxser_new.h
index 7f7b4a711cfc..844171115954 100644
--- a/drivers/char/mxser_new.h
+++ b/drivers/char/mxser_new.h
@@ -11,12 +11,10 @@
11 11
12#define MOXA 0x400 12#define MOXA 0x400
13#define MOXA_GETDATACOUNT (MOXA + 23) 13#define MOXA_GETDATACOUNT (MOXA + 23)
14#define MOXA_GET_CONF (MOXA + 35)
15#define MOXA_DIAGNOSE (MOXA + 50) 14#define MOXA_DIAGNOSE (MOXA + 50)
16#define MOXA_CHKPORTENABLE (MOXA + 60) 15#define MOXA_CHKPORTENABLE (MOXA + 60)
17#define MOXA_HighSpeedOn (MOXA + 61) 16#define MOXA_HighSpeedOn (MOXA + 61)
18#define MOXA_GET_MAJOR (MOXA + 63) 17#define MOXA_GET_MAJOR (MOXA + 63)
19#define MOXA_GET_CUMAJOR (MOXA + 64)
20#define MOXA_GETMSTATUS (MOXA + 65) 18#define MOXA_GETMSTATUS (MOXA + 65)
21#define MOXA_SET_OP_MODE (MOXA + 66) 19#define MOXA_SET_OP_MODE (MOXA + 66)
22#define MOXA_GET_OP_MODE (MOXA + 67) 20#define MOXA_GET_OP_MODE (MOXA + 67)