USB: usb_get_string should check the descriptor type
[pandora-kernel.git] / drivers / usb / core / message.c
index 315363b..2aa2a58 100644 (file)
@@ -389,7 +389,6 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
        if (io->entries <= 0)
                return io->entries;
 
-       io->count = io->entries;
        io->urbs = kmalloc(io->entries * sizeof *io->urbs, mem_flags);
        if (!io->urbs)
                goto nomem;
@@ -400,7 +399,7 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
        if (usb_pipein(pipe))
                urb_flags |= URB_SHORT_NOT_OK;
 
-       for (i = 0; i < io->entries; i++) {
+       for_each_sg(sg, sg, io->entries, i) {
                unsigned len;
 
                io->urbs[i] = usb_alloc_urb(0, mem_flags);
@@ -434,17 +433,17 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
                 * to prevent stale pointers and to help spot bugs.
                 */
                if (dma) {
-                       io->urbs[i]->transfer_dma = sg_dma_address(sg + i);
-                       len = sg_dma_len(sg + i);
+                       io->urbs[i]->transfer_dma = sg_dma_address(sg);
+                       len = sg_dma_len(sg);
 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_GART_IOMMU)
                        io->urbs[i]->transfer_buffer = NULL;
 #else
-                       io->urbs[i]->transfer_buffer = sg_virt(&sg[i]);
+                       io->urbs[i]->transfer_buffer = sg_virt(sg);
 #endif
                } else {
                        /* hc may use _only_ transfer_buffer */
-                       io->urbs[i]->transfer_buffer = sg_virt(&sg[i]);
-                       len = sg[i].length;
+                       io->urbs[i]->transfer_buffer = sg_virt(sg);
+                       len = sg->length;
                }
 
                if (length) {
@@ -458,6 +457,7 @@ int usb_sg_init(struct usb_sg_request *io, struct usb_device *dev,
        io->urbs[--i]->transfer_flags &= ~URB_NO_INTERRUPT;
 
        /* transaction state */
+       io->count = io->entries;
        io->status = 0;
        io->bytes = 0;
        init_completion(&io->complete);
@@ -651,7 +651,7 @@ int usb_get_descriptor(struct usb_device *dev, unsigned char type,
                if (result <= 0 && result != -ETIMEDOUT)
                        continue;
                if (result > 1 && ((u8 *)buf)[1] != type) {
-                       result = -EPROTO;
+                       result = -ENODATA;
                        continue;
                }
                break;
@@ -694,8 +694,13 @@ static int usb_get_string(struct usb_device *dev, unsigned short langid,
                        USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
                        (USB_DT_STRING << 8) + index, langid, buf, size,
                        USB_CTRL_GET_TIMEOUT);
-               if (!(result == 0 || result == -EPIPE))
-                       break;
+               if (result == 0 || result == -EPIPE)
+                       continue;
+               if (result > 1 && ((u8 *) buf)[1] != USB_DT_STRING) {
+                       result = -ENODATA;
+                       continue;
+               }
+               break;
        }
        return result;
 }
@@ -1091,8 +1096,9 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
                                continue;
                        dev_dbg(&dev->dev, "unregistering interface %s\n",
                                dev_name(&interface->dev));
-                       device_del(&interface->dev);
+                       interface->unregistering = 1;
                        usb_remove_sysfs_intf_files(interface);
+                       device_del(&interface->dev);
                }
 
                /* Now that the interfaces are unbound, nobody should
@@ -1476,7 +1482,7 @@ static struct usb_interface_assoc_descriptor *find_iad(struct usb_device *dev,
  *
  * This call is synchronous. The calling context must be able to sleep,
  * must own the device lock, and must not hold the driver model's USB
- * bus mutex; usb device driver probe() methods cannot use this routine.
+ * bus mutex; usb interface driver probe() methods cannot use this routine.
  *
  * Returns zero on success, or else the status code returned by the
  * underlying call that failed.  On successful completion, each interface