Skip to content

Commit

Permalink
cdc-phonet: Don't leak in usbpn_open
Browse files Browse the repository at this point in the history
We allocate memory for 'req' with usb_alloc_urb() and then test
'if (!req || rx_submit(pnd, req, GFP_KERNEL | __GFP_COLD))'.
If we enter that branch due to '!req' then there is no problem. But if
we enter the branch due to 'req' being != 0 and the 'rx_submit()' call
being false, then we'll leak the memory we allocated.
Deal with the leak by always calling 'usb_free_urb(req)' when entering
the branch. If 'req' happens to be 0 then the call is harmless, if it
is not 0 then we free the memory we allocated but don't need.

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Acked-by: Rémi Denis-Courmont <remi@remlab.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jesper Juhl authored and David S. Miller committed Aug 8, 2012
1 parent 155e4e1 commit 47dffc7
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions drivers/net/usb/cdc-phonet.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ static int usbpn_open(struct net_device *dev)
struct urb *req = usb_alloc_urb(0, GFP_KERNEL);

if (!req || rx_submit(pnd, req, GFP_KERNEL | __GFP_COLD)) {
usb_free_urb(req);
usbpn_close(dev);
return -ENOMEM;
}
Expand Down

0 comments on commit 47dffc7

Please sign in to comment.