Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / usb / serial / keyspan.c
index 2f2abae..052b735 100644 (file)
 #include <linux/module.h>
 #include <linux/spinlock.h>
 #include <asm/uaccess.h>
-
-#ifdef CONFIG_USB_SERIAL_DEBUG
-       static int debug = 1;
-       #define DEBUG
-#else
-       static int debug;
-       #undef DEBUG
-#endif
-
 #include <linux/usb.h>
-
 #include "usb-serial.h"
 #include "keyspan.h"
 
+static int debug;
+
 /*
  * Version Information
  */
@@ -350,7 +342,7 @@ static int keyspan_ioctl(struct usb_serial_port *port, struct file *file,
 
        /* Write function is similar for the four protocols used
           with only a minor change for usa90 (usa19hs) required */
-static int keyspan_write(struct usb_serial_port *port, int from_user, 
+static int keyspan_write(struct usb_serial_port *port, 
                         const unsigned char *buf, int count)
 {
        struct keyspan_port_private     *p_priv;
@@ -382,7 +374,7 @@ static int keyspan_write(struct usb_serial_port *port, int from_user,
                flip = p_priv->out_flip;
        
                /* Check we have a valid urb/endpoint before we use it... */
-               if ((this_urb = p_priv->out_urbs[flip]) == 0) {
+               if ((this_urb = p_priv->out_urbs[flip]) == NULL) {
                        /* no bulk out, so return 0 bytes written */
                        dbg("%s - no output urb :(", __FUNCTION__);
                        return count;
@@ -391,11 +383,8 @@ static int keyspan_write(struct usb_serial_port *port, int from_user,
                dbg("%s - endpoint %d flip %d", __FUNCTION__, usb_pipeendpoint(this_urb->pipe), flip);
 
                if (this_urb->status == -EINPROGRESS) {
-                       if (this_urb->transfer_flags & URB_ASYNC_UNLINK)
-                               break;
                        if (time_before(jiffies, p_priv->tx_start_time[flip] + 10 * HZ))
                                break;
-                       this_urb->transfer_flags |= URB_ASYNC_UNLINK;
                        usb_unlink_urb(this_urb);
                        break;
                }
@@ -404,18 +393,12 @@ static int keyspan_write(struct usb_serial_port *port, int from_user,
                   for now so set to zero */
                ((char *)this_urb->transfer_buffer)[0] = 0;
 
-               if (from_user) {
-                       if (copy_from_user(this_urb->transfer_buffer + dataOffset, buf, todo))
-                               return -EFAULT;
-               } else {
-                       memcpy (this_urb->transfer_buffer + dataOffset, buf, todo);
-               }
+               memcpy (this_urb->transfer_buffer + dataOffset, buf, todo);
                buf += todo;
 
                /* send the data out the bulk port */
                this_urb->transfer_buffer_length = todo + dataOffset;
 
-               this_urb->transfer_flags &= ~URB_ASYNC_UNLINK;
                this_urb->dev = port->serial->dev;
                if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) {
                        dbg("usb_submit_urb(write bulk) failed (%d)", err);
@@ -1033,11 +1016,11 @@ static int keyspan_write_room (struct usb_serial_port *port)
        flip = p_priv->out_flip;
 
        /* Check both endpoints to see if any are available. */
-       if ((this_urb = p_priv->out_urbs[flip]) != 0) {
+       if ((this_urb = p_priv->out_urbs[flip]) != NULL) {
                if (this_urb->status != -EINPROGRESS)
                        return (data_len);
                flip = (flip + 1) & d_details->outdat_endp_flip;        
-               if ((this_urb = p_priv->out_urbs[flip]) != 0
+               if ((this_urb = p_priv->out_urbs[flip]) != NULL
                        if (this_urb->status != -EINPROGRESS)
                                return (data_len);
        }
@@ -1132,10 +1115,8 @@ static int keyspan_open (struct usb_serial_port *port, struct file *filp)
 
 static inline void stop_urb(struct urb *urb)
 {
-       if (urb && urb->status == -EINPROGRESS) {
-               urb->transfer_flags &= ~URB_ASYNC_UNLINK;
-               usb_unlink_urb(urb);
-       }
+       if (urb && urb->status == -EINPROGRESS)
+               usb_kill_urb(urb);
 }
 
 static void keyspan_close(struct usb_serial_port *port, struct file *filp)
@@ -1175,7 +1156,7 @@ static void keyspan_close(struct usb_serial_port *port, struct file *filp)
                        stop_urb(p_priv->out_urbs[i]);
                }
        }
-       port->tty = 0;
+       port->tty = NULL;
 }
 
 
@@ -1187,16 +1168,16 @@ static int keyspan_fake_startup (struct usb_serial *serial)
        char                            *fw_name;
 
        dbg("Keyspan startup version %04x product %04x",
-           serial->dev->descriptor.bcdDevice,
-           serial->dev->descriptor.idProduct); 
+           le16_to_cpu(serial->dev->descriptor.bcdDevice),
+           le16_to_cpu(serial->dev->descriptor.idProduct));
        
-       if ((serial->dev->descriptor.bcdDevice & 0x8000) != 0x8000) {
+       if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000) != 0x8000) {
                dbg("Firmware already loaded.  Quitting.");
                return(1);
        }
 
                /* Select firmware image on the basis of idProduct */
-       switch (serial->dev->descriptor.idProduct) {
+       switch (le16_to_cpu(serial->dev->descriptor.idProduct)) {
        case keyspan_usa28_pre_product_id:
                record = &keyspan_usa28_firmware[0];
                fw_name = "USA28";
@@ -2261,20 +2242,19 @@ static int keyspan_startup (struct usb_serial *serial)
        dbg("%s", __FUNCTION__);
 
        for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
-               if (d_details->product_id == serial->dev->descriptor.idProduct)
+               if (d_details->product_id == le16_to_cpu(serial->dev->descriptor.idProduct))
                        break;
        if (d_details == NULL) {
-               dev_err(&serial->dev->dev, "%s - unknown product id %x\n", __FUNCTION__, serial->dev->descriptor.idProduct);
+               dev_err(&serial->dev->dev, "%s - unknown product id %x\n", __FUNCTION__, le16_to_cpu(serial->dev->descriptor.idProduct));
                return 1;
        }
 
        /* Setup private data for serial driver */
-       s_priv = kmalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
+       s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
        if (!s_priv) {
                dbg("%s - kmalloc for keyspan_serial_private failed.", __FUNCTION__);
                return -ENOMEM;
        }
-       memset(s_priv, 0, sizeof(struct keyspan_serial_private));
 
        s_priv->device_details = d_details;
        usb_set_serial_data(serial, s_priv);
@@ -2282,12 +2262,11 @@ static int keyspan_startup (struct usb_serial *serial)
        /* Now setup per port private data */
        for (i = 0; i < serial->num_ports; i++) {
                port = serial->port[i];
-               p_priv = kmalloc(sizeof(struct keyspan_port_private), GFP_KERNEL);
+               p_priv = kzalloc(sizeof(struct keyspan_port_private), GFP_KERNEL);
                if (!p_priv) {
                        dbg("%s - kmalloc for keyspan_port_private (%d) failed!.", __FUNCTION__, i);
                        return (1);
                }
-               memset(p_priv, 0, sizeof(struct keyspan_port_private));
                p_priv->device_details = d_details;
                usb_set_serial_port_data(port, p_priv);
        }
@@ -2362,6 +2341,6 @@ MODULE_AUTHOR( DRIVER_AUTHOR );
 MODULE_DESCRIPTION( DRIVER_DESC );
 MODULE_LICENSE("GPL");
 
-MODULE_PARM(debug, "i");
+module_param(debug, bool, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(debug, "Debug enabled or not");