nfsd4: fix null dereference creating nfsv4 callback client
[safe/jmp/linux-2.6] / drivers / char / ser_a2232.c
index 65c751d..33a2b53 100644 (file)
@@ -86,7 +86,6 @@
 #include <linux/module.h>
 
 #include <linux/types.h>
-#include <linux/sched.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 
 /***************************** Prototypes ***************************/
 /* The interrupt service routine */
-static irqreturn_t a2232_vbl_inter(int irq, void *data, struct pt_regs *fp);
+static irqreturn_t a2232_vbl_inter(int irq, void *data);
 /* Initialize the port structures */
 static void a2232_init_portstructs(void);
 /* Initialize and register TTY drivers. */
@@ -123,7 +122,7 @@ static void a2232_disable_tx_interrupts(void *ptr);
 static void a2232_enable_tx_interrupts(void *ptr);
 static void a2232_disable_rx_interrupts(void *ptr);
 static void a2232_enable_rx_interrupts(void *ptr);
-static int  a2232_get_CD(void *ptr);
+static int  a2232_carrier_raised(struct tty_port *port);
 static void a2232_shutdown_port(void *ptr);
 static int  a2232_set_real_termios(void *ptr);
 static int  a2232_chars_in_buffer(void *ptr);
@@ -149,7 +148,6 @@ static struct real_driver a2232_real_driver = {
         a2232_enable_tx_interrupts,
         a2232_disable_rx_interrupts,
         a2232_enable_rx_interrupts,
-        a2232_get_CD,
         a2232_shutdown_port,
         a2232_set_real_termios,
         a2232_chars_in_buffer,
@@ -193,7 +191,7 @@ static inline void a2232_receive_char(struct a2232_port *port, int ch, int err)
        Maybe one could implement a more efficient version by not only
        transferring one character at a time.
 */
-       struct tty_struct *tty = port->gs.tty;
+       struct tty_struct *tty = port->gs.port.tty;
 
 #if 0
        switch(err) {
@@ -227,7 +225,7 @@ static void a2232_disable_tx_interrupts(void *ptr)
 
        /* Does this here really have to be? */
        local_irq_save(flags);
-       port->gs.flags &= ~GS_TX_INTEN;
+       port->gs.port.flags &= ~GS_TX_INTEN;
        local_irq_restore(flags);
 }
 
@@ -243,7 +241,7 @@ static void a2232_enable_tx_interrupts(void *ptr)
 
        /* Does this here really have to be? */
        local_irq_save(flags);
-       port->gs.flags |= GS_TX_INTEN;
+       port->gs.port.flags |= GS_TX_INTEN;
        local_irq_restore(flags);
 }
 
@@ -261,9 +259,10 @@ static void a2232_enable_rx_interrupts(void *ptr)
        port->disable_rx = 0;
 }
 
-static int  a2232_get_CD(void *ptr)
+static int  a2232_carrier_raised(struct tty_port *port)
 {
-       return ((struct a2232_port *) ptr)->cd_status;
+       struct a2232_port *ap = container_of(port, struct a2232_port, gs.port);
+       return ap->cd_status;
 }
 
 static void a2232_shutdown_port(void *ptr)
@@ -277,9 +276,9 @@ static void a2232_shutdown_port(void *ptr)
 
        local_irq_save(flags);
 
-       port->gs.flags &= ~GS_ACTIVE;
+       port->gs.port.flags &= ~GS_ACTIVE;
        
