USB: serial: pl2303: clean up urb->status usage
[safe/jmp/linux-2.6] / drivers / usb / serial / omninet.c
index b595bef..ee94d96 100644 (file)
@@ -1,10 +1,9 @@
 /*
  * USB ZyXEL omni.net LCD PLUS driver
  *
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
+ *     This program is free software; you can redistribute it and/or
+ *     modify it under the terms of the GNU General Public License version
+ *     2 as published by the Free Software Foundation.
  *
  * See Documentation/usb/usb-serial.txt for more information on using this driver
  *
@@ -35,7 +34,6 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/init.h>
@@ -47,7 +45,7 @@
 #include <linux/spinlock.h>
 #include <asm/uaccess.h>
 #include <linux/usb.h>
-#include "usb-serial.h"
+#include <linux/usb/serial.h>
 
 static int debug;
 
@@ -65,11 +63,12 @@ static int debug;
 /* function prototypes */
 static int  omninet_open               (struct usb_serial_port *port, struct file *filp);
 static void omninet_close              (struct usb_serial_port *port, struct file *filp);
-static void omninet_read_bulk_callback (struct urb *urb, struct pt_regs *regs);
-static void omninet_write_bulk_callback        (struct urb *urb, struct pt_regs *regs);
+static void omninet_read_bulk_callback (struct urb *urb);
+static void omninet_write_bulk_callback        (struct urb *urb);
 static int  omninet_write              (struct usb_serial_port *port, const unsigned char *buf, int count);
 static int  omninet_write_room         (struct usb_serial_port *port);
 static void omninet_shutdown           (struct usb_serial *serial);
+static int omninet_attach              (struct usb_serial *serial);
 
 static struct usb_device_id id_table [] = {
        { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) },
@@ -80,7 +79,6 @@ static struct usb_device_id id_table [] = {
 MODULE_DEVICE_TABLE (usb, id_table);
 
 static struct usb_driver omninet_driver = {
-       .owner =        THIS_MODULE,
        .name =         "omninet",
        .probe =        usb_serial_probe,
        .disconnect =   usb_serial_disconnect,
@@ -95,11 +93,13 @@ static struct usb_serial_driver zyxel_omninet_device = {
                .name =         "omninet",
        },
        .description =          "ZyXEL - omni.net lcd plus usb",
+       .usb_driver =           &omninet_driver,
        .id_table =             id_table,
        .num_interrupt_in =     1,
        .num_bulk_in =          1,
        .num_bulk_out =         2,
        .num_ports =            1,
+       .attach =               omninet_attach,
        .open =                 omninet_open,
        .close =                omninet_close,
        .write =                omninet_write,
@@ -146,22 +146,28 @@ struct omninet_data
        __u8    od_outseq;      // Sequence number for bulk_out URBs
 };
 
-static int omninet_open (struct usb_serial_port *port, struct file *filp)
+static int omninet_attach (struct usb_serial *serial)
 {
-       struct usb_serial       *serial = port->serial;
-       struct usb_serial_port  *wport;
-       struct omninet_data     *od;
-       int                     result = 0;
-
-       dbg("%s - port %d", __FUNCTION__, port->number);
+       struct omninet_data *od;
+       struct usb_serial_port *port = serial->port[0];
 
        od = kmalloc( sizeof(struct omninet_data), GFP_KERNEL );
        if( !od ) {
                err("%s- kmalloc(%Zd) failed.", __FUNCTION__, sizeof(struct omninet_data));
                return -ENOMEM;
        }
-
        usb_set_serial_port_data(port, od);
+       return 0;
+}
+
+static int omninet_open (struct usb_serial_port *port, struct file *filp)
+{
+       struct usb_serial       *serial = port->serial;
+       struct usb_serial_port  *wport;
+       int                     result = 0;
+
+       dbg("%s - port %d", __FUNCTION__, port->number);
+
        wport = serial->port[1];
        wport->tty = port->tty;
 
@@ -171,24 +177,17 @@ static int omninet_open (struct usb_serial_port *port, struct file *filp)
                      port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length,
                      omninet_read_bulk_callback, port);
        result = usb_submit_urb(port->read_urb, GFP_KERNEL);
-       if (result)
+       if (result) {
                err("%s - failed submitting read urb, error %d", __FUNCTION__, result);
+       }
 
        return result;
 }
 
 static void omninet_close (struct usb_serial_port *port, struct file * filp)
 {
-       struct usb_serial       *serial = port->serial;
-       struct usb_serial_port  *wport;
-
        dbg("%s - port %d", __FUNCTION__, port->number);
-
-       wport = serial->port[1];
-       usb_kill_urb(wport->write_urb);
        usb_kill_urb(port->read_urb);
-
-       kfree(usb_get_serial_port_data(port));
 }
 
 
