On Fri, Jun 07, 2002, Roland Dreier <[EMAIL PROTECTED]> wrote:
> >>>>> "Johannes" == Johannes Erdfelt <[EMAIL PROTECTED]> writes:
> 
>     Johannes> Nope, the HCD's do that.  This patch looks good, but
>     Johannes> could use a little bit of cleaning up.
> 
> What cleaning up would you like to see?  I would definitely like to
> get these fixes into the main tree so just let me know...

@@ -1044,17 +1072,19 @@
         * If nothing changed, we reprogram the configuration and then
         * the alternate settings.
         */
-       ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, &descriptor,
-                       sizeof(descriptor));
+        descriptor = kmalloc(sizeof *descriptor, GFP_KERNEL);
+       ret = usb_get_descriptor(dev, USB_DT_DEVICE, 0, descriptor,
+                                 sizeof *descriptor);
        if (ret < 0)
                return ret;
[...]

There's a couple of places where you allocate memory, but don't check to
see if it succeeded. That's bad.

Also, I'm not sure what your patch to usb_get_descriptor is for:

diff -Nru a/drivers/usb/usb.c b/drivers/usb/usb.c
--- a/drivers/usb/usb.c Fri Jun  7 16:35:31 2002
+++ b/drivers/usb/usb.c Fri Jun  7 16:35:31 2002
@@ -1787,16 +1787,23 @@
 {
        int i = 5;
        int result;
+        void *tmp_buf;

-       memset(buf,0,size);     // Make sure we parse really received data
+        tmp_buf = kmalloc(size, in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
+        if (!tmp_buf) {
+          return -ENOMEM;
+        }
+       memset(tmp_buf,0,size); // Make sure we parse really received data

        while (i--) {
                if ((result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
                        USB_REQ_GET_DESCRIPTOR, USB_DIR_IN,
-                       (type << 8) + index, 0, buf, size, HZ * GET_TIMEOUT)) > 0 ||
+                       (type << 8) + index, 0, tmp_buf, size, HZ * GET_TIMEOUT)) > 0 
+||
                     result == -EPIPE)
                        break;  /* retry if the returned length was 0; flaky device */
        }
+        memcpy(buf, tmp_buf, size);
+        kfree(tmp_buf);
        return result;
 }

All of the uses of usb_get_descriptor in usb.c are safe. I'd much rather
make the calling routine require a DMA capable buffer than in
usb_get_descriptor.

Also, please use tabs instead of spaces when appropriate :)

JE


_______________________________________________________________

Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas - 
http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink

_______________________________________________
[EMAIL PROTECTED]
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

Reply via email to