summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEvgeny Novikov <novikov@ispras.ru>2020-06-26 16:17:47 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-07-29 07:42:56 +0200
commit028792885d6db18b261f809ff17e73273bc8fad3 (patch)
treeca76e70901f7dba198e0e0b69ba9db9d2cf01085
parent95a3bd3f0aa7e12ac7ccda9bb58aa19a7744b042 (diff)
downloadlinux-stable-028792885d6db18b261f809ff17e73273bc8fad3.tar.gz
linux-stable-028792885d6db18b261f809ff17e73273bc8fad3.tar.bz2
linux-stable-028792885d6db18b261f809ff17e73273bc8fad3.zip
usb: gadget: udc: gr_udc: fix memleak on error handling path in gr_ep_init()
[ Upstream commit c8f8529e2c4141afa2ebb487ad48e8a6ec3e8c99 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--drivers/usb/gadget/udc/gr_udc.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/usb/gadget/udc/gr_udc.c b/drivers/usb/gadget/udc/gr_udc.c
index feb73a1c42ef..be094f4e116b 100644
--- a/drivers/usb/gadget/udc/gr_udc.c
+++ b/drivers/usb/gadget/udc/gr_udc.c
@@ -2000,9 +2000,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;
}