Patchwork USB Network driver infrastructure: Fix leak when usb_autopm_get_interface() returns less than zero in kevent().

login
register
mail settings
Submitter Jesper Juhl
Date Feb. 10, 2011, 8:58 p.m.
Message ID <alpine.LNX.2.00.1102102152450.26035@swampdragon.chaosbits.net>
Download mbox | patch
Permalink /patch/82667/
State Accepted
Delegated to: David Miller
Headers show

Comments

Jesper Juhl - Feb. 10, 2011, 8:58 p.m.
We'll leak the memory allocated to 'urb' in 
drivers/net/usb/usbnet.c:kevent() when we 'goto fail_lowmem' and the 'urb' 
variable goes out of scope while still completely unused.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
---
 usbnet.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

 compile tested only.
David Miller - Feb. 13, 2011, 7:21 p.m.
From: Jesper Juhl <jj@chaosbits.net>
Date: Thu, 10 Feb 2011 21:58:45 +0100 (CET)

> We'll leak the memory allocated to 'urb' in 
> drivers/net/usb/usbnet.c:kevent() when we 'goto fail_lowmem' and the 'urb' 
> variable goes out of scope while still completely unused.
> 
> Signed-off-by: Jesper Juhl <jj@chaosbits.net>

Applied.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
index ed9a416..95c41d5 100644
--- a/drivers/net/usb/usbnet.c
+++ b/drivers/net/usb/usbnet.c
@@ -931,8 +931,10 @@  fail_halt:
 		if (urb != NULL) {
 			clear_bit (EVENT_RX_MEMORY, &dev->flags);
 			status = usb_autopm_get_interface(dev->intf);
-			if (status < 0)
+			if (status < 0) {
+				usb_free_urb(urb);
 				goto fail_lowmem;
+			}
 			if (rx_submit (dev, urb, GFP_KERNEL) == -ENOLINK)
 				resched = 0;
 			usb_autopm_put_interface(dev->intf);