-       if (port->gs.tty && port->gs.tty->termios->c_cflag & HUPCL) {
+       if (port->gs.port.tty && port->gs.port.tty->termios->c_cflag & HUPCL) {
                /* Set DTR and RTS to Low, flush output.
                   The NetBSD driver "msc.c" does it this way. */
                stat->Command = (       (stat->Command & ~A2232CMD_CMask) | 
@@ -310,7 +309,7 @@ static int  a2232_set_real_termios(void *ptr)
        volatile struct a2232status *status;
        volatile struct a2232memory *mem;
 
-       if (!port->gs.tty || !port->gs.tty->termios) return 0;
+       if (!port->gs.port.tty || !port->gs.port.tty->termios) return 0;
 
        status = a2232stat(port->which_a2232, port->which_port_on_a2232);
        mem = a2232mem(port->which_a2232);
@@ -346,7 +345,7 @@ static int  a2232_set_real_termios(void *ptr)
        }
        a2232_param |= rate;
 
-       cflag  = port->gs.tty->termios->c_cflag;
+       cflag  = port->gs.port.tty->termios->c_cflag;
 
        // get character size
        chsize = cflag & CSIZE;
@@ -383,7 +382,7 @@ static int  a2232_set_real_termios(void *ptr)
                the conventional way of inserting START/STOP characters
                by hand in throttle()/unthrottle().
        */
-       softflow = !!( port->gs.tty->termios->c_iflag & IXOFF );
+       softflow = !!( port->gs.port.tty->termios->c_iflag & IXOFF );
 
        // get Parity (Enabled/Disabled? If Enabled, Odd or Even?)
        parity = cflag & (PARENB | PARODD);
@@ -401,9 +400,9 @@ static int  a2232_set_real_termios(void *ptr)
        /*      Hmm. Maybe an own a2232_port structure
                member would be cleaner?        */
        if (cflag & CLOCAL)
-               port->gs.flags &= ~ASYNC_CHECK_CD;
+               port->gs.port.flags &= ~ASYNC_CHECK_CD;
        else
-               port->gs.flags |= ASYNC_CHECK_CD;
+               port->gs.port.flags |= ASYNC_CHECK_CD;
 
 
        /* Now we have all parameters and can go to set them: */
@@ -461,14 +460,14 @@ static void a2232_throttle(struct tty_struct *tty)
    if switched on. So the only thing we can do at this
    layer here is not taking any characters out of the
    A2232 buffer any more. */
-       struct a2232_port *port = (struct a2232_port *) tty->driver_data;
+       struct a2232_port *port = tty->driver_data;
        port->throttle_input = -1;
 }
 
 static void a2232_unthrottle(struct tty_struct *tty)
 {
 /* Unthrottle: dual to "throttle()" above. */
-       struct a2232_port *port = (struct a2232_port *) tty->driver_data;
+       struct a2232_port *port = tty->driver_data;
        port->throttle_input = 0;
 }
 
@@ -483,18 +482,18 @@ static int  a2232_open(struct tty_struct * tty, struct file * filp)
        port = &a2232_ports[line];
        
        tty->driver_data = port;
-       port->gs.tty = tty;
-       port->gs.count++;
+       port->gs.port.tty = tty;
+       port->gs.port.count++;
        retval = gs_init_port(&port->gs);
        if (retval) {
-               port->gs.count--;
+               port->gs.port.count--;
                return retval;
        }
-       port->gs.flags |= GS_ACTIVE;
+       port->gs.port.flags |= GS_ACTIVE;
        retval = gs_block_til_ready(port, filp);
 
        if (retval) {
-               port->gs.count--;
+               port->gs.port.count--;
                return retval;
        }
 
@@ -504,7 +503,7 @@ static int  a2232_open(struct tty_struct * tty, struct file * filp)
 }
 /*** END OF FUNCTIONS EXPECTED BY TTY DRIVER STRUCTS ***/
 
