Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755307AbbLKLkD (ORCPT ); Fri, 11 Dec 2015 06:40:03 -0500 Received: from mailout1.samsung.com ([203.254.224.24]:51062 "EHLO mailout1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754963AbbLKLZk (ORCPT ); Fri, 11 Dec 2015 06:25:40 -0500 X-AuditID: cbfee61a-f79266d000003652-bd-566ab2b34aac 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 03/36] usb: gadget: f_sourcesink: free requests in sourcesink_disable() Date: Fri, 11 Dec 2015 12:24:42 +0100 Message-id: <1449833115-24065-4-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+NgFprOLMWRmVeSWpSXmKPExsVy+t9jQd3Nm7LCDN4sEbOY9bKdxWLjjPWs Fgfv11s0L17PZnF51xw2i0XLWpkt1h65y27x4PBOdgcOj/1z17B79G1Zxehx/MZ2Jo/Pm+QC WKK4bFJSczLLUov07RK4Mm533WAp+CRbceTNcaYGxlviXYycHBICJhIPD7SyQNhiEhfurWfr YuTiEBKYxShx4P5nVgjnJ6PEw3vPmECq2AR0JLZ8n8AIYosICEisf3GJHaSIWeAcUNGdNrCE sECMxKN5d5hBbBYBVYmJzZvBbF4BV4ln33+yQ6yTkzh5bDIriM0p4CYx+eQlsBohoJo3r9cx TmDkXcDIsIpRIrUguaA4KT3XMC+1XK84Mbe4NC9dLzk/dxMjOLieSe1gPLjL/RCjAAejEg/v Ao6sMCHWxLLiytxDjBIczEoivL82AIV4UxIrq1KL8uOLSnNSiw8xSnOwKInz1l6KDBMSSE8s Sc1OTS1ILYLJMnFwSjUwmrF+dU5u3ROYqt+TOEf/cYNhyvVwDccHSy9Ok9nu0Hj8/Ybz8S+v Z3OrsRbeOB3FdHdq4uxIIb3bfqKqZX3LFFeLOR75oP7SpUljhfxM2yO+gRtcKuyP6MwX+nZi U8W2XaqMZzdH3tx7YYdoek01e8kcLu20P73XFD3iesXYlB+eftazIeyhEktxRqKhFnNRcSIA 22tcOSoCAAA= Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3938 Lines: 138 USB requests in SourceSink function are allocated in sourcesink_get_alt() function, so we prefer to free them rather in sourcesink_disable() than in source_sink_complete() when request is completed with error. It provides better symetry in resource management and improves code readability. Signed-off-by: Robert Baldyga --- drivers/usb/gadget/function/f_sourcesink.c | 63 ++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c index e950031..6193b47 100644 --- a/drivers/usb/gadget/function/f_sourcesink.c +++ b/drivers/usb/gadget/function/f_sourcesink.c @@ -44,6 +44,11 @@ struct f_sourcesink { struct usb_ep *iso_out_ep; int cur_alt; + struct usb_request **in_reqs; + struct usb_request **out_reqs; + struct usb_request **iso_in_reqs; + struct usb_request **iso_out_reqs; + unsigned pattern; unsigned isoc_interval; unsigned isoc_maxpacket; @@ -550,7 +555,6 @@ static void source_sink_complete(struct usb_ep *ep, struct usb_request *req) req->actual, req->length); if (ep == ss->out_ep) check_read_data(ss, req); - free_ep_req(ep, req); return; case -EOVERFLOW: /* buffer overrun on read means that @@ -579,7 +583,7 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in, bool is_iso, int speed) { struct usb_ep *ep; - struct usb_request *req; + struct usb_request **reqs; int i, size, qlen, status = 0; if (is_iso) { @@ -604,19 +608,23 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in, qlen = ss->bulk_qlen; size = 0; } - + + reqs = kzalloc(qlen * sizeof(*reqs), GFP_ATOMIC); + for (i = 0; i < qlen; i++) { - req = ss_alloc_ep_req(ep, size); - if (!req) - return -ENOMEM; + reqs[i] = ss_alloc_ep_req(ep, size); + if (!reqs[i]) { + status = -ENOMEM; + goto err; + } - req->complete = source_sink_complete; + reqs[i]->complete = source_sink_complete; if (is_in) - reinit_write_data(ep, req); + reinit_write_data(ep, reqs[i]); else if (ss->pattern != 2) - memset(req->buf, 0x55, req->length); + memset(reqs[i]->buf, 0x55, reqs[i]->length); - status = usb_ep_queue(ep, req, GFP_ATOMIC); + status = usb_ep_queue(ep, reqs[i], GFP_ATOMIC); if (status) { struct usb_composite_dev *cdev; @@ -624,12 +632,30 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in, ERROR(cdev, "start %s%s %s --> %d\n", is_iso ? "ISO-" : "", is_in ? "IN" : "OUT", ep->name, status); - free_ep_req(ep, req); - return status; + free_ep_req(ep, reqs[i]); + goto err; + } + + if (is_iso) { + if (is_in) + ss->iso_in_reqs = reqs; + else + ss->iso_out_reqs = reqs; + } else { + if (is_in) + ss->in_reqs = reqs; + else + ss->out_reqs = reqs; } } return status; + +err: + while (--i) + free_ep_req(ep, reqs[i]); + kfree(reqs); + return status; } static void disable_source_sink(struct f_sourcesink *ss) @@ -754,8 +780,21 @@ static int sourcesink_get_alt(struct usb_function *f, unsigned intf) static void sourcesink_disable(struct usb_function *f) { struct f_sourcesink *ss = func_to_ss(f); + int i; disable_source_sink(ss); + + for (i = 0; i < ss->bulk_qlen; ++i) { + free_ep_req(ss->in_ep, ss->in_reqs[i]); + free_ep_req(ss->out_ep, ss->out_reqs[i]); + } + + if (ss->iso_in_ep) { + for (i = 0; i < ss->iso_qlen; ++i) { + free_ep_req(ss->iso_in_ep, ss->iso_in_reqs[i]); + free_ep_req(ss->iso_out_ep, ss->iso_out_reqs[i]); + } + } } /*-------------------------------------------------------------------------*/ -- 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/