nfsd: move most of nfsfh.h to fs/nfsd
[safe/jmp/linux-2.6] / drivers / char / moxa.c
index 8b0da97..dd0083b 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
 #include <linux/major.h>
+#include <linux/smp_lock.h>
 #include <linux/string.h>
 #include <linux/fcntl.h>
 #include <linux/ptrace.h>
@@ -1184,6 +1185,11 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
                return -ENODEV;
        }
 
+       if (port % MAX_PORTS_PER_BOARD >= brd->numPorts) {
+               mutex_unlock(&moxa_openlock);
+               return -ENODEV;
+       }
+
        ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
        ch->port.count++;
        tty->driver_data = ch;
@@ -1486,11 +1492,11 @@ static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
        }
 
        if (!handle) /* nothing else to do */
-               return 0;
+               goto put;
 
        intr = readw(ip); /* port irq status */
        if (intr == 0)
-               return 0;
+               goto put;
 
        writew(0, ip); /* ACK port */
        ofsAddr = p->tableAddr;
@@ -1499,16 +1505,17 @@ static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
                                ofsAddr + HostStat);
 
        if (!inited)
-               return 0;
+               goto put;
 
        if (tty && (intr & IntrBreak) && !I_IGNBRK(tty)) { /* BREAK */
                tty_insert_flip_char(tty, 0, TTY_BREAK);
                tty_schedule_flip(tty);
        }
-       tty_kref_put(tty);
 
        if (intr & IntrLine)
                moxa_new_dcdstate(p, readb(ofsAddr + FlagStat) & DCD_state);
+put:
+       tty_kref_put(tty);
 
        return 0;
 }