drivers/char/mem.c: avoid OOM lockup during large reads from /dev/zero
[safe/jmp/linux-2.6] / drivers / char / riscom8.c
index 45e73bd..2176604 100644 (file)
@@ -48,6 +48,7 @@
 #include <linux/delay.h>
 #include <linux/tty_flip.h>
 #include <linux/spinlock.h>
+#include <linux/device.h>
 
 #include <linux/uaccess.h>
 
@@ -322,7 +323,7 @@ static struct riscom_port *rc_get_port(struct riscom_board const *bp,
        channel = rc_in(bp, CD180_GICR) >> GICR_CHAN_OFF;
        if (channel < CD180_NCH)  {
                port = &rc_port[board_No(bp) * RC_NPORT + channel];
-               if (port->flags & ASYNC_INITIALIZED)
+               if (port->port.flags & ASYNC_INITIALIZED)
                        return port;
        }
        printk(KERN_ERR "rc%d: %s interrupt from invalid port %d\n",
@@ -341,7 +342,7 @@ static void rc_receive_exc(struct riscom_board const *bp)
        if (port == NULL)
                return;
 
-       tty = port->tty;
+       tty = port->port.tty;
 
 #ifdef RC_REPORT_OVERRUN
        status = rc_in(bp, CD180_RCSR);
@@ -364,7 +365,7 @@ static void rc_receive_exc(struct riscom_board const *bp)
                printk(KERN_INFO "rc%d: port %d: Handling break...\n",
                       board_No(bp), port_No(port));
                flag = TTY_BREAK;
-               if (port->flags & ASYNC_SAK)
+               if (port->port.flags & ASYNC_SAK)
                        do_SAK(tty);
 
        } else if (status & RCSR_PE)
@@ -392,7 +393,7 @@ static void rc_receive(struct riscom_board const *bp)
        if (port == NULL)
                return;
 
-       tty = port->tty;
+       tty = port->port.tty;
 
        count = rc_in(bp, CD180_RDCR);
 
@@ -422,7 +423,7 @@ static void rc_transmit(struct riscom_board const *bp)
        if (port == NULL)
                return;
 
-       tty = port->tty;
+       tty = port->port.tty;
 
        if (port->IER & IER_TXEMPTY) {
                /* FIFO drained */
@@ -467,7 +468,7 @@ static void rc_transmit(struct riscom_board const *bp)
 
        count = CD180_NFIFO;
        do {
-               rc_out(bp, CD180_TDR, port->xmit_buf[port->xmit_tail++]);
+               rc_out(bp, CD180_TDR, port->port.xmit_buf[port->xmit_tail++]);
                port->xmit_tail = port->xmit_tail & (SERIAL_XMIT_SIZE-1);
                if (--port->xmit_cnt <= 0)
                        break;
@@ -492,12 +493,12 @@ static void rc_check_modem(struct riscom_board const *bp)
        if (port == NULL)
                return;
 
-       tty = port->tty;
+       tty = port->port.tty;
 
        mcr = rc_in(bp, CD180_MCR);
        if (mcr & MCR_CDCHG) {
                if (rc_in(bp, CD180_MSVR) & MSVR_CD)
-                       wake_up_interruptible(&port->open_wait);
+                       wake_up_interruptible(&port->port.open_wait);
                else
                        tty_hangup(tty);
        }
@@ -632,15 +633,12 @@ static void rc_shutdown_board(struct riscom_board *bp)
  */
 static void rc_change_speed(struct riscom_board *bp, struct riscom_port *port)
 {
-       struct tty_struct *tty = port->tty;
+       struct tty_struct *tty = port->port.tty;
        unsigned long baud;
        long tmp;
        unsigned char cor1 = 0, cor3 = 0;
        unsigned char mcor1 = 0, mcor2 = 0;
 
-       if (tty == NULL || tty->termios == NULL)
-               return;
-
        port->IER  = 0;
        port->COR2 = 0;
        port->MSVR = MSVR_RTS;
@@ -786,39 +784,30 @@ static int rc_setup_port(struct riscom_board *bp, struct riscom_port *port)
 {
        unsigned long flags;
 
-       if (port->flags & ASYNC_INITIALIZED)
+       if (port->port.flags & ASYNC_INITIALIZED)
                return 0;
 
-       if (!port->xmit_buf) {
-               /* We may sleep in get_zeroed_page() */
-               unsigned long tmp = get_zeroed_page(GFP_KERNEL);
-               if (tmp == 0)
-                       return -ENOMEM;
-               if (port->xmit_buf)
-                       free_page(tmp);
-               else
-                       port->xmit_buf = (unsigned char *) tmp;
-       }
+       if (tty_port_alloc_xmit_buf(&port->port) < 0)
+               return -ENOMEM;
+
        spin_lock_irqsave(&riscom_lock, flags);
 
-       if (port->tty)
-               clear_bit(TTY_IO_ERROR, &port->tty->flags);
-       if (port->count == 1)
+       clear_bit(TTY_IO_ERROR, &port->port.tty->flags);
+       if (port->port.count == 1)
                bp->count++;
        port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
        rc_change_speed(bp, port);
-       port->flags |= ASYNC_INITIALIZED;
+       port->port.flags |= ASYNC_INITIALIZED;
 
        spin_unlock_irqrestore(&riscom_lock, flags);
        return 0;
 }
 
 /* Must be called with interrupts disabled */
-static void rc_shutdown_port(struct riscom_board *bp, struct riscom_port *port)
+static void rc_shutdown_port(struct tty_struct *tty,
+                       struct riscom_board *bp, struct riscom_port *port)
 {
-       struct tty_struct *tty;
-
-       if (!(port->flags & ASYNC_INITIALIZED))
+       if (!(port->port.flags & ASYNC_INITIALIZED))
                return;
 
 #ifdef RC_REPORT_OVERRUN
@@ -836,14 +825,8 @@ static void rc_shutdown_port(struct riscom_board *bp, struct riscom_port *port)
                printk("].\n");
        }
 #endif
-       if (port->xmit_buf)  {
-               free_page((unsigned long) port->xmit_buf);
-               port->xmit_buf = NULL;
-       }
-
-       tty = port->tty;
-
-       if (tty == NULL || C_HUPCL(tty)) {
+       tty_port_free_xmit_buf(&port->port);
+       if (C_HUPCL(tty)) {
                /* Drop DTR */
                bp->DTR |= (1u << port_No(port));
                rc_out(bp, RC_DTR, bp->DTR);
@@ -858,9 +841,8 @@ static void rc_shutdown_port(struct riscom_board *bp, struct riscom_port *port)
        port->IER = 0;
        rc_out(bp, CD180_IER, port->IER);
 
-       if (tty)
-               set_bit(TTY_IO_ERROR, &tty->flags);
-       port->flags &= ~ASYNC_INITIALIZED;
+       set_bit(TTY_IO_ERROR, &tty->flags);
+       port->port.flags &= ~ASYNC_INITIALIZED;
 
        if (--bp->count < 0)  {
                printk(KERN_INFO "rc%d: rc_shutdown_port: "
@@ -876,98 +858,21 @@ static void rc_shutdown_port(struct riscom_board *bp, struct riscom_port *port)
                rc_shutdown_board(bp);
 }
 
-static int block_til_ready(struct tty_struct *tty, struct file *filp,
-                          struct riscom_port *port)
+static int carrier_raised(struct tty_port *port)
 {
-       DECLARE_WAITQUEUE(wait, current);
-       struct riscom_board *bp = port_Board(port);
-       int    retval;
-       int    do_clocal = 0;
-       int    CD;
+       struct riscom_port *p = container_of(port, struct riscom_port, port);
+       struct riscom_board *bp = port_Board(p);
        unsigned long flags;
-
-       /*
-        * If the device is in the middle of being closed, then block
-        * until it's done, and then try again.
-        */
-       if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
-               interruptible_sleep_on(&port->close_wait);
-               if (port->flags & ASYNC_HUP_NOTIFY)
-                       return -EAGAIN;
-               else
-                       return -ERESTARTSYS;
-       }
-
-       /*
-        * If non-blocking mode is set, or the port is not enabled,
-        * then make the check up front and then exit.
-        */
-       if ((filp->f_flags & O_NONBLOCK) ||
-           (tty->flags & (1 << TTY_IO_ERROR))) {
-               port->flags |= ASYNC_NORMAL_ACTIVE;
-               return 0;
-       }
-
-       if (C_CLOCAL(tty))
-               do_clocal = 1;
-
-       /*
-        * Block waiting for the carrier detect and the line to become
-        * free (i.e., not in use by the callout).  While we are in
-        * this loop, info->count is dropped by one, so that
-        * rs_close() knows when to free things.  We restore it upon
-        * exit, either normal or abnormal.
-        */
-       retval = 0;
-       add_wait_queue(&port->open_wait, &wait);
-
+       int CD;
+       
        spin_lock_irqsave(&riscom_lock, flags);
-
-       if (!tty_hung_up_p(filp))
-               port->count--;
-
+       rc_out(bp, CD180_CAR, port_No(p));
+       CD = rc_in(bp, CD180_MSVR) & MSVR_CD;
+       rc_out(bp, CD180_MSVR, MSVR_RTS);
+       bp->DTR &= ~(1u << port_No(p));
+       rc_out(bp, RC_DTR, bp->DTR);
        spin_unlock_irqrestore(&riscom_lock, flags);
-
-       port->blocked_open++;
-       while (1) {
-               spin_lock_irqsave(&riscom_lock, flags);
-
-               rc_out(bp, CD180_CAR, port_No(port));
-               CD = rc_in(bp, CD180_MSVR) & MSVR_CD;
-               rc_out(bp, CD180_MSVR, MSVR_RTS);
-               bp->DTR &= ~(1u << port_No(port));
-               rc_out(bp, RC_DTR, bp->DTR);
-
-               spin_unlock_irqrestore(&riscom_lock, flags);
-
-               set_current_state(TASK_INTERRUPTIBLE);
-               if (tty_hung_up_p(filp) ||
-                   !(port->flags & ASYNC_INITIALIZED)) {
-                       if (port->flags & ASYNC_HUP_NOTIFY)
-                               retval = -EAGAIN;
-                       else
-                               retval = -ERESTARTSYS;
-                       break;
-               }
-               if (!(port->flags & ASYNC_CLOSING) &&
-                   (do_clocal || CD))
-                       break;
-               if (signal_pending(current)) {
-                       retval = -ERESTARTSYS;
-                       break;
-               }
-               schedule();
-       }
-       __set_current_state(TASK_RUNNING);
-       remove_wait_queue(&port->open_wait, &wait);
-       if (!tty_hung_up_p(filp))
-               port->count++;
-       port->blocked_open--;
-       if (retval)
-               return retval;
-
-       port->flags |= ASYNC_NORMAL_ACTIVE;
-       return 0;
+       return CD;
 }
 
 static int rc_open(struct tty_struct *tty, struct file *filp)
@@ -990,19 +895,19 @@ static int rc_open(struct tty_struct *tty, struct file *filp)
        if (error)
                return error;
 
-       port->count++;
+       port->port.count++;
        tty->driver_data = port;
-       port->tty = tty;
+       port->port.tty = tty;
 
        error = rc_setup_port(bp, port);
        if (error == 0)
-               error = block_til_ready(tty, filp, port);
+               error = tty_port_block_til_ready(&port->port, tty, filp);
        return error;
 }
 
 static void rc_flush_buffer(struct tty_struct *tty)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        unsigned long flags;
 
        if (rc_paranoia_check(port, tty->name, "rc_flush_buffer"))
@@ -1017,7 +922,7 @@ static void rc_flush_buffer(struct tty_struct *tty)
 
 static void rc_close(struct tty_struct *tty, struct file *filp)
 {
-       struct riscom_port *port = (struct riscom_port *) tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        struct riscom_board *bp;
        unsigned long flags;
        unsigned long timeout;
@@ -1025,42 +930,21 @@ static void rc_close(struct tty_struct *tty, struct file *filp)
        if (!port || rc_paranoia_check(port, tty->name, "close"))
                return;
 
-       spin_lock_irqsave(&riscom_lock, flags);
-
-       if (tty_hung_up_p(filp))
-               goto out;
-
        bp = port_Board(port);
-       if ((tty->count == 1) && (port->count != 1))  {
-               printk(KERN_INFO "rc%d: rc_close: bad port count;"
-                      " tty->count is 1, port count is %d\n",
-                      board_No(bp), port->count);
-               port->count = 1;
-       }
-       if (--port->count < 0)  {
-               printk(KERN_INFO "rc%d: rc_close: bad port count "
-                                "for tty%d: %d\n",
-                      board_No(bp), port_No(port), port->count);
-               port->count = 0;
-       }
-       if (port->count)
-               goto out;
-       port->flags |= ASYNC_CLOSING;
-       /*
-        * Now we wait for the transmit buffer to clear; and we notify
-        * the line discipline to only process XON/XOFF characters.
-        */
-       tty->closing = 1;
-       if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
-               tty_wait_until_sent(tty, port->closing_wait);
+       
+       if (tty_port_close_start(&port->port, tty, filp) == 0)
+               return;
+       
        /*
         * At this point we stop accepting input.  To do this, we
         * disable the receive line status interrupts, and tell the
         * interrupt driver to stop checking the data ready bit in the
         * line status register.
         */
+
+       spin_lock_irqsave(&riscom_lock, flags);
        port->IER &= ~IER_RXD;
-       if (port->flags & ASYNC_INITIALIZED) {
+       if (port->port.flags & ASYNC_INITIALIZED) {
                port->IER &= ~IER_TXRDY;
                port->IER |= IER_TXEMPTY;
                rc_out(bp, CD180_CAR, port_No(port));
@@ -1072,33 +956,24 @@ static void rc_close(struct tty_struct *tty, struct file *filp)
                 */
                timeout = jiffies + HZ;
                while (port->IER & IER_TXEMPTY) {
+                       spin_unlock_irqrestore(&riscom_lock, flags);
                        msleep_interruptible(jiffies_to_msecs(port->timeout));
+                       spin_lock_irqsave(&riscom_lock, flags);
                        if (time_after(jiffies, timeout))
                                break;
                }
        }
-       rc_shutdown_port(bp, port);
+       rc_shutdown_port(tty, bp, port);
        rc_flush_buffer(tty);
-       tty_ldisc_flush(tty);
-
-       tty->closing = 0;
-       port->tty = NULL;
-       if (port->blocked_open) {
-               if (port->close_delay)
-                       msleep_interruptible(jiffies_to_msecs(port->close_delay));
-               wake_up_interruptible(&port->open_wait);
-       }
-       port->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
-       wake_up_interruptible(&port->close_wait);
-
-out:
        spin_unlock_irqrestore(&riscom_lock, flags);
+
+       tty_port_close_end(&port->port, tty);
 }
 
 static int rc_write(struct tty_struct *tty,
                    const unsigned char *buf, int count)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        struct riscom_board *bp;
        int c, total = 0;
        unsigned long flags;
@@ -1108,9 +983,6 @@ static int rc_write(struct tty_struct *tty,
 
        bp = port_Board(port);
 
-       if (!tty || !port->xmit_buf)
-               return 0;
-
        while (1) {
                spin_lock_irqsave(&riscom_lock, flags);
 
@@ -1119,7 +991,7 @@ static int rc_write(struct tty_struct *tty,
                if (c <= 0)
                        break;  /* lock continues to be held */
 
-               memcpy(port->xmit_buf + port->xmit_head, buf, c);
+               memcpy(port->port.xmit_buf + port->xmit_head, buf, c);
                port->xmit_head = (port->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
                port->xmit_cnt += c;
 
@@ -1144,22 +1016,19 @@ static int rc_write(struct tty_struct *tty,
 
 static int rc_put_char(struct tty_struct *tty, unsigned char ch)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        unsigned long flags;
        int ret = 0;
 
        if (rc_paranoia_check(port, tty->name, "rc_put_char"))
                return 0;
 
-       if (!tty || !port->xmit_buf)
-               return 0;
-
        spin_lock_irqsave(&riscom_lock, flags);
 
        if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1)
                goto out;
 
-       port->xmit_buf[port->xmit_head++] = ch;
+       port->port.xmit_buf[port->xmit_head++] = ch;
        port->xmit_head &= SERIAL_XMIT_SIZE - 1;
        port->xmit_cnt++;
        ret = 1;
@@ -1171,14 +1040,13 @@ out:
 
 static void rc_flush_chars(struct tty_struct *tty)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        unsigned long flags;
 
        if (rc_paranoia_check(port, tty->name, "rc_flush_chars"))
                return;
 
-       if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
-           !port->xmit_buf)
+       if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped)
                return;
 
        spin_lock_irqsave(&riscom_lock, flags);
@@ -1192,7 +1060,7 @@ static void rc_flush_chars(struct tty_struct *tty)
 
 static int rc_write_room(struct tty_struct *tty)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        int     ret;
 
        if (rc_paranoia_check(port, tty->name, "rc_write_room"))
@@ -1206,7 +1074,7 @@ static int rc_write_room(struct tty_struct *tty)
 
 static int rc_chars_in_buffer(struct tty_struct *tty)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
 
        if (rc_paranoia_check(port, tty->name, "rc_chars_in_buffer"))
                return 0;
@@ -1216,13 +1084,13 @@ static int rc_chars_in_buffer(struct tty_struct *tty)
 
 static int rc_tiocmget(struct tty_struct *tty, struct file *file)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        struct riscom_board *bp;
        unsigned char status;
        unsigned int result;
        unsigned long flags;
 
-       if (rc_paranoia_check(port, tty->name, __FUNCTION__))
+       if (rc_paranoia_check(port, tty->name, __func__))
                return -ENODEV;
 
        bp = port_Board(port);
@@ -1246,11 +1114,11 @@ static int rc_tiocmget(struct tty_struct *tty, struct file *file)
 static int rc_tiocmset(struct tty_struct *tty, struct file *file,
                       unsigned int set, unsigned int clear)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        unsigned long flags;
        struct riscom_board *bp;
 
-       if (rc_paranoia_check(port, tty->name, __FUNCTION__))
+       if (rc_paranoia_check(port, tty->name, __func__))
                return -ENODEV;
 
        bp = port_Board(port);
@@ -1276,11 +1144,15 @@ static int rc_tiocmset(struct tty_struct *tty, struct file *file,
        return 0;
 }
 
-static void rc_send_break(struct riscom_port *port, unsigned long length)
+static int rc_send_break(struct tty_struct *tty, int length)
 {
+       struct riscom_port *port = tty->driver_data;
        struct riscom_board *bp = port_Board(port);
        unsigned long flags;
 
+       if (length == 0 || length == -1)
+               return -EOPNOTSUPP;
+
        spin_lock_irqsave(&riscom_lock, flags);
 
        port->break_length = RISCOM_TPS / HZ * length;
@@ -1294,6 +1166,7 @@ static void rc_send_break(struct riscom_port *port, unsigned long length)
        rc_wait_CCR(bp);
 
        spin_unlock_irqrestore(&riscom_lock, flags);
+       return 0;
 }
 
 static int rc_set_serial_info(struct riscom_port *port,
@@ -1317,22 +1190,22 @@ static int rc_set_serial_info(struct riscom_port *port,
                return -EINVAL;
 #endif
 
-       change_speed = ((port->flags & ASYNC_SPD_MASK) !=
+       change_speed = ((port->port.flags & ASYNC_SPD_MASK) !=
                        (tmp.flags & ASYNC_SPD_MASK));
 
        if (!capable(CAP_SYS_ADMIN)) {
-               if ((tmp.close_delay != port->close_delay) ||
-                   (tmp.closing_wait != port->closing_wait) ||
+               if ((tmp.close_delay != port->port.close_delay) ||
+                   (tmp.closing_wait != port->port.closing_wait) ||
                    ((tmp.flags & ~ASYNC_USR_MASK) !=
-                    (port->flags & ~ASYNC_USR_MASK)))
+                    (port->port.flags & ~ASYNC_USR_MASK)))
                        return -EPERM;
-               port->flags = ((port->flags & ~ASYNC_USR_MASK) |
+               port->port.flags = ((port->port.flags & ~ASYNC_USR_MASK) |
                               (tmp.flags & ASYNC_USR_MASK));
        } else  {
-               port->flags = ((port->flags & ~ASYNC_FLAGS) |
+               port->port.flags = ((port->port.flags & ~ASYNC_FLAGS) |
                               (tmp.flags & ASYNC_FLAGS));
-               port->close_delay = tmp.close_delay;
-               port->closing_wait = tmp.closing_wait;
+               port->port.close_delay = tmp.close_delay;
+               port->port.closing_wait = tmp.closing_wait;
        }
        if (change_speed)  {
                unsigned long flags;
@@ -1355,10 +1228,10 @@ static int rc_get_serial_info(struct riscom_port *port,
        tmp.line = port - rc_port;
        tmp.port = bp->base;
        tmp.irq  = bp->irq;
-       tmp.flags = port->flags;
+       tmp.flags = port->port.flags;
        tmp.baud_base = (RC_OSCFREQ + CD180_TPC/2) / CD180_TPC;
-       tmp.close_delay = port->close_delay * HZ/100;
-       tmp.closing_wait = port->closing_wait * HZ/100;
+       tmp.close_delay = port->port.close_delay * HZ/100;
+       tmp.closing_wait = port->port.closing_wait * HZ/100;
        tmp.xmit_fifo_size = CD180_NFIFO;
        return copy_to_user(retinfo, &tmp, sizeof(tmp)) ? -EFAULT : 0;
 }
@@ -1366,29 +1239,14 @@ static int rc_get_serial_info(struct riscom_port *port,
 static int rc_ioctl(struct tty_struct *tty, struct file *filp,
                    unsigned int cmd, unsigned long arg)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        void __user *argp = (void __user *)arg;
-       int retval = 0;
+       int retval;
 
        if (rc_paranoia_check(port, tty->name, "rc_ioctl"))
                return -ENODEV;
 
        switch (cmd) {
-       case TCSBRK:    /* SVID version: non-zero arg --> no break */
-               retval = tty_check_change(tty);
-               if (retval)
-                       return retval;
-               tty_wait_until_sent(tty, 0);
-               if (!arg)
-                       rc_send_break(port, HZ/4);      /* 1/4 second */
-               break;
-       case TCSBRKP:   /* support for POSIX tcsendbreak() */
-               retval = tty_check_change(tty);
-               if (retval)
-                       return retval;
-               tty_wait_until_sent(tty, 0);
-               rc_send_break(port, arg ? arg*(HZ/10) : HZ/4);
-               break;
        case TIOCGSERIAL:
                lock_kernel();
                retval = rc_get_serial_info(port, argp);
@@ -1407,7 +1265,7 @@ static int rc_ioctl(struct tty_struct *tty, struct file *filp,
 
 static void rc_throttle(struct tty_struct *tty)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        struct riscom_board *bp;
        unsigned long flags;
 
@@ -1429,7 +1287,7 @@ static void rc_throttle(struct tty_struct *tty)
 
 static void rc_unthrottle(struct tty_struct *tty)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        struct riscom_board *bp;
        unsigned long flags;
 
@@ -1451,7 +1309,7 @@ static void rc_unthrottle(struct tty_struct *tty)
 
 static void rc_stop(struct tty_struct *tty)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        struct riscom_board *bp;
        unsigned long flags;
 
@@ -1469,7 +1327,7 @@ static void rc_stop(struct tty_struct *tty)
 
 static void rc_start(struct tty_struct *tty)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        struct riscom_board *bp;
        unsigned long flags;
 
@@ -1480,7 +1338,7 @@ static void rc_start(struct tty_struct *tty)
 
        spin_lock_irqsave(&riscom_lock, flags);
 
-       if (port->xmit_cnt && port->xmit_buf && !(port->IER & IER_TXRDY)) {
+       if (port->xmit_cnt && port->port.xmit_buf && !(port->IER & IER_TXRDY)) {
                port->IER |= IER_TXRDY;
                rc_out(bp, CD180_CAR, port_No(port));
                rc_out(bp, CD180_IER, port->IER);
@@ -1490,25 +1348,28 @@ static void rc_start(struct tty_struct *tty)
 
 static void rc_hangup(struct tty_struct *tty)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        struct riscom_board *bp;
+       unsigned long flags;
 
        if (rc_paranoia_check(port, tty->name, "rc_hangup"))
                return;
 
        bp = port_Board(port);
 
-       rc_shutdown_port(bp, port);
-       port->count = 0;
-       port->flags &= ~ASYNC_NORMAL_ACTIVE;
-       port->tty = NULL;
-       wake_up_interruptible(&port->open_wait);
+       rc_shutdown_port(tty, bp, port);
+       spin_lock_irqsave(&port->port.lock, flags);
+       port->port.count = 0;
+       port->port.flags &= ~ASYNC_NORMAL_ACTIVE;
+       port->port.tty = NULL;
+       wake_up_interruptible(&port->port.open_wait);
+       spin_unlock_irqrestore(&port->port.lock, flags);
 }
 
 static void rc_set_termios(struct tty_struct *tty,
                                        struct ktermios *old_termios)
 {
-       struct riscom_port *port = (struct riscom_port *)tty->driver_data;
+       struct riscom_port *port = tty->driver_data;
        unsigned long flags;
 
        if (rc_paranoia_check(port, tty->name, "rc_set_termios"))
@@ -1543,8 +1404,14 @@ static const struct tty_operations riscom_ops = {
        .hangup = rc_hangup,
        .tiocmget = rc_tiocmget,
        .tiocmset = rc_tiocmset,
+       .break_ctl = rc_send_break,
+};
+
+static const struct tty_port_operations riscom_port_ops = {
+       .carrier_raised = carrier_raised,
 };
 
+
 static int __init rc_init_drivers(void)
 {
        int error;
@@ -1564,7 +1431,7 @@ static int __init rc_init_drivers(void)
                B9600 | CS8 | CREAD | HUPCL | CLOCAL;
        riscom_driver->init_termios.c_ispeed = 9600;
        riscom_driver->init_termios.c_ospeed = 9600;
-       riscom_driver->flags = TTY_DRIVER_REAL_RAW;
+       riscom_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
        tty_set_operations(riscom_driver, &riscom_ops);
        error = tty_register_driver(riscom_driver);
        if (error != 0) {
@@ -1575,11 +1442,9 @@ static int __init rc_init_drivers(void)
        }
        memset(rc_port, 0, sizeof(rc_port));
        for (i = 0; i < RC_NPORT * RC_NBOARD; i++)  {
+               tty_port_init(&rc_port[i].port);
+               rc_port[i].port.ops = &riscom_port_ops;
                rc_port[i].magic = RISCOM8_MAGIC;
-               rc_port[i].close_delay = 50 * HZ / 100;
-               rc_port[i].closing_wait = 3000 * HZ / 100;
-               init_waitqueue_head(&rc_port[i].open_wait);
-               init_waitqueue_head(&rc_port[i].close_wait);
        }
        return 0;
 }
@@ -1660,6 +1525,7 @@ module_param(iobase2, int, 0);
 module_param(iobase3, int, 0);
 
 MODULE_LICENSE("GPL");
+MODULE_ALIAS_CHARDEV_MAJOR(RISCOM8_NORMAL_MAJOR);
 #endif /* MODULE */
 
 /*