usb: gadget: udc: gr_udc: fix memleak on error handling path in gr_ep_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>
This commit is contained in:
Evgeny Novikov 2020-06-26 16:17:47 +03:00 committed by Felipe Balbi
parent 4a0f5a7f2b
commit c8f8529e2c
1 changed files with 5 additions and 2 deletions

View File

@ -1980,9 +1980,12 @@ static int gr_ep_init(struct gr_udc *dev, int num, int is_in, u32 maxplimit)
if (num == 0) { if (num == 0) {
_req = gr_alloc_request(&ep->ep, GFP_ATOMIC); _req = gr_alloc_request(&ep->ep, GFP_ATOMIC);
if (!_req)
return -ENOMEM;
buf = devm_kzalloc(dev->dev, PAGE_SIZE, GFP_DMA | GFP_ATOMIC); buf = devm_kzalloc(dev->dev, PAGE_SIZE, GFP_DMA | GFP_ATOMIC);
if (!_req || !buf) { if (!buf) {
/* possible _req freed by gr_probe via gr_remove */ gr_free_request(&ep->ep, _req);
return -ENOMEM; return -ENOMEM;
} }