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 / kl5kusb105.c
index c5207d1..78335a5 100644 (file)
@@ -79,7 +79,6 @@ static int  klsi_105_open              (struct usb_serial_port *port,
 static void klsi_105_close              (struct usb_serial_port *port,
                                          struct file *filp);
 static int  klsi_105_write              (struct usb_serial_port *port,
-                                         int from_user,
                                          const unsigned char *buf,
                                          int count);
 static void klsi_105_write_bulk_callback (struct urb *urb, struct pt_regs *regs);
@@ -117,17 +116,19 @@ static struct usb_device_id id_table [] = {
 MODULE_DEVICE_TABLE (usb, id_table);
 
 static struct usb_driver kl5kusb105d_driver = {
-       .owner =        THIS_MODULE,
        .name =         "kl5kusb105d",
        .probe =        usb_serial_probe,
        .disconnect =   usb_serial_disconnect,
        .id_table =     id_table,
+       .no_dynamic_id =        1,
 };
 
-static struct usb_serial_device_type kl5kusb105d_device = {
-       .owner =             THIS_MODULE,
-       .name =              "KL5KUSB105D / PalmConnect",
-       .short_name =        "kl5kusb105d",
+static struct usb_serial_driver kl5kusb105d_device = {
+       .driver = {
+               .owner =        THIS_MODULE,
+               .name =         "kl5kusb105d",
+       },
+       .description =       "KL5KUSB105D / PalmConnect",
        .id_table =          id_table,
        .num_interrupt_in =  1,
        .num_bulk_in =       1,
@@ -179,7 +180,7 @@ struct klsi_105_private {
  */
 
 
-#define KLSI_TIMEOUT    (HZ * 5 ) /* default urb timeout */
+#define KLSI_TIMEOUT    5000 /* default urb timeout */
 
 static int klsi_105_chg_port_settings(struct usb_serial_port *port,
                                      struct klsi_105_port_settings *settings)
@@ -237,7 +238,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
                             0, /* value */
                             0, /* index */
                             status_buf, KLSI_STATUSBUF_LEN,
-                            10*HZ
+                            10000
                             );
        if (rc < 0)
                err("Reading line status failed (error = %d)", rc);
@@ -336,14 +337,13 @@ static void klsi_105_shutdown (struct usb_serial *serial)
                        for (j = 0; j < NUM_URBS; j++) {
                                if (write_urbs[j]) {
                                        /* FIXME - uncomment the following
-                                        * usb_unlink_urb call when the host
+                                        * usb_kill_urb call when the host
                                         * controllers get fixed to set
                                         * urb->dev = NULL after the urb is
                                         * finished.  Otherwise this call
                                         * oopses. */
-                                       /* usb_unlink_urb(write_urbs[j]); */
-                                       if (write_urbs[j]->transfer_buffer)
-                                                   kfree(write_urbs[j]->transfer_buffer);
+                                       /* usb_kill_urb(write_urbs[j]); */
+                                       kfree(write_urbs[j]->transfer_buffer);
                                        usb_free_urb (write_urbs[j]);
                                }
                        }
@@ -467,12 +467,12 @@ static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
                    err("Disabling read failed (error = %d)", rc);
 
        /* shutdown our bulk reads and writes */
-       usb_unlink_urb (port->write_urb);
-       usb_unlink_urb (port->read_urb);
+       usb_kill_urb(port->write_urb);
+       usb_kill_urb(port->read_urb);
        /* unlink our write pool */
        /* FIXME */
        /* wgg - do I need this? I think so. */
-       usb_unlink_urb (port->interrupt_in_urb);
+       usb_kill_urb(port->interrupt_in_urb);
        info("kl5kusb105 port stats: %ld bytes in, %ld bytes out", priv->bytes_in, priv->bytes_out);
 } /* klsi_105_close */
 
@@ -484,7 +484,7 @@ static void klsi_105_close (struct usb_serial_port *port, struct file *filp)
 #define KLSI_105_DATA_OFFSET   2   /* in the bulk urb data block */
 
 
-static int klsi_105_write (struct usb_serial_port *port, int from_user,
+static int klsi_105_write (struct usb_serial_port *port,
                           const unsigned char *buf, int count)
 {
        struct klsi_105_private *priv = usb_get_serial_port_data(port);
@@ -525,15 +525,7 @@ static int klsi_105_write (struct usb_serial_port *port, int from_user,
                size = min (count, port->bulk_out_size - KLSI_105_DATA_OFFSET);
                size = min (size, URB_TRANSFER_BUFFER_SIZE - KLSI_105_DATA_OFFSET);
 
-               if (from_user) {
-                       if (copy_from_user(urb->transfer_buffer
-                                          + KLSI_105_DATA_OFFSET, buf, size)) {
-                               return -EFAULT;
-                       }
-               } else {
-                       memcpy (urb->transfer_buffer + KLSI_105_DATA_OFFSET,
-                               buf, size);
-               }
+               memcpy (urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size);
 
                /* write payload size into transfer buffer */
                ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF);
@@ -656,7 +648,6 @@ static void klsi_105_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
                usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
                                      urb->actual_length, data);
        } else {
-               int i;
                int bytes_sent = ((__u8 *) data)[0] +
                                 ((unsigned int) ((__u8 *) data)[1] << 8);
                tty = port->tty;
@@ -677,16 +668,8 @@ static void klsi_105_read_bulk_callback (struct urb *urb, struct pt_regs *regs)
                        bytes_sent = urb->actual_length - 2;
                }
 
-               for (i = 2; i < 2+bytes_sent; i++) {
-                       /* if we insert more than TTY_FLIPBUF_SIZE characters,
-                        * we drop them. */
-                       if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
-                               tty_flip_buffer_push(tty);
-                       }
-                       /* this doesn't actually push the data through unless 
-                        * tty->low_latency is set */
-                       tty_insert_flip_char(tty, ((__u8*) data)[i], 0);
-               }
+               tty_buffer_request_room(tty, bytes_sent);
+               tty_insert_flip_string(tty, data + 2, bytes_sent);
                tty_flip_buffer_push(tty);
 
                /* again lockless, but debug info only */
@@ -782,9 +765,11 @@ static void klsi_105_set_termios (struct usb_serial_port *port,
                switch (cflag & CSIZE) {
                case CS5:
                        dbg("%s - 5 bits/byte not supported", __FUNCTION__);
+                       spin_unlock_irqrestore (&priv->lock, flags);
                        return ;
                case CS6:
                        dbg("%s - 6 bits/byte not supported", __FUNCTION__);
+                       spin_unlock_irqrestore (&priv->lock, flags);
                        return ;
                case CS7:
                        priv->cfg.databits = kl5kusb105a_dtb_7;
@@ -932,45 +917,34 @@ static int klsi_105_ioctl (struct usb_serial_port *port, struct file * file,
                /* TODO */
                dbg("%s - TIOCMIWAIT not handled", __FUNCTION__);
                return -ENOIOCTLCMD;
-
        case TIOCGICOUNT:
                /* return count of modemline transitions */
                /* TODO */
                dbg("%s - TIOCGICOUNT not handled", __FUNCTION__);
                return -ENOIOCTLCMD;
-       case TCGETS: {
-            /* return current info to caller */
-            int retval;
-
-            dbg("%s - TCGETS data faked/incomplete", __FUNCTION__);
-
-            retval = verify_area(VERIFY_WRITE, user_arg,
-                                 sizeof(struct termios));
-            if (retval)
-                        return retval;
-
-            if (kernel_termios_to_user_termios((struct termios __user *)arg,
-                                               &priv->termios))
-                    return -EFAULT;
-            return(0);
-            }
-       case TCSETS: {
-               /* set port termios to the one given by the user */
-               int retval;
+       case TCGETS:
+               /* return current info to caller */
+               dbg("%s - TCGETS data faked/incomplete", __FUNCTION__);
+
+               if (!access_ok(VERIFY_WRITE, user_arg, sizeof(struct termios)))
+                       return -EFAULT;
 
+               if (kernel_termios_to_user_termios((struct termios __user *)arg,
+                                                  &priv->termios))
+                       return -EFAULT;
+               return 0;
+       case TCSETS:
+               /* set port termios to the one given by the user */
                dbg("%s - TCSETS not handled", __FUNCTION__);
 
-               retval = verify_area(VERIFY_READ, user_arg,
-                                    sizeof(struct termios));
-               if (retval)
-                           return retval;
+               if (!access_ok(VERIFY_READ, user_arg, sizeof(struct termios)))
+                       return -EFAULT;
 
                if (user_termios_to_kernel_termios(&priv->termios,
-                                                 (struct termios __user *)arg))
+                                                  (struct termios __user *)arg))
                        return -EFAULT;
                klsi_105_set_termios(port, &priv->termios);
-               return(0);
-            }
+               return 0;
        case TCSETSW: {
                /* set port termios and try to wait for completion of last
                 * write operation */
@@ -994,7 +968,7 @@ static int klsi_105_ioctl (struct usb_serial_port *port, struct file * file,
 static void klsi_105_throttle (struct usb_serial_port *port)
 {
        dbg("%s - port %d", __FUNCTION__, port->number);
-       usb_unlink_urb (port->read_urb);
+       usb_kill_urb(port->read_urb);
 }
 
 static void klsi_105_unthrottle (struct usb_serial_port *port)