-static irqreturn_t a2232_vbl_inter(int irq, void *data, struct pt_regs *fp)
+static irqreturn_t a2232_vbl_inter(int irq, void *data)
 {
 #if A2232_IOBUFLEN != 256
 #error "Re-Implement a2232_vbl_inter()!"
@@ -523,7 +522,7 @@ int ch, err, n, p;
                for (p = 0; p < NUMLINES; p++){ /* for every port on this board */
                        err = 0;
                        port = &a2232_ports[n*NUMLINES+p];
-                       if ( port->gs.flags & GS_ACTIVE ){ /* if the port is used */
+                       if ( port->gs.port.flags & GS_ACTIVE ){ /* if the port is used */
 
                                status = a2232stat(n,p);
 
@@ -578,8 +577,8 @@ int ch, err, n, p;
                                obuf = mem->OutBuf[p];
                                bufpos = status->OutHead;
                                while ( (port->gs.xmit_cnt > 0)         &&
-                                       (!port->gs.tty->stopped)        &&
-                                       (!port->gs.tty->hw_stopped) ){  /* While there are chars to transmit */
+                                       (!port->gs.port.tty->stopped)   &&
+                                       (!port->gs.port.tty->hw_stopped) ){     /* While there are chars to transmit */
                                        if (((bufpos+1) & A2232_IOBUFLENMASK) != status->OutTail) { /* If the A2232 buffer is not full */
                                                ch = port->gs.xmit_buf[port->gs.xmit_tail];                                     /* get the next char to transmit */
                                                port->gs.xmit_tail = (port->gs.xmit_tail+1) & (SERIAL_XMIT_SIZE-1); /* modulo-addition for the gs.xmit_buf ring-buffer */
@@ -593,8 +592,8 @@ int ch, err, n, p;
                                status->OutHead = bufpos;
                                        
                                /* WakeUp if output buffer runs low */
-                               if ((port->gs.xmit_cnt <= port->gs.wakeup_chars) && port->gs.tty) {
-                                       tty_wakeup(port->gs.tty);
+                               if ((port->gs.xmit_cnt <= port->gs.wakeup_chars) && port->gs.port.tty) {
+                                       tty_wakeup(port->gs.port.tty);
                                }
                        } // if the port is used
                } // for every port on the board
@@ -614,16 +613,16 @@ int ch, err, n, p;
                                                struct a2232_port *port = &a2232_ports[n*7+p];
                                                port->cd_status = !(ncd & 1); /* ncd&1 <=> CD is now off */
 
-                                               if (!(port->gs.flags & ASYNC_CHECK_CD))
+                                               if (!(port->gs.port.flags & ASYNC_CHECK_CD))
                                                        ;       /* Don't report DCD changes */
                                                else if (port->cd_status) { // if DCD on: DCD went UP!
                                                        
                                                        /* Are we blocking in open?*/
-                                                       wake_up_interruptible(&port->gs.open_wait);
+                                                       wake_up_interruptible(&port->gs.port.open_wait);
                                                }
                                                else { // if DCD off: DCD went DOWN!
-                                                       if (port->gs.tty)
-                                                               tty_hangup (port->gs.tty);
+                                                       if (port->gs.port.tty)
+                                                               tty_hangup (port->gs.port.tty);
                                                }
                                                
                                        } // if CD changed for this port
@@ -639,6 +638,10 @@ int ch, err, n, p;
        return IRQ_HANDLED;
 }
 
+static const struct tty_port_operations a2232_port_ops = {
+       .carrier_raised = a2232_carrier_raised,
+};
+
 static void a2232_init_portstructs(void)
 {
        struct a2232_port *port;
@@ -646,6 +649,8 @@ static void a2232_init_portstructs(void)
 
        for (i = 0; i < MAX_A2232_BOARDS*NUMLINES; i++) {
                port = a2232_ports + i;
+               tty_port_init(&port->gs.port);
+               port->gs.port.ops = &a2232_port_ops;
                port->which_a2232 = i/NUMLINES;
                port->which_port_on_a2232 = i%NUMLINES;
                port->disable_rx = port->throttle_input = port->cd_status = 0;
@@ -653,11 +658,6 @@ static void a2232_init_portstructs(void)
                port->gs.close_delay = HZ/2;
                port->gs.closing_wait = 30 * HZ;
                port->gs.rd = &a2232_real_driver;
-#ifdef NEW_WRITE_LOCKING
-               init_MUTEX(&(port->gs.port_write_mutex));
-#endif
-               init_waitqueue_head(&port->gs.open_wait);
-               init_waitqueue_head(&port->gs.close_wait);
        }
 }
 
@@ -695,6 +695,8 @@ static int a2232_init_drivers(void)
        a2232_driver->init_termios = tty_std_termios;
        a2232_driver->init_termios.c_cflag =
                B9600 | CS8 | CREAD | HUPCL | CLOCAL;
+       a2232_driver->init_termios.c_ispeed = 9600;
+       a2232_driver->init_termios.c_ospeed = 9600;
        a2232_driver->flags = TTY_DRIVER_REAL_RAW;
        tty_set_operations(a2232_driver, &a2232_ops);
        if ((error = tty_register_driver(a2232_driver))) {
@@ -716,6 +718,7 @@ static int __init a2232board_init(void)
        u_char *from;
        volatile u_char *to;
        volatile struct a2232memory *mem;
+       int error, i;
 
 #ifdef CONFIG_SMP
        return -ENODEV; /* This driver is not SMP aware. Is there an SMP ZorroII-bus-machine? */
@@ -795,8 +798,15 @@ static int __init a2232board_init(void)
        */
        if (a2232_init_drivers()) return -ENODEV; // maybe we should use a different -Exxx?
 
-       request_irq(IRQ_AMIGA_VERTB, a2232_vbl_inter, 0, "A2232 serial VBL", a2232_driver_ID);
-       return 0;
+       error = request_irq(IRQ_AMIGA_VERTB, a2232_vbl_inter, 0,
+                           "A2232 serial VBL", a2232_driver_ID);
+       if (error) {
+               for (i = 0; i < nr_a2232; i++)
+                       zorro_release_device(zd_a2232[i]);
+               tty_unregister_driver(a2232_driver);
+               put_tty_driver(a2232_driver);
+       }
+       return error;
 }
 
 static void __exit a2232board_exit(void)