USB: wusbcore/wa-xfer: error handling fixes in setup_segs()
authorDan Carpenter <dan.carpenter@oracle.com>
Fri, 1 Feb 2013 12:53:34 +0000 (15:53 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 6 Feb 2013 19:38:14 +0000 (11:38 -0800)
1) It didn't free xfer->seg[0] so there was a leak.
2) xfer->seg[cnt] can be NULL.
3) Use usb_free_urb() for ->dto_urb instead of kfree().

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/wusbcore/wa-xfer.c

index 57c01ab09ad85209cedc966e90a3be2d94cb90f7..6ef94bce8c0dc49a5e118c642dbcb4e6c2beddf3 100644 (file)
@@ -695,9 +695,9 @@ error_dto_alloc:
        cnt--;
 error_seg_kzalloc:
        /* use the fact that cnt is left at were it failed */
-       for (; cnt > 0; cnt--) {
-               if (xfer->is_inbound == 0)
-                       kfree(xfer->seg[cnt]->dto_urb);
+       for (; cnt >= 0; cnt--) {
+               if (xfer->seg[cnt] && xfer->is_inbound == 0)
+                       usb_free_urb(xfer->seg[cnt]->dto_urb);
                kfree(xfer->seg[cnt]);
        }
 error_segs_kzalloc: