From: Felipe Ferreri Tonello <eu@felipetonello.com>
To: Robert Baldyga <r.baldyga@samsung.com>, 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
Subject: Re: [PATCH 04/23] usb: gadget: f_loopback: free requests in loopback_disable()
Date: Wed, 4 Nov 2015 10:15:52 +0000 [thread overview]
Message-ID: <5639DAD8.40204@felipetonello.com> (raw)
In-Reply-To: <1446555242-3733-5-git-send-email-r.baldyga@samsung.com>
Hi Robert,
On 03/11/15 12:53, Robert Baldyga wrote:
> USB requests in Loopback function are allocated in loopback_get_alt()
> function, so we prefer to free them rather in loopback_disable() than
> in loopback_complete() when request is completed with error. It provides
> better symetry in resource management and improves code readability.
Are we doing this for all functions? Because I see that several
functions does the same thing, they free IN/OUT ep requests on
complete() instead of disable().
I also prefer this, but then we need to refactor most function code.
>
> Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
> ---
> drivers/usb/gadget/function/f_loopback.c | 58 +++++++++++++-------------------
> 1 file changed, 23 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/f_loopback.c b/drivers/usb/gadget/function/f_loopback.c
> index 6b2102b..41464ae 100644
> --- a/drivers/usb/gadget/function/f_loopback.c
> +++ b/drivers/usb/gadget/function/f_loopback.c
> @@ -35,6 +35,9 @@ struct f_loopback {
> struct usb_ep *in_ep;
> struct usb_ep *out_ep;
>
> + struct usb_request *in_req;
> + struct usb_request *out_req;
> +
> unsigned qlen;
> unsigned buflen;
> };
> @@ -249,30 +252,25 @@ static void loopback_complete(struct usb_ep *ep, struct usb_request *req)
> * We received some data from the host so let's
> * queue it so host can read the from our in ep
> */
> - struct usb_request *in_req = req->context;
> -
> - in_req->zero = (req->actual < req->length);
> - in_req->length = req->actual;
> + loop->in_req->zero = (req->actual < req->length);
> + loop->in_req->length = req->actual;
> + req = loop->in_req;
> ep = loop->in_ep;
> - req = in_req;
> } else {
> /*
> * We have just looped back a bunch of data
> * to host. Now let's wait for some more data.
> */
> - req = req->context;
> + req = loop->out_req;
> ep = loop->out_ep;
> }
>
> /* queue the buffer back to host or for next bunch of data */
> status = usb_ep_queue(ep, req, GFP_ATOMIC);
> - if (status == 0) {
> - return;
> - } else {
> + if (status < 0)
> ERROR(cdev, "Unable to loop back buffer to %s: %d\n",
> ep->name, status);
> - goto free_req;
> - }
> + break;
>
> /* "should never get here" */
> default:
> @@ -280,20 +278,10 @@ static void loopback_complete(struct usb_ep *ep, struct usb_request *req)
> status, req->actual, req->length);
> /* FALLTHROUGH */
>
> - /* NOTE: since this driver doesn't maintain an explicit record
> - * of requests it submitted (just maintains qlen count), we
> - * rely on the hardware driver to clean up on disconnect or
> - * endpoint disable.
> - */
> case -ECONNABORTED: /* hardware forced ep reset */
> case -ECONNRESET: /* request dequeued */
> case -ESHUTDOWN: /* disconnect from host */
> -free_req:
> - usb_ep_free_request(ep == loop->in_ep ?
> - loop->out_ep : loop->in_ep,
> - req->context);
> - free_ep_req(ep, req);
> - return;
> + break;
> }
> }
>
> @@ -316,7 +304,6 @@ static inline struct usb_request *lb_alloc_ep_req(struct usb_ep *ep, int len)
> static int alloc_requests(struct usb_composite_dev *cdev,
> struct f_loopback *loop)
> {
> - struct usb_request *in_req, *out_req;
> int i;
> int result = 0;
>
> @@ -329,23 +316,21 @@ static int alloc_requests(struct usb_composite_dev *cdev,
> for (i = 0; i < loop->qlen && result == 0; i++) {
> result = -ENOMEM;
>
> - in_req = usb_ep_alloc_request(loop->in_ep, GFP_KERNEL);
> - if (!in_req)
> + loop->in_req = usb_ep_alloc_request(loop->in_ep, GFP_KERNEL);
> + if (!loop->in_req)
> goto fail;
>
> - out_req = lb_alloc_ep_req(loop->out_ep, 0);
> - if (!out_req)
> + loop->out_req = lb_alloc_ep_req(loop->out_ep, 0);
> + if (!loop->out_req)
> goto fail_in;
>
> - in_req->complete = loopback_complete;
> - out_req->complete = loopback_complete;
> + loop->in_req->complete = loopback_complete;
> + loop->out_req->complete = loopback_complete;
>
> - in_req->buf = out_req->buf;
> + loop->in_req->buf = loop->out_req->buf;
> /* length will be set in complete routine */
> - in_req->context = out_req;
> - out_req->context = in_req;
>
> - result = usb_ep_queue(loop->out_ep, out_req, GFP_ATOMIC);
> + result = usb_ep_queue(loop->out_ep, loop->out_req, GFP_ATOMIC);
> if (result) {
> ERROR(cdev, "%s queue req --> %d\n",
> loop->out_ep->name, result);
> @@ -356,9 +341,9 @@ static int alloc_requests(struct usb_composite_dev *cdev,
> return 0;
>
> fail_out:
> - free_ep_req(loop->out_ep, out_req);
> + free_ep_req(loop->out_ep, loop->out_req);
> fail_in:
> - usb_ep_free_request(loop->in_ep, in_req);
> + usb_ep_free_request(loop->in_ep, loop->in_req);
> fail:
> return result;
> }
> @@ -426,6 +411,9 @@ static void loopback_disable(struct usb_function *f)
> struct f_loopback *loop = func_to_loop(f);
>
> disable_loopback(loop);
> +
> + free_ep_req(loop->out_ep, loop->out_req);
> + usb_ep_free_request(loop->in_ep, loop->in_req);
> }
>
> static struct usb_function *loopback_alloc(struct usb_function_instance *fi)
>
--
Felipe
next prev parent reply other threads:[~2015-11-04 10:15 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-03 12:53 [PATCH 00/23] usb: gadget: composite: introduce new function API Robert Baldyga
2015-11-03 12:53 ` [PATCH 01/23] usb: gadget: f_sourcesink: make ISO altset user-selectable Robert Baldyga
2015-11-06 3:05 ` Peter Chen
2015-11-06 7:26 ` Robert Baldyga
2015-11-03 12:53 ` [PATCH 02/23] usb: gadget: f_sourcesink: compute req size once Robert Baldyga
2015-11-06 3:07 ` Peter Chen
2015-11-03 12:53 ` [PATCH 03/23] usb: gadget: f_sourcesink: free requests in sourcesink_disable() Robert Baldyga
2015-11-06 8:15 ` Peter Chen
2015-11-06 8:50 ` Robert Baldyga
2015-11-06 9:48 ` Peter Chen
2015-11-06 9:58 ` Krzysztof Opasiak
2015-11-10 2:02 ` Peter Chen
2015-11-16 16:43 ` Krzysztof Opasiak
2015-11-03 12:53 ` [PATCH 04/23] usb: gadget: f_loopback: free requests in loopback_disable() Robert Baldyga
2015-11-04 10:15 ` Felipe Ferreri Tonello [this message]
2015-11-04 11:02 ` Robert Baldyga
2015-11-03 12:53 ` [PATCH 05/23] usb: gadget: configfs: fix error path Robert Baldyga
2015-11-03 13:45 ` Sergei Shtylyov
2015-11-03 12:53 ` [PATCH 06/23] usb: gadget: composite: introduce new descriptors format Robert Baldyga
2015-11-03 12:53 ` [PATCH 07/23] usb: gadget: composite: add functions for descriptors handling Robert Baldyga
2015-11-03 12:53 ` [PATCH 08/23] usb: gadget: composite: introduce new USB function ops Robert Baldyga
2015-11-03 12:53 ` [PATCH 09/23] usb: gadget: composite: handle function bind Robert Baldyga
2015-11-03 12:53 ` [PATCH 10/23] usb: gadget: composite: handle vendor descs Robert Baldyga
2015-11-03 12:53 ` [PATCH 11/23] usb: gadget: composite: generate old descs for compatibility Robert Baldyga
2015-11-03 12:53 ` [PATCH 12/23] usb: gadget: composite: disable eps before calling disable() callback Robert Baldyga
2015-11-03 12:53 ` [PATCH 13/23] usb: gadget: composite: enable eps before calling set_alt() callback Robert Baldyga
2015-11-03 12:53 ` [PATCH 14/23] usb: gadget: composite: introduce clear_alt() operation Robert Baldyga
2015-11-03 12:53 ` [PATCH 15/23] usb: gadget: composite: handle get_alt() automatically Robert Baldyga
2015-11-03 12:53 ` [PATCH 16/23] usb: gadget: composite: add usb_function_get_ep() function Robert Baldyga
2015-11-03 12:53 ` [PATCH 17/23] usb: gadget: composite: add usb_get_interface_id() function Robert Baldyga
2015-11-03 12:53 ` [PATCH 18/23] usb: gadget: composite: enable adding USB functions using new API Robert Baldyga
2015-11-03 12:53 ` [PATCH 19/23] usb: gadget: configfs: add new composite API support Robert Baldyga
2015-11-03 12:53 ` [PATCH 20/23] usb: gadget: f_loopback: convert to new API Robert Baldyga
2015-11-03 12:54 ` [PATCH 21/23] usb: gadget: f_sourcesink: " Robert Baldyga
2015-11-03 12:54 ` [PATCH 22/23] usb: gadget: f_ecm: conversion " Robert Baldyga
2015-11-03 12:54 ` [PATCH 23/23] usb: gadget: f_rndis: " Robert Baldyga
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5639DAD8.40204@felipetonello.com \
--to=eu@felipetonello.com \
--cc=andrzej.p@samsung.com \
--cc=b.zolnierkie@samsung.com \
--cc=balbi@ti.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=m.szyprowski@samsung.com \
--cc=r.baldyga@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox