Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755339AbbLKLc3 (ORCPT ); Fri, 11 Dec 2015 06:32:29 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:56846 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752030AbbLKL0m (ORCPT ); Fri, 11 Dec 2015 06:26:42 -0500 X-AuditID: cbfee61a-f79266d000003652-0e-566ab2f120fe From: Robert Baldyga To: balbi@ti.com Cc: gregkh@linuxfoundation.org, andrzej.p@samsung.com, m.szyprowski@samsung.com, b.zolnierkie@samsung.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Robert Baldyga Subject: [PATCH v3 24/36] usb: gadget: f_hid: handle requests lifetime properly Date: Fri, 11 Dec 2015 12:25:03 +0100 Message-id: <1449833115-24065-25-git-send-email-r.baldyga@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1449833115-24065-1-git-send-email-r.baldyga@samsung.com> References: <1449833115-24065-1-git-send-email-r.baldyga@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprGLMWRmVeSWpSXmKPExsVy+t9jQd2Pm7LCDL7d47WY9bKdxWLjjPWs Fgfv11s0L17PZnF51xw2i0XLWpkt1h65y27x4PBOdgcOj/1z17B79G1Zxehx/MZ2Jo/Pm+QC WKK4bFJSczLLUov07RK4MpYtucdS8EqoYuPLF8wNjE/4uhg5OSQETCRO7D/JCmGLSVy4t54N xBYSmMUo8ehjSBcjF5D9k1FiYsMWdpAEm4COxJbvExhBbBEBAYn1Ly6xgxQxC5xjlHh4pw0s ISzgL7HkVwNYA4uAqsSHLyuYQGxeATeJudsWM0Fsk5M4eWwy2GZOoPjkk5eYITa7Srx5vY5x AiPvAkaGVYwSqQXJBcVJ6bmGeanlesWJucWleel6yfm5mxjBofVMagfjwV3uhxgFOBiVeHgX cGSFCbEmlhVX5h5ilOBgVhLh/bUBKMSbklhZlVqUH19UmpNafIhRmoNFSZy39lJkmJBAemJJ anZqakFqEUyWiYNTqoHxgMyx6y5LgpMeVj+9pSbMu+X3l0yDxjkhk71/sOQfSjSo/1xW9WX1 EctJF3/e6U/9//Byvdz5L6d3rJkpvfDbu9L+YJ+/jKKTAu6uqMuW6IltvjWhl7+xisH93Ea7 04efvRR687Y278TRC9JrDKUjFA+vbGt6OTcp6yHzl6QXIeInd6XEnl07X4mlOCPRUIu5qDgR ADz+wcApAgAA Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2573 Lines: 87 So far USB requests allocated in hidg_set_alt() were not freed. Now we free them in case of hidg_set_alt() failure (when we are not able to allocate and enqueue all the requests) or in hidg_disable() function. Signed-off-by: Robert Baldyga --- drivers/usb/gadget/function/f_hid.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c index 99285b4..0456a53 100644 --- a/drivers/usb/gadget/function/f_hid.c +++ b/drivers/usb/gadget/function/f_hid.c @@ -59,6 +59,7 @@ struct f_hidg { bool write_pending; wait_queue_head_t write_queue; struct usb_request *req; + struct usb_request **out_reqs; int minor; struct cdev cdev; @@ -490,6 +491,7 @@ static void hidg_disable(struct usb_function *f) { struct f_hidg *hidg = func_to_hidg(f); struct f_hidg_req_list *list, *next; + int i; usb_ep_disable(hidg->in_ep); usb_ep_disable(hidg->out_ep); @@ -498,6 +500,12 @@ static void hidg_disable(struct usb_function *f) list_del(&list->list); kfree(list); } + + for (i = 0; i < hidg->qlen; ++i) { + kfree(hidg->out_reqs[i]->buf); + kfree(hidg->out_reqs[i]); + } + kfree(hidg->out_reqs); } static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) @@ -547,11 +555,14 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) /* * allocate a bunch of read buffers and queue them all at once. */ + hidg->out_reqs = kzalloc(hidg->qlen * + sizeof(*hidg->out_reqs), GFP_KERNEL); for (i = 0; i < hidg->qlen && status == 0; i++) { struct usb_request *req = hidg_alloc_ep_req(hidg->out_ep, hidg->report_length); if (req) { + hidg->out_reqs[i] = req; req->complete = hidg_set_report_complete; req->context = hidg; status = usb_ep_queue(hidg->out_ep, req, @@ -562,11 +573,20 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt) } else { usb_ep_disable(hidg->out_ep); status = -ENOMEM; - goto fail; + goto free_req; } } } +free_req: + if (status < 0) { + while (i--) { + kfree(hidg->out_reqs[i]->buf); + kfree(hidg->out_reqs[i]); + } + kfree(hidg->out_reqs); + } + fail: return status; } -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/