* [PATCH 0/3] Gadget endpoint allocation request
@ 2016-08-23 17:24 Felipe F. Tonello
2016-08-23 17:24 ` [PATCH 1/3] usb: gadget: remove useless parameter in alloc_ep_req() Felipe F. Tonello
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Felipe F. Tonello @ 2016-08-23 17:24 UTC (permalink / raw)
To: linux-usb; +Cc: linux-kernel, Felipe Balbi
Patch #1 removes a unnecessary and confusing parameter from alloc_ep_req().
Also, this series updates f_hid function to use alloc/free_ep_req() instead of
allocating/freeing requests directly.
Felipe F. Tonello (3):
usb: gadget: remove useless parameter in alloc_ep_req()
usb: gadget: f_hid: use free_ep_req()
usb: gadget: f_hid: use alloc_ep_req()
drivers/usb/gadget/function/f_hid.c | 18 +++++-------------
drivers/usb/gadget/function/f_loopback.c | 6 ++----
drivers/usb/gadget/function/f_midi.c | 2 +-
drivers/usb/gadget/function/f_sourcesink.c | 6 ++----
drivers/usb/gadget/u_f.c | 7 +++----
drivers/usb/gadget/u_f.h | 3 +--
6 files changed, 14 insertions(+), 28 deletions(-)
--
2.9.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] usb: gadget: remove useless parameter in alloc_ep_req()
2016-08-23 17:24 [PATCH 0/3] Gadget endpoint allocation request Felipe F. Tonello
@ 2016-08-23 17:24 ` Felipe F. Tonello
2016-08-23 17:24 ` [PATCH 2/3] usb: gadget: f_hid: use free_ep_req() Felipe F. Tonello
2016-08-23 17:24 ` [PATCH 3/3] usb: gadget: f_hid: use alloc_ep_req() Felipe F. Tonello
2 siblings, 0 replies; 4+ messages in thread
From: Felipe F. Tonello @ 2016-08-23 17:24 UTC (permalink / raw)
To: linux-usb; +Cc: linux-kernel, Felipe Balbi
The default_length parameter of alloc_ep_req was not really necessary
and gadget drivers would almost always create an inline function to pass
the same value to len and default_len.
This patch removes that parameter and updates all calls to alloc_ep_req() to
use the new API.
Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
---
drivers/usb/gadget/function/f_hid.c | 2 +-
drivers/usb/gadget/function/f_loopback.c | 6 ++----
drivers/usb/gadget/function/f_midi.c | 2 +-
drivers/usb/gadget/function/f_sourcesink.c | 6 ++----
drivers/usb/gadget/u_f.c | 7 +++----
drivers/usb/gadget/u_f.h | 3 +--
6 files changed, 10 insertions(+), 16 deletions(-)
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 4cd486600a9b..fa807ce7fc0e 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -365,7 +365,7 @@ static int f_hidg_open(struct inode *inode, struct file *fd)
static inline struct usb_request *hidg_alloc_ep_req(struct usb_ep *ep,
unsigned length)
{
- return alloc_ep_req(ep, length, length);
+ return alloc_ep_req(ep, length);
}
static void hidg_set_report_complete(struct usb_ep *ep, struct usb_request *req)
diff --git a/drivers/usb/gadget/function/f_loopback.c b/drivers/usb/gadget/function/f_loopback.c
index 3a9f8f9c77bd..ddb8c896eaa3 100644
--- a/drivers/usb/gadget/function/f_loopback.c
+++ b/drivers/usb/gadget/function/f_loopback.c
@@ -308,9 +308,7 @@ static void disable_loopback(struct f_loopback *loop)
static inline struct usb_request *lb_alloc_ep_req(struct usb_ep *ep, int len)
{
- struct f_loopback *loop = ep->driver_data;
-
- return alloc_ep_req(ep, len, loop->buflen);
+ return alloc_ep_req(ep, len);
}
static int alloc_requests(struct usb_composite_dev *cdev,
@@ -333,7 +331,7 @@ static int alloc_requests(struct usb_composite_dev *cdev,
if (!in_req)
goto fail;
- out_req = lb_alloc_ep_req(loop->out_ep, 0);
+ out_req = lb_alloc_ep_req(loop->out_ep, loop->buflen);
if (!out_req)
goto fail_in;
diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
index 3a47596afcab..a5719f271bf0 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -211,7 +211,7 @@ static struct usb_gadget_strings *midi_strings[] = {
static inline struct usb_request *midi_alloc_ep_req(struct usb_ep *ep,
unsigned length)
{
- return alloc_ep_req(ep, length, length);
+ return alloc_ep_req(ep, length);
}
static const uint8_t f_midi_cin_length[] = {
diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c
index df0189ddfdd5..8784fa12ea2c 100644
--- a/drivers/usb/gadget/function/f_sourcesink.c
+++ b/drivers/usb/gadget/function/f_sourcesink.c
@@ -293,9 +293,7 @@ static struct usb_gadget_strings *sourcesink_strings[] = {
static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len)
{
- struct f_sourcesink *ss = ep->driver_data;
-
- return alloc_ep_req(ep, len, ss->buflen);
+ return alloc_ep_req(ep, len);
}
static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
@@ -606,7 +604,7 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in,
} else {
ep = is_in ? ss->in_ep : ss->out_ep;
qlen = ss->bulk_qlen;
- size = 0;
+ size = ss->buflen;
}
for (i = 0; i < qlen; i++) {
diff --git a/drivers/usb/gadget/u_f.c b/drivers/usb/gadget/u_f.c
index 907f8144813c..18839732c840 100644
--- a/drivers/usb/gadget/u_f.c
+++ b/drivers/usb/gadget/u_f.c
@@ -14,15 +14,14 @@
#include "u_f.h"
#include <linux/usb/ch9.h>
-struct usb_request *alloc_ep_req(struct usb_ep *ep, size_t len, int default_len)
+struct usb_request *alloc_ep_req(struct usb_ep *ep, size_t len)
{
struct usb_request *req;
req = usb_ep_alloc_request(ep, GFP_ATOMIC);
if (req) {
- req->length = len ?: default_len;
- if (usb_endpoint_dir_out(ep->desc))
- req->length = usb_ep_align(ep, req->length);
+ req->length = usb_endpoint_dir_out(ep->desc) ?
+ usb_ep_align(ep, len) : len;
req->buf = kmalloc(req->length, GFP_ATOMIC);
if (!req->buf) {
usb_ep_free_request(ep, req);
diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h
index 69a1d10df04f..7d53a4773d1a 100644
--- a/drivers/usb/gadget/u_f.h
+++ b/drivers/usb/gadget/u_f.h
@@ -53,14 +53,13 @@ struct usb_request;
*
* @ep: the endpoint to allocate a usb_request
* @len: usb_requests's buffer suggested size
- * @default_len: used if @len is not provided, ie, is 0
*
* In case @ep direction is OUT, the @len will be aligned to ep's
* wMaxPacketSize. In order to avoid memory leaks or drops, *always* use
* usb_requests's length (req->length) to refer to the allocated buffer size.
* Requests allocated via alloc_ep_req() *must* be freed by free_ep_req().
*/
-struct usb_request *alloc_ep_req(struct usb_ep *ep, size_t len, int default_len);
+struct usb_request *alloc_ep_req(struct usb_ep *ep, size_t len);
/* Frees a usb_request previously allocated by alloc_ep_req() */
static inline void free_ep_req(struct usb_ep *ep, struct usb_request *req)
--
2.9.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] usb: gadget: f_hid: use free_ep_req()
2016-08-23 17:24 [PATCH 0/3] Gadget endpoint allocation request Felipe F. Tonello
2016-08-23 17:24 ` [PATCH 1/3] usb: gadget: remove useless parameter in alloc_ep_req() Felipe F. Tonello
@ 2016-08-23 17:24 ` Felipe F. Tonello
2016-08-23 17:24 ` [PATCH 3/3] usb: gadget: f_hid: use alloc_ep_req() Felipe F. Tonello
2 siblings, 0 replies; 4+ messages in thread
From: Felipe F. Tonello @ 2016-08-23 17:24 UTC (permalink / raw)
To: linux-usb; +Cc: linux-kernel, Felipe Balbi
We should always use free_ep_req() when allocating requests with
alloc_ep_req().
Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
---
drivers/usb/gadget/function/f_hid.c | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index fa807ce7fc0e..aa1c19946d10 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -677,11 +677,8 @@ fail_free_descs:
usb_free_all_descriptors(f);
fail:
ERROR(f->config->cdev, "hidg_bind FAILED\n");
- if (hidg->req != NULL) {
- kfree(hidg->req->buf);
- if (hidg->in_ep != NULL)
- usb_ep_free_request(hidg->in_ep, hidg->req);
- }
+ if (hidg->req != NULL)
+ free_ep_req(hidg->in_ep, hidg->req);
return status;
}
@@ -920,8 +917,7 @@ static void hidg_unbind(struct usb_configuration *c, struct usb_function *f)
/* disable/free request and end point */
usb_ep_disable(hidg->in_ep);
- kfree(hidg->req->buf);
- usb_ep_free_request(hidg->in_ep, hidg->req);
+ free_ep_req(hidg->in_ep, hidg->req);
usb_free_all_descriptors(f);
}
--
2.9.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] usb: gadget: f_hid: use alloc_ep_req()
2016-08-23 17:24 [PATCH 0/3] Gadget endpoint allocation request Felipe F. Tonello
2016-08-23 17:24 ` [PATCH 1/3] usb: gadget: remove useless parameter in alloc_ep_req() Felipe F. Tonello
2016-08-23 17:24 ` [PATCH 2/3] usb: gadget: f_hid: use free_ep_req() Felipe F. Tonello
@ 2016-08-23 17:24 ` Felipe F. Tonello
2 siblings, 0 replies; 4+ messages in thread
From: Felipe F. Tonello @ 2016-08-23 17:24 UTC (permalink / raw)
To: linux-usb; +Cc: linux-kernel, Felipe Balbi
Use gadget's framework allocation function instead of directly calling
usb_ep_alloc_request().
Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
---
drivers/usb/gadget/function/f_hid.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index aa1c19946d10..e2966f87c860 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -617,14 +617,10 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
/* preallocate request and buffer */
status = -ENOMEM;
- hidg->req = usb_ep_alloc_request(hidg->in_ep, GFP_KERNEL);
+ hidg->req = alloc_ep_req(hidg->in_ep, hidg->report_length);
if (!hidg->req)
goto fail;
- hidg->req->buf = kmalloc(hidg->report_length, GFP_KERNEL);
- if (!hidg->req->buf)
- goto fail;
-
/* set descriptor dynamic values */
hidg_interface_desc.bInterfaceSubClass = hidg->bInterfaceSubClass;
hidg_interface_desc.bInterfaceProtocol = hidg->bInterfaceProtocol;
--
2.9.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2016-08-23 17:26 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-23 17:24 [PATCH 0/3] Gadget endpoint allocation request Felipe F. Tonello
2016-08-23 17:24 ` [PATCH 1/3] usb: gadget: remove useless parameter in alloc_ep_req() Felipe F. Tonello
2016-08-23 17:24 ` [PATCH 2/3] usb: gadget: f_hid: use free_ep_req() Felipe F. Tonello
2016-08-23 17:24 ` [PATCH 3/3] usb: gadget: f_hid: use alloc_ep_req() Felipe F. Tonello
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.