1 From foo@baz Mon Oct 8 18:01:43 CEST 2018
2 From: Anton Vasilyev <vasilyev@ispras.ru>
3 Date: Tue, 7 Aug 2018 14:44:48 +0300
4 Subject: usb: gadget: fotg210-udc: Fix memory leak of fotg210->ep[i]
6 From: Anton Vasilyev <vasilyev@ispras.ru>
8 [ Upstream commit c37bd52836296ecc9a0fc8060b819089aebdbcde ]
10 There is no deallocation of fotg210->ep[i] elements, allocated at
13 The patch adds deallocation of fotg210->ep array elements and simplifies
14 error path of fotg210_udc_probe().
16 Found by Linux Driver Verification project (linuxtesting.org).
18 Signed-off-by: Anton Vasilyev <vasilyev@ispras.ru>
19 Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
20 Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
21 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
23 drivers/usb/gadget/udc/fotg210-udc.c | 15 ++++++++++-----
24 1 file changed, 10 insertions(+), 5 deletions(-)
26 --- a/drivers/usb/gadget/udc/fotg210-udc.c
27 +++ b/drivers/usb/gadget/udc/fotg210-udc.c
28 @@ -1066,12 +1066,15 @@ static struct usb_gadget_ops fotg210_gad
29 static int fotg210_udc_remove(struct platform_device *pdev)
31 struct fotg210_udc *fotg210 = platform_get_drvdata(pdev);
34 usb_del_gadget_udc(&fotg210->gadget);
35 iounmap(fotg210->reg);
36 free_irq(platform_get_irq(pdev, 0), fotg210);
38 fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req);
39 + for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
40 + kfree(fotg210->ep[i]);
44 @@ -1102,7 +1105,7 @@ static int fotg210_udc_probe(struct plat
46 fotg210 = kzalloc(sizeof(struct fotg210_udc), GFP_KERNEL);
51 for (i = 0; i < FOTG210_MAX_NUM_EP; i++) {
52 _ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL);
53 @@ -1114,7 +1117,7 @@ static int fotg210_udc_probe(struct plat
54 fotg210->reg = ioremap(res->start, resource_size(res));
55 if (fotg210->reg == NULL) {
56 pr_err("ioremap error.\n");
61 spin_lock_init(&fotg210->lock);
62 @@ -1162,7 +1165,7 @@ static int fotg210_udc_probe(struct plat
63 fotg210->ep0_req = fotg210_ep_alloc_request(&fotg210->ep[0]->ep,
65 if (fotg210->ep0_req == NULL)
69 fotg210_init(fotg210);
71 @@ -1190,12 +1193,14 @@ err_req:
72 fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req);
76 - iounmap(fotg210->reg);
77 + iounmap(fotg210->reg);
80 + for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
81 + kfree(fotg210->ep[i]);