Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1261482
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 03/23] usb: gadget: f_sourcesink: free requests in sourcesink_disable() |
| Date | 2015-11-03 14:00 +0100 |
| Message-ID | <qqJlX-2OU-59@gated-at.bofh.it> (permalink) |
| References | <qqJlU-2OU-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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
+
/*
* 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);
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;
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-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/
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 00/23] usb: gadget: composite: introduce new function API Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:00 +0100
[PATCH 21/23] usb: gadget: f_sourcesink: convert to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:00 +0100
[PATCH 09/23] usb: gadget: composite: handle function bind Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:00 +0100
[PATCH 22/23] usb: gadget: f_ecm: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:00 +0100
[PATCH 19/23] usb: gadget: configfs: add new composite API support Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:00 +0100
[PATCH 15/23] usb: gadget: composite: handle get_alt() automatically Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:00 +0100
[PATCH 01/23] usb: gadget: f_sourcesink: make ISO altset user-selectable Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:00 +0100
Re: [PATCH 01/23] usb: gadget: f_sourcesink: make ISO altset user-selectable Robert Baldyga <r.baldyga@samsung.com> - 2015-11-06 08:30 +0100
[PATCH 03/23] usb: gadget: f_sourcesink: free requests in sourcesink_disable() Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:00 +0100
Re: [PATCH 03/23] usb: gadget: f_sourcesink: free requests in sourcesink_disable() Robert Baldyga <r.baldyga@samsung.com> - 2015-11-06 10:00 +0100
Re: [PATCH 03/23] usb: gadget: f_sourcesink: free requests in sourcesink_disable() Krzysztof Opasiak <k.opasiak@samsung.com> - 2015-11-06 11:00 +0100
[PATCH 06/23] usb: gadget: composite: introduce new descriptors format Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:10 +0100
[PATCH 10/23] usb: gadget: composite: handle vendor descs Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:10 +0100
[PATCH 05/23] usb: gadget: configfs: fix error path Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:10 +0100
Re: [PATCH 05/23] usb: gadget: configfs: fix error path Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> - 2015-11-03 14:50 +0100
[PATCH 11/23] usb: gadget: composite: generate old descs for compatibility Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:10 +0100
[PATCH 02/23] usb: gadget: f_sourcesink: compute req size once Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:10 +0100
[PATCH 07/23] usb: gadget: composite: add functions for descriptors handling Robert Baldyga <r.baldyga@samsung.com> - 2015-11-03 14:10 +0100
csiph-web