Skip to content

Commit

Permalink
usb: gadget: udc: gr_udc: fix memleak on error handling path in gr_ep…
Browse files Browse the repository at this point in the history
…_init()

gr_ep_init() does not assign the allocated request anywhere if allocation
of memory for the buffer fails. This is a memory leak fixed by the given
patch.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Evgeny Novikov <novikov@ispras.ru>
Signed-off-by: Felipe Balbi <balbi@kernel.org>
  • Loading branch information
Evgeny Novikov authored and Felipe Balbi committed Jul 9, 2020
1 parent 4a0f5a7 commit c8f8529
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions drivers/usb/gadget/udc/gr_udc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1980,9 +1980,12 @@ static int gr_ep_init(struct gr_udc *dev, int num, int is_in, u32 maxplimit)

if (num == 0) {
_req = gr_alloc_request(&ep->ep, GFP_ATOMIC);
if (!_req)
return -ENOMEM;

buf = devm_kzalloc(dev->dev, PAGE_SIZE, GFP_DMA | GFP_ATOMIC);
if (!_req || !buf) {
/* possible _req freed by gr_probe via gr_remove */
if (!buf) {
gr_free_request(&ep->ep, _req);
return -ENOMEM;
}

Expand Down

0 comments on commit c8f8529

Please sign in to comment.