@@ -196,19 +195,20 @@ static void omninet_close (struct usb_serial_port *port, struct file * filp)
 #define OMNINET_HEADERLEN      sizeof(struct omninet_header)
 #define OMNINET_BULKOUTSIZE    (64 - OMNINET_HEADERLEN)
 
-static void omninet_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
+static void omninet_read_bulk_callback (struct urb *urb)
 {
        struct usb_serial_port  *port   = (struct usb_serial_port *)urb->context;
        unsigned char           *data   = urb->transfer_buffer;
        struct omninet_header   *header = (struct omninet_header *) &data[0];
-
+       int status = urb->status;
        int i;
        int result;
 
-//     dbg("omninet_read_bulk_callback");
+       dbg("%s - port %d", __FUNCTION__, port->number);
 
-       if (urb->status) {
-               dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
+       if (status) {
+               dbg("%s - nonzero read bulk status received: %d",
+                   __FUNCTION__, status);
                return;
        }
 
@@ -251,21 +251,21 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
 
        int                     result;
 
-//     dbg("omninet_write port %d", port->number);
+       dbg("%s - port %d", __FUNCTION__, port->number);
 
        if (count == 0) {
                dbg("%s - write request of 0 bytes", __FUNCTION__);
                return (0);
        }
 
-       spin_lock(&port->lock);
-       if (port->write_urb_busy) {
-               spin_unlock(&port->lock);
+       spin_lock_bh(&wport->lock);
+       if (wport->write_urb_busy) {
+               spin_unlock_bh(&wport->lock);
                dbg("%s - already writing", __FUNCTION__);
                return 0;
        }
-       port->write_urb_busy = 1;
-       spin_unlock(&port->lock);
+       wport->write_urb_busy = 1;
+       spin_unlock_bh(&wport->lock);
 
        count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count;
 
@@ -284,7 +284,7 @@ static int omninet_write (struct usb_serial_port *port, const unsigned char *buf
        wport->write_urb->dev = serial->dev;
        result = usb_submit_urb(wport->write_urb, GFP_ATOMIC);
        if (result) {
-               port->write_urb_busy = 0;
+               wport->write_urb_busy = 0;
                err("%s - failed submitting write urb, error %d", __FUNCTION__, result);
        } else
                result = count;
@@ -303,33 +303,38 @@ static int omninet_write_room (struct usb_serial_port *port)
        if (wport->write_urb_busy)
                room = wport->bulk_out_size - OMNINET_HEADERLEN;
 
-//     dbg("omninet_write_room returns %d", room);
+       dbg("%s - returns %d", __FUNCTION__, room);
 
        return (room);
 }
 
-static void omninet_write_bulk_callback (struct urb *urb, struct pt_regs *regs)
+static void omninet_write_bulk_callback (struct urb *urb)
 {
 /*     struct omninet_header   *header = (struct omninet_header  *) urb->transfer_buffer; */
        struct usb_serial_port  *port   = (struct usb_serial_port *) urb->context;
+       int status = urb->status;
 
-//     dbg("omninet_write_bulk_callback, port %0x\n", port);
+       dbg("%s - port %0x\n", __FUNCTION__, port->number);
 
        port->write_urb_busy = 0;
-       if (urb->status) {
-               dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
+       if (status) {
+               dbg("%s - nonzero write bulk status received: %d",
+                   __FUNCTION__, status);
                return;
        }
 
-       schedule_work(&port->work);
-
-//     dbg("omninet_write_bulk_callback, tty %0x\n", tty);
+       usb_serial_port_softint(port);
 }
 
 
 static void omninet_shutdown (struct usb_serial *serial)
 {
+       struct usb_serial_port *wport = serial->port[1];
+       struct usb_serial_port *port = serial->port[0];
        dbg ("%s", __FUNCTION__);
+
+       usb_kill_urb(wport->write_urb);
+       kfree(usb_get_serial_port_data(port));
 }