public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Robert Baldyga <r.baldyga@samsung.com>
To: Peter Chen <peter.chen@freescale.com>
Cc: balbi@ti.com, 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 03/23] usb: gadget: f_sourcesink: free requests in sourcesink_disable()
Date: Fri, 06 Nov 2015 09:50:11 +0100	[thread overview]
Message-ID: <563C69C3.2030102@samsung.com> (raw)
In-Reply-To: <20151106081512.GD12560@shlinux2>

On 11/06/2015 09:15 AM, Peter Chen wrote:
> On Tue, Nov 03, 2015 at 01:53:42PM +0100, Robert Baldyga wrote:
>> 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 <r.baldyga@samsung.com>
>> ---
>>  drivers/usb/gadget/function/f_sourcesink.c | 33 +++++++++++++++++++++++++++---
>>  1 file changed, 30 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c
>> index a8b68c6..d8f5f56 100644
>> --- a/drivers/usb/gadget/function/f_sourcesink.c
>> +++ b/drivers/usb/gadget/function/f_sourcesink.c
>> @@ -22,6 +22,8 @@
>>  #include "g_zero.h"
>>  #include "u_f.h"
>>  
>> +#define REQ_CNT	8
>> +
> 
> It would be buffer if we can have module parameter for this like
> qlen at f_loopback.
> 
>>  /*
>>   * SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral
>>   * controller drivers.
>> @@ -51,6 +53,11 @@ struct f_sourcesink {
>>  	struct usb_ep		*iso_out_ep;
>>  	int			cur_alt;
>>  
>> +	struct usb_request	*in_req;
>> +	struct usb_request	*out_req;
>> +	struct usb_request	*iso_in_req[REQ_CNT];
>> +	struct usb_request	*iso_out_req[REQ_CNT];
>> +
>>  	unsigned pattern;
>>  	unsigned isoc_interval;
>>  	unsigned isoc_maxpacket;
>> @@ -561,7 +568,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);
> 
> I find the current code may cause memory leak, since above code
> is only called one time.
> 

I don't see what you mean. Can you explain a bit more in which situation
can memory leak take place?

I've only changed place where requests are freed. Now they are freed in
sourcesink_disable(). The current code is even more memory leak
resistant, because requests will be freed even in case of failure of
usb_ep_queue() in source_sink_complete(), which was not provided so far.

>>  		return;
>>  
>>  	case -EOVERFLOW:		/* buffer overrun on read means that
>> @@ -613,7 +619,7 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in,
>>  		ep = is_in ? ss->in_ep : ss->out_ep;
>>  	}
>>  
>> -	for (i = 0; i < 8; i++) {
>> +	for (i = 0; i < REQ_CNT; i++) {
>>  		req = ss_alloc_ep_req(ep, size);
>>  		if (!req)
>>  			return -ENOMEM;
>> @@ -635,8 +641,18 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in,
>>  			free_ep_req(ep, req);
>>  		}
>>  
>> -		if (!is_iso)
>> +		if (is_iso) {
>> +			if (is_in)
>> +				ss->iso_in_req[i] = req;
>> +			else
>> +				ss->iso_out_req[i] = req;
>> +		} else {
>> +			if (is_in)
>> +				ss->in_req = req;
>> +			else
>> +				ss->out_req = req;
> 
> The req will be different for both bulk and iso, why you only
> have array for iso requests?

Because only for iso endpoints there is allocated more than one request.
I don't know why, but I've decided to not change this.

> 
>>  			break;
>> +		}
>>  	}
>>  
>>  	return status;
>> @@ -764,8 +780,19 @@ 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);
>> +
>> +	free_ep_req(ss->in_ep, ss->in_req);
>> +	free_ep_req(ss->out_ep, ss->out_req);
>> +
>> +	if (ss->iso_in_ep) {
>> +		for (i = 0; i < REQ_CNT; i++) {
>> +			free_ep_req(ss->iso_in_ep, ss->iso_in_req[i]);
>> +			free_ep_req(ss->iso_out_ep, ss->iso_out_req[i]);
>> +		}
>> +	}
>>  }
>>  
>>  /*-------------------------------------------------------------------------*/
>> -- 
>> 1.9.1
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


  reply	other threads:[~2015-11-06  8:50 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 [this message]
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
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=563C69C3.2030102@samsung.com \
    --to=r.baldyga@samsung.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=peter.chen@freescale.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