Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1256164 > unrolled thread
| Started by | "Felipe F. Tonello" <eu@felipetonello.com> |
|---|---|
| First post | 2015-10-26 18:00 +0100 |
| Last post | 2015-10-27 15:20 +0100 |
| Articles | 13 — 5 participants |
Back to article view | Back to linux.kernel
[PATCH v4 0/7] USB MIDI Gadget improvements and bug fixes "Felipe F. Tonello" <eu@felipetonello.com> - 2015-10-26 18:00 +0100
[PATCH v4 3/7] usb: gadget: define free_ep_req as universal function "Felipe F. Tonello" <eu@felipetonello.com> - 2015-10-26 18:00 +0100
Re: [PATCH v4 3/7] usb: gadget: define free_ep_req as universal function Robert Baldyga <r.baldyga@samsung.com> - 2015-10-27 08:00 +0100
Re: [PATCH v4 3/7] usb: gadget: define free_ep_req as universal function Felipe Ferreri Tonello <eu@felipetonello.com> - 2015-10-27 10:20 +0100
Re: [PATCH v4 3/7] usb: gadget: define free_ep_req as universal function Robert Baldyga <r.baldyga@samsung.com> - 2015-10-27 10:50 +0100
Re: [PATCH v4 3/7] usb: gadget: define free_ep_req as universal function Felipe Ferreri Tonello <eu@felipetonello.com> - 2015-10-27 14:00 +0100
[PATCH v4 6/7] usb: gadget: gmidi: Cleanup legacy code "Felipe F. Tonello" <eu@felipetonello.com> - 2015-10-26 18:00 +0100
[PATCH v4 5/7] usb: gadget: f_midi: set altsettings only for MIDIStreaming interface "Felipe F. Tonello" <eu@felipetonello.com> - 2015-10-26 18:00 +0100
Re: [PATCH v4 5/7] usb: gadget: f_midi: set altsettings only for MIDIStreaming interface Robert Baldyga <r.baldyga@hackerion.com> - 2015-10-26 23:40 +0100
Re: [PATCH v4 5/7] usb: gadget: f_midi: set altsettings only for MIDIStreaming interface Felipe Tonello <eu@felipetonello.com> - 2015-10-27 00:00 +0100
Re: [PATCH v4 5/7] usb: gadget: f_midi: set altsettings only for MIDIStreaming interface Robert Baldyga <r.baldyga@samsung.com> - 2015-10-27 07:50 +0100
Re: [PATCH v4 5/7] usb: gadget: f_midi: set altsettings only for MIDIStreaming interface Felipe Ferreri Tonello <eu@felipetonello.com> - 2015-10-27 10:20 +0100
Re: [PATCH v4 0/7] USB MIDI Gadget improvements and bug fixes Felipe Ferreri Tonello <eu@felipetonello.com> - 2015-10-27 15:20 +0100
| From | "Felipe F. Tonello" <eu@felipetonello.com> |
|---|---|
| Date | 2015-10-26 18:00 +0100 |
| Subject | [PATCH v4 0/7] USB MIDI Gadget improvements and bug fixes |
| Message-ID | <qnThM-2d0-3@gated-at.bofh.it> |
Patch 7 has changes on how to transmit IN USB requests. It implements a FIFO of pre-allocated usb requests and uses then as needed, instead of allocating then on demand. This is my initial implementation and is open for suggestions and comments. Patches 1-6 is pretty much straight forward. changes in v4: - pre-alocation of in requests. - more code clean up - fix memory leak on out requests - configure endpoints only when setting up MIDIStreaming interface Felipe F. Tonello (7): usb: gadget: f_midi: Transmit data only when IN ep is enabled usb: gadget: f_midi: remove duplicated code usb: gadget: define free_ep_req as universal function usb: gadget: f_midi: fix leak on failed to enqueue out requests usb: gadget: f_midi: set altsettings only for MIDIStreaming interface usb: gadget: gmidi: Cleanup legacy code usb: gadget: f_midi: pre-allocate IN requests drivers/usb/gadget/function/f_midi.c | 201 ++++++++++++++++++++--------- drivers/usb/gadget/function/f_sourcesink.c | 6 - drivers/usb/gadget/function/g_zero.h | 1 - drivers/usb/gadget/legacy/gmidi.c | 12 +- drivers/usb/gadget/u_f.c | 8 ++ drivers/usb/gadget/u_f.h | 3 +- 6 files changed, 151 insertions(+), 80 deletions(-) -- 2.1.4 -- 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/
[toc] | [next] | [standalone]
| From | "Felipe F. Tonello" <eu@felipetonello.com> |
|---|---|
| Date | 2015-10-26 18:00 +0100 |
| Subject | [PATCH v4 3/7] usb: gadget: define free_ep_req as universal function |
| Message-ID | <qnThN-2d0-25@gated-at.bofh.it> |
| In reply to | #1256164 |
This function is shared between gadget functions, so this avoid unnecessary
duplicated code and potentially avoid memory leaks.
Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
---
drivers/usb/gadget/function/f_midi.c | 6 ------
drivers/usb/gadget/function/f_sourcesink.c | 6 ------
drivers/usb/gadget/function/g_zero.h | 1 -
drivers/usb/gadget/u_f.c | 8 ++++++++
drivers/usb/gadget/u_f.h | 3 +--
5 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
index c19f154..4c01c8a 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -202,12 +202,6 @@ static inline struct usb_request *midi_alloc_ep_req(struct usb_ep *ep,
return alloc_ep_req(ep, length, length);
}
-static void free_ep_req(struct usb_ep *ep, struct usb_request *req)
-{
- kfree(req->buf);
- usb_ep_free_request(ep, req);
-}
-
static const uint8_t f_midi_cin_length[] = {
0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1
};
diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c
index 3a5ae99..eedea7f 100644
--- a/drivers/usb/gadget/function/f_sourcesink.c
+++ b/drivers/usb/gadget/function/f_sourcesink.c
@@ -307,12 +307,6 @@ static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len)
return alloc_ep_req(ep, len, buflen);
}
-void free_ep_req(struct usb_ep *ep, struct usb_request *req)
-{
- kfree(req->buf);
- usb_ep_free_request(ep, req);
-}
-
static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
{
int value;
diff --git a/drivers/usb/gadget/function/g_zero.h b/drivers/usb/gadget/function/g_zero.h
index 15f1809..5ed90b4 100644
--- a/drivers/usb/gadget/function/g_zero.h
+++ b/drivers/usb/gadget/function/g_zero.h
@@ -59,7 +59,6 @@ void lb_modexit(void);
int lb_modinit(void);
/* common utilities */
-void free_ep_req(struct usb_ep *ep, struct usb_request *req);
void disable_endpoints(struct usb_composite_dev *cdev,
struct usb_ep *in, struct usb_ep *out,
struct usb_ep *iso_in, struct usb_ep *iso_out);
diff --git a/drivers/usb/gadget/u_f.c b/drivers/usb/gadget/u_f.c
index c6276f0..f78bd1f 100644
--- a/drivers/usb/gadget/u_f.c
+++ b/drivers/usb/gadget/u_f.c
@@ -14,6 +14,7 @@
#include <linux/usb/gadget.h>
#include "u_f.h"
+/* Requests allocated via alloc_ep_req() must be freed by free_ep_req(). */
struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len)
{
struct usb_request *req;
@@ -30,3 +31,10 @@ struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len)
return req;
}
EXPORT_SYMBOL_GPL(alloc_ep_req);
+
+void free_ep_req(struct usb_ep *ep, struct usb_request *req)
+{
+ kfree(req->buf);
+ usb_ep_free_request(ep, req);
+}
+EXPORT_SYMBOL_GPL(free_ep_req);
diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h
index 1d5f0eb..2a1a6fb 100644
--- a/drivers/usb/gadget/u_f.h
+++ b/drivers/usb/gadget/u_f.h
@@ -46,7 +46,6 @@ struct usb_ep;
struct usb_request;
struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len);
+void free_ep_req(struct usb_ep *ep, struct usb_request *req);
#endif /* __U_F_H__ */
-
-
--
2.1.4
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2015-10-27 08:00 +0100 |
| Subject | Re: [PATCH v4 3/7] usb: gadget: define free_ep_req as universal function |
| Message-ID | <qo6oG-1Wi-9@gated-at.bofh.it> |
| In reply to | #1256165 |
On 10/26/2015 05:55 PM, Felipe F. Tonello wrote:
> This function is shared between gadget functions, so this avoid unnecessary
> duplicated code and potentially avoid memory leaks.
>
> Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
> ---
> drivers/usb/gadget/function/f_midi.c | 6 ------
> drivers/usb/gadget/function/f_sourcesink.c | 6 ------
> drivers/usb/gadget/function/g_zero.h | 1 -
> drivers/usb/gadget/u_f.c | 8 ++++++++
> drivers/usb/gadget/u_f.h | 3 +--
> 5 files changed, 9 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
> index c19f154..4c01c8a 100644
> --- a/drivers/usb/gadget/function/f_midi.c
> +++ b/drivers/usb/gadget/function/f_midi.c
> @@ -202,12 +202,6 @@ static inline struct usb_request *midi_alloc_ep_req(struct usb_ep *ep,
> return alloc_ep_req(ep, length, length);
> }
>
> -static void free_ep_req(struct usb_ep *ep, struct usb_request *req)
> -{
> - kfree(req->buf);
> - usb_ep_free_request(ep, req);
> -}
> -
> static const uint8_t f_midi_cin_length[] = {
> 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1
> };
> diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c
> index 3a5ae99..eedea7f 100644
> --- a/drivers/usb/gadget/function/f_sourcesink.c
> +++ b/drivers/usb/gadget/function/f_sourcesink.c
> @@ -307,12 +307,6 @@ static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len)
> return alloc_ep_req(ep, len, buflen);
> }
>
> -void free_ep_req(struct usb_ep *ep, struct usb_request *req)
> -{
> - kfree(req->buf);
> - usb_ep_free_request(ep, req);
> -}
> -
> static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
> {
> int value;
> diff --git a/drivers/usb/gadget/function/g_zero.h b/drivers/usb/gadget/function/g_zero.h
> index 15f1809..5ed90b4 100644
> --- a/drivers/usb/gadget/function/g_zero.h
> +++ b/drivers/usb/gadget/function/g_zero.h
> @@ -59,7 +59,6 @@ void lb_modexit(void);
> int lb_modinit(void);
>
> /* common utilities */
> -void free_ep_req(struct usb_ep *ep, struct usb_request *req);
> void disable_endpoints(struct usb_composite_dev *cdev,
> struct usb_ep *in, struct usb_ep *out,
> struct usb_ep *iso_in, struct usb_ep *iso_out);
> diff --git a/drivers/usb/gadget/u_f.c b/drivers/usb/gadget/u_f.c
> index c6276f0..f78bd1f 100644
> --- a/drivers/usb/gadget/u_f.c
> +++ b/drivers/usb/gadget/u_f.c
> @@ -14,6 +14,7 @@
> #include <linux/usb/gadget.h>
> #include "u_f.h"
>
> +/* Requests allocated via alloc_ep_req() must be freed by free_ep_req(). */
> struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len)
> {
> struct usb_request *req;
> @@ -30,3 +31,10 @@ struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len)
> return req;
> }
> EXPORT_SYMBOL_GPL(alloc_ep_req);
> +
> +void free_ep_req(struct usb_ep *ep, struct usb_request *req)
> +{
> + kfree(req->buf);
> + usb_ep_free_request(ep, req);
> +}
> +EXPORT_SYMBOL_GPL(free_ep_req);
> diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h
> index 1d5f0eb..2a1a6fb 100644
> --- a/drivers/usb/gadget/u_f.h
> +++ b/drivers/usb/gadget/u_f.h
> @@ -46,7 +46,6 @@ struct usb_ep;
> struct usb_request;
>
> struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len);
> +void free_ep_req(struct usb_ep *ep, struct usb_request *req);
>
> #endif /* __U_F_H__ */
> -
> -
>
Isn't it simple enough to be static inline?
Best regards,
Robert
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Felipe Ferreri Tonello <eu@felipetonello.com> |
|---|---|
| Date | 2015-10-27 10:20 +0100 |
| Subject | Re: [PATCH v4 3/7] usb: gadget: define free_ep_req as universal function |
| Message-ID | <qo8Ab-3pT-15@gated-at.bofh.it> |
| In reply to | #1256509 |
Hi Robert,
On 27/10/15 06:53, Robert Baldyga wrote:
> On 10/26/2015 05:55 PM, Felipe F. Tonello wrote:
>> This function is shared between gadget functions, so this avoid unnecessary
>> duplicated code and potentially avoid memory leaks.
>>
>> Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
>> ---
>> drivers/usb/gadget/function/f_midi.c | 6 ------
>> drivers/usb/gadget/function/f_sourcesink.c | 6 ------
>> drivers/usb/gadget/function/g_zero.h | 1 -
>> drivers/usb/gadget/u_f.c | 8 ++++++++
>> drivers/usb/gadget/u_f.h | 3 +--
>> 5 files changed, 9 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
>> index c19f154..4c01c8a 100644
>> --- a/drivers/usb/gadget/function/f_midi.c
>> +++ b/drivers/usb/gadget/function/f_midi.c
>> @@ -202,12 +202,6 @@ static inline struct usb_request *midi_alloc_ep_req(struct usb_ep *ep,
>> return alloc_ep_req(ep, length, length);
>> }
>>
>> -static void free_ep_req(struct usb_ep *ep, struct usb_request *req)
>> -{
>> - kfree(req->buf);
>> - usb_ep_free_request(ep, req);
>> -}
>> -
>> static const uint8_t f_midi_cin_length[] = {
>> 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1
>> };
>> diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c
>> index 3a5ae99..eedea7f 100644
>> --- a/drivers/usb/gadget/function/f_sourcesink.c
>> +++ b/drivers/usb/gadget/function/f_sourcesink.c
>> @@ -307,12 +307,6 @@ static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len)
>> return alloc_ep_req(ep, len, buflen);
>> }
>>
>> -void free_ep_req(struct usb_ep *ep, struct usb_request *req)
>> -{
>> - kfree(req->buf);
>> - usb_ep_free_request(ep, req);
>> -}
>> -
>> static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
>> {
>> int value;
>> diff --git a/drivers/usb/gadget/function/g_zero.h b/drivers/usb/gadget/function/g_zero.h
>> index 15f1809..5ed90b4 100644
>> --- a/drivers/usb/gadget/function/g_zero.h
>> +++ b/drivers/usb/gadget/function/g_zero.h
>> @@ -59,7 +59,6 @@ void lb_modexit(void);
>> int lb_modinit(void);
>>
>> /* common utilities */
>> -void free_ep_req(struct usb_ep *ep, struct usb_request *req);
>> void disable_endpoints(struct usb_composite_dev *cdev,
>> struct usb_ep *in, struct usb_ep *out,
>> struct usb_ep *iso_in, struct usb_ep *iso_out);
>> diff --git a/drivers/usb/gadget/u_f.c b/drivers/usb/gadget/u_f.c
>> index c6276f0..f78bd1f 100644
>> --- a/drivers/usb/gadget/u_f.c
>> +++ b/drivers/usb/gadget/u_f.c
>> @@ -14,6 +14,7 @@
>> #include <linux/usb/gadget.h>
>> #include "u_f.h"
>>
>> +/* Requests allocated via alloc_ep_req() must be freed by free_ep_req(). */
>> struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len)
>> {
>> struct usb_request *req;
>> @@ -30,3 +31,10 @@ struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len)
>> return req;
>> }
>> EXPORT_SYMBOL_GPL(alloc_ep_req);
>> +
>> +void free_ep_req(struct usb_ep *ep, struct usb_request *req)
>> +{
>> + kfree(req->buf);
>> + usb_ep_free_request(ep, req);
>> +}
>> +EXPORT_SYMBOL_GPL(free_ep_req);
>> diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h
>> index 1d5f0eb..2a1a6fb 100644
>> --- a/drivers/usb/gadget/u_f.h
>> +++ b/drivers/usb/gadget/u_f.h
>> @@ -46,7 +46,6 @@ struct usb_ep;
>> struct usb_request;
>>
>> struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len);
>> +void free_ep_req(struct usb_ep *ep, struct usb_request *req);
>>
>> #endif /* __U_F_H__ */
>> -
>> -
>>
>
> Isn't it simple enough to be static inline?
inline yes. And the compiler will do it automatically. But I can add it
for clarity.
Make it static it doesn't make sense. This function is exported in the
kernel.
--
Felipe
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2015-10-27 10:50 +0100 |
| Subject | Re: [PATCH v4 3/7] usb: gadget: define free_ep_req as universal function |
| Message-ID | <qo93c-3zz-13@gated-at.bofh.it> |
| In reply to | #1256603 |
On 10/27/2015 10:18 AM, Felipe Ferreri Tonello wrote:
> Hi Robert,
>
> On 27/10/15 06:53, Robert Baldyga wrote:
>> On 10/26/2015 05:55 PM, Felipe F. Tonello wrote:
>>> This function is shared between gadget functions, so this avoid unnecessary
>>> duplicated code and potentially avoid memory leaks.
>>>
>>> Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
>>> ---
>>> drivers/usb/gadget/function/f_midi.c | 6 ------
>>> drivers/usb/gadget/function/f_sourcesink.c | 6 ------
>>> drivers/usb/gadget/function/g_zero.h | 1 -
>>> drivers/usb/gadget/u_f.c | 8 ++++++++
>>> drivers/usb/gadget/u_f.h | 3 +--
>>> 5 files changed, 9 insertions(+), 15 deletions(-)
>>>
>>> diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
>>> index c19f154..4c01c8a 100644
>>> --- a/drivers/usb/gadget/function/f_midi.c
>>> +++ b/drivers/usb/gadget/function/f_midi.c
>>> @@ -202,12 +202,6 @@ static inline struct usb_request *midi_alloc_ep_req(struct usb_ep *ep,
>>> return alloc_ep_req(ep, length, length);
>>> }
>>>
>>> -static void free_ep_req(struct usb_ep *ep, struct usb_request *req)
>>> -{
>>> - kfree(req->buf);
>>> - usb_ep_free_request(ep, req);
>>> -}
>>> -
>>> static const uint8_t f_midi_cin_length[] = {
>>> 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1
>>> };
>>> diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c
>>> index 3a5ae99..eedea7f 100644
>>> --- a/drivers/usb/gadget/function/f_sourcesink.c
>>> +++ b/drivers/usb/gadget/function/f_sourcesink.c
>>> @@ -307,12 +307,6 @@ static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len)
>>> return alloc_ep_req(ep, len, buflen);
>>> }
>>>
>>> -void free_ep_req(struct usb_ep *ep, struct usb_request *req)
>>> -{
>>> - kfree(req->buf);
>>> - usb_ep_free_request(ep, req);
>>> -}
>>> -
>>> static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
>>> {
>>> int value;
>>> diff --git a/drivers/usb/gadget/function/g_zero.h b/drivers/usb/gadget/function/g_zero.h
>>> index 15f1809..5ed90b4 100644
>>> --- a/drivers/usb/gadget/function/g_zero.h
>>> +++ b/drivers/usb/gadget/function/g_zero.h
>>> @@ -59,7 +59,6 @@ void lb_modexit(void);
>>> int lb_modinit(void);
>>>
>>> /* common utilities */
>>> -void free_ep_req(struct usb_ep *ep, struct usb_request *req);
>>> void disable_endpoints(struct usb_composite_dev *cdev,
>>> struct usb_ep *in, struct usb_ep *out,
>>> struct usb_ep *iso_in, struct usb_ep *iso_out);
>>> diff --git a/drivers/usb/gadget/u_f.c b/drivers/usb/gadget/u_f.c
>>> index c6276f0..f78bd1f 100644
>>> --- a/drivers/usb/gadget/u_f.c
>>> +++ b/drivers/usb/gadget/u_f.c
>>> @@ -14,6 +14,7 @@
>>> #include <linux/usb/gadget.h>
>>> #include "u_f.h"
>>>
>>> +/* Requests allocated via alloc_ep_req() must be freed by free_ep_req(). */
>>> struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len)
>>> {
>>> struct usb_request *req;
>>> @@ -30,3 +31,10 @@ struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len)
>>> return req;
>>> }
>>> EXPORT_SYMBOL_GPL(alloc_ep_req);
>>> +
>>> +void free_ep_req(struct usb_ep *ep, struct usb_request *req)
>>> +{
>>> + kfree(req->buf);
>>> + usb_ep_free_request(ep, req);
>>> +}
>>> +EXPORT_SYMBOL_GPL(free_ep_req);
>>> diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h
>>> index 1d5f0eb..2a1a6fb 100644
>>> --- a/drivers/usb/gadget/u_f.h
>>> +++ b/drivers/usb/gadget/u_f.h
>>> @@ -46,7 +46,6 @@ struct usb_ep;
>>> struct usb_request;
>>>
>>> struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len);
>>> +void free_ep_req(struct usb_ep *ep, struct usb_request *req);
>>>
>>> #endif /* __U_F_H__ */
>>> -
>>> -
>>>
>>
>> Isn't it simple enough to be static inline?
>
> inline yes. And the compiler will do it automatically. But I can add it
> for clarity.
No, compiler will never make function inline when you export its symbol.
To make it inline you should place it in header.
>
> Make it static it doesn't make sense. This function is exported in the
> kernel.
>
Best regards,
Robert
--
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/
[toc] | [prev] | [next] | [standalone]
| From | Felipe Ferreri Tonello <eu@felipetonello.com> |
|---|---|
| Date | 2015-10-27 14:00 +0100 |
| Subject | Re: [PATCH v4 3/7] usb: gadget: define free_ep_req as universal function |
| Message-ID | <qoc14-5j9-15@gated-at.bofh.it> |
| In reply to | #1256629 |
Hi Robert,
On 27/10/15 09:47, Robert Baldyga wrote:
> On 10/27/2015 10:18 AM, Felipe Ferreri Tonello wrote:
>> Hi Robert,
>>
>> On 27/10/15 06:53, Robert Baldyga wrote:
>>> On 10/26/2015 05:55 PM, Felipe F. Tonello wrote:
>>>> This function is shared between gadget functions, so this avoid unnecessary
>>>> duplicated code and potentially avoid memory leaks.
>>>>
>>>> Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
>>>> ---
>>>> drivers/usb/gadget/function/f_midi.c | 6 ------
>>>> drivers/usb/gadget/function/f_sourcesink.c | 6 ------
>>>> drivers/usb/gadget/function/g_zero.h | 1 -
>>>> drivers/usb/gadget/u_f.c | 8 ++++++++
>>>> drivers/usb/gadget/u_f.h | 3 +--
>>>> 5 files changed, 9 insertions(+), 15 deletions(-)
>>>>
>>>> diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
>>>> index c19f154..4c01c8a 100644
>>>> --- a/drivers/usb/gadget/function/f_midi.c
>>>> +++ b/drivers/usb/gadget/function/f_midi.c
>>>> @@ -202,12 +202,6 @@ static inline struct usb_request *midi_alloc_ep_req(struct usb_ep *ep,
>>>> return alloc_ep_req(ep, length, length);
>>>> }
>>>>
>>>> -static void free_ep_req(struct usb_ep *ep, struct usb_request *req)
>>>> -{
>>>> - kfree(req->buf);
>>>> - usb_ep_free_request(ep, req);
>>>> -}
>>>> -
>>>> static const uint8_t f_midi_cin_length[] = {
>>>> 0, 0, 2, 3, 3, 1, 2, 3, 3, 3, 3, 3, 2, 2, 3, 1
>>>> };
>>>> diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c
>>>> index 3a5ae99..eedea7f 100644
>>>> --- a/drivers/usb/gadget/function/f_sourcesink.c
>>>> +++ b/drivers/usb/gadget/function/f_sourcesink.c
>>>> @@ -307,12 +307,6 @@ static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len)
>>>> return alloc_ep_req(ep, len, buflen);
>>>> }
>>>>
>>>> -void free_ep_req(struct usb_ep *ep, struct usb_request *req)
>>>> -{
>>>> - kfree(req->buf);
>>>> - usb_ep_free_request(ep, req);
>>>> -}
>>>> -
>>>> static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
>>>> {
>>>> int value;
>>>> diff --git a/drivers/usb/gadget/function/g_zero.h b/drivers/usb/gadget/function/g_zero.h
>>>> index 15f1809..5ed90b4 100644
>>>> --- a/drivers/usb/gadget/function/g_zero.h
>>>> +++ b/drivers/usb/gadget/function/g_zero.h
>>>> @@ -59,7 +59,6 @@ void lb_modexit(void);
>>>> int lb_modinit(void);
>>>>
>>>> /* common utilities */
>>>> -void free_ep_req(struct usb_ep *ep, struct usb_request *req);
>>>> void disable_endpoints(struct usb_composite_dev *cdev,
>>>> struct usb_ep *in, struct usb_ep *out,
>>>> struct usb_ep *iso_in, struct usb_ep *iso_out);
>>>> diff --git a/drivers/usb/gadget/u_f.c b/drivers/usb/gadget/u_f.c
>>>> index c6276f0..f78bd1f 100644
>>>> --- a/drivers/usb/gadget/u_f.c
>>>> +++ b/drivers/usb/gadget/u_f.c
>>>> @@ -14,6 +14,7 @@
>>>> #include <linux/usb/gadget.h>
>>>> #include "u_f.h"
>>>>
>>>> +/* Requests allocated via alloc_ep_req() must be freed by free_ep_req(). */
>>>> struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len)
>>>> {
>>>> struct usb_request *req;
>>>> @@ -30,3 +31,10 @@ struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len)
>>>> return req;
>>>> }
>>>> EXPORT_SYMBOL_GPL(alloc_ep_req);
>>>> +
>>>> +void free_ep_req(struct usb_ep *ep, struct usb_request *req)
>>>> +{
>>>> + kfree(req->buf);
>>>> + usb_ep_free_request(ep, req);
>>>> +}
>>>> +EXPORT_SYMBOL_GPL(free_ep_req);
>>>> diff --git a/drivers/usb/gadget/u_f.h b/drivers/usb/gadget/u_f.h
>>>> index 1d5f0eb..2a1a6fb 100644
>>>> --- a/drivers/usb/gadget/u_f.h
>>>> +++ b/drivers/usb/gadget/u_f.h
>>>> @@ -46,7 +46,6 @@ struct usb_ep;
>>>> struct usb_request;
>>>>
>>>> struct usb_request *alloc_ep_req(struct usb_ep *ep, int len, int default_len);
>>>> +void free_ep_req(struct usb_ep *ep, struct usb_request *req);
>>>>
>>>> #endif /* __U_F_H__ */
>>>> -
>>>> -
>>>>
>>>
>>> Isn't it simple enough to be static inline?
>>
>> inline yes. And the compiler will do it automatically. But I can add it
>> for clarity.
>
> No, compiler will never make function inline when you export its symbol.
> To make it inline you should place it in header.
Correct.
I will improve it on next revision.
--
Felipe
--
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/
[toc] | [prev] | [next] | [standalone]
| From | "Felipe F. Tonello" <eu@felipetonello.com> |
|---|---|
| Date | 2015-10-26 18:00 +0100 |
| Subject | [PATCH v4 6/7] usb: gadget: gmidi: Cleanup legacy code |
| Message-ID | <qnThN-2d0-27@gated-at.bofh.it> |
| In reply to | #1256164 |
Remove unnecessary headers and variables.
Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
---
drivers/usb/gadget/legacy/gmidi.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/drivers/usb/gadget/legacy/gmidi.c b/drivers/usb/gadget/legacy/gmidi.c
index da19c48..055390b 100644
--- a/drivers/usb/gadget/legacy/gmidi.c
+++ b/drivers/usb/gadget/legacy/gmidi.c
@@ -21,21 +21,12 @@
/* #define VERBOSE_DEBUG */
#include <linux/kernel.h>
-#include <linux/slab.h>
#include <linux/module.h>
-#include <linux/device.h>
-#include <sound/core.h>
#include <sound/initval.h>
-#include <sound/rawmidi.h>
-#include <linux/usb/ch9.h>
#include <linux/usb/composite.h>
#include <linux/usb/gadget.h>
-#include <linux/usb/audio.h>
-#include <linux/usb/midi.h>
-
-#include "gadget_chips.h"
#include "u_midi.h"
@@ -44,7 +35,6 @@
MODULE_AUTHOR("Ben Williamson");
MODULE_LICENSE("GPL v2");
-static const char shortname[] = "g_midi";
static const char longname[] = "MIDI Gadget";
USB_GADGET_COMPOSITE_OPTIONS();
--
2.1.4
--
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/
[toc] | [prev] | [next] | [standalone]
| From | "Felipe F. Tonello" <eu@felipetonello.com> |
|---|---|
| Date | 2015-10-26 18:00 +0100 |
| Subject | [PATCH v4 5/7] usb: gadget: f_midi: set altsettings only for MIDIStreaming interface |
| Message-ID | <qnThN-2d0-35@gated-at.bofh.it> |
| In reply to | #1256164 |
This avoids duplication of USB requests for OUT endpoint and re-enabling endpoints. Signed-off-by: Felipe F. Tonello <eu@felipetonello.com> --- drivers/usb/gadget/function/f_midi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c index 0e9cdeb..a617df3 100644 --- a/drivers/usb/gadget/function/f_midi.c +++ b/drivers/usb/gadget/function/f_midi.c @@ -323,6 +323,10 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) unsigned i; int err; + /* We don't care if it is not MIDIStreaming interface */ + if (intf != ms_interface_desc.bInterfaceNumber) + return 0; + err = f_midi_start_ep(midi, f, midi->in_ep); if (err) return err; -- 2.1.4 -- 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/
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@hackerion.com> |
|---|---|
| Date | 2015-10-26 23:40 +0100 |
| Subject | Re: [PATCH v4 5/7] usb: gadget: f_midi: set altsettings only for MIDIStreaming interface |
| Message-ID | <qnYAO-5xU-15@gated-at.bofh.it> |
| In reply to | #1256168 |
On 10/26/2015 05:55 PM, Felipe F. Tonello wrote: > This avoids duplication of USB requests for OUT endpoint and > re-enabling endpoints. > > Signed-off-by: Felipe F. Tonello <eu@felipetonello.com> > --- > drivers/usb/gadget/function/f_midi.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c > index 0e9cdeb..a617df3 100644 > --- a/drivers/usb/gadget/function/f_midi.c > +++ b/drivers/usb/gadget/function/f_midi.c > @@ -323,6 +323,10 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) > unsigned i; > int err; > > + /* We don't care if it is not MIDIStreaming interface */ > + if (intf != ms_interface_desc.bInterfaceNumber) > + return 0; > + These global descriptors are overwritten in bind() of each instance of f_midi, so you have no guarantee that your bInterfaceNumber is correct for your current instance. Instead you should store value obtained from usb_interface_id() during bind(). > err = f_midi_start_ep(midi, f, midi->in_ep); > if (err) > return err; > Best regards, Robert -- 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/
[toc] | [prev] | [next] | [standalone]
| From | Felipe Tonello <eu@felipetonello.com> |
|---|---|
| Date | 2015-10-27 00:00 +0100 |
| Subject | Re: [PATCH v4 5/7] usb: gadget: f_midi: set altsettings only for MIDIStreaming interface |
| Message-ID | <qnYUa-5Ev-13@gated-at.bofh.it> |
| In reply to | #1256330 |
Hi Robert, On Mon, Oct 26, 2015 at 10:30 PM, Robert Baldyga <r.baldyga@hackerion.com> wrote: > On 10/26/2015 05:55 PM, Felipe F. Tonello wrote: >> This avoids duplication of USB requests for OUT endpoint and >> re-enabling endpoints. >> >> Signed-off-by: Felipe F. Tonello <eu@felipetonello.com> >> --- >> drivers/usb/gadget/function/f_midi.c | 4 ++++ >> 1 file changed, 4 insertions(+) >> >> diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c >> index 0e9cdeb..a617df3 100644 >> --- a/drivers/usb/gadget/function/f_midi.c >> +++ b/drivers/usb/gadget/function/f_midi.c >> @@ -323,6 +323,10 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) >> unsigned i; >> int err; >> >> + /* We don't care if it is not MIDIStreaming interface */ >> + if (intf != ms_interface_desc.bInterfaceNumber) >> + return 0; >> + > > These global descriptors are overwritten in bind() of each instance of > f_midi, so you have no guarantee that your bInterfaceNumber is correct > for your current instance. Instead you should store value obtained from > usb_interface_id() during bind(). Ok. But then this interface descriptors shouldn't be global static, because they will always reflect the latest bind() only. Right? > >> err = f_midi_start_ep(midi, f, midi->in_ep); >> if (err) >> return err; >> Felipe -- 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/
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2015-10-27 07:50 +0100 |
| Subject | Re: [PATCH v4 5/7] usb: gadget: f_midi: set altsettings only for MIDIStreaming interface |
| Message-ID | <qo6eZ-1SY-5@gated-at.bofh.it> |
| In reply to | #1256336 |
On 10/26/2015 11:53 PM, Felipe Tonello wrote: > Hi Robert, > > On Mon, Oct 26, 2015 at 10:30 PM, Robert Baldyga > <r.baldyga@hackerion.com> wrote: >> On 10/26/2015 05:55 PM, Felipe F. Tonello wrote: >>> This avoids duplication of USB requests for OUT endpoint and >>> re-enabling endpoints. >>> >>> Signed-off-by: Felipe F. Tonello <eu@felipetonello.com> >>> --- >>> drivers/usb/gadget/function/f_midi.c | 4 ++++ >>> 1 file changed, 4 insertions(+) >>> >>> diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c >>> index 0e9cdeb..a617df3 100644 >>> --- a/drivers/usb/gadget/function/f_midi.c >>> +++ b/drivers/usb/gadget/function/f_midi.c >>> @@ -323,6 +323,10 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) >>> unsigned i; >>> int err; >>> >>> + /* We don't care if it is not MIDIStreaming interface */ >>> + if (intf != ms_interface_desc.bInterfaceNumber) >>> + return 0; >>> + >> >> These global descriptors are overwritten in bind() of each instance of >> f_midi, so you have no guarantee that your bInterfaceNumber is correct >> for your current instance. Instead you should store value obtained from >> usb_interface_id() during bind(). > > Ok. > > But then this interface descriptors shouldn't be global static, > because they will always reflect the latest bind() only. Right? They are copied for each instance of USB function, so they are actually template to fill and copy in bind(). I'm currently working on some patches changing a bit behavior of set_alt() to make it clearer, but for now the only way to distinguish between altsettings properly is to store bInterfaceNumber value for each function instance in its bind(). Best regards, Robert > >> >>> err = f_midi_start_ep(midi, f, midi->in_ep); >>> if (err) >>> return err; >>> > > Felipe -- 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/
[toc] | [prev] | [next] | [standalone]
| From | Felipe Ferreri Tonello <eu@felipetonello.com> |
|---|---|
| Date | 2015-10-27 10:20 +0100 |
| Subject | Re: [PATCH v4 5/7] usb: gadget: f_midi: set altsettings only for MIDIStreaming interface |
| Message-ID | <qo8Ab-3pT-21@gated-at.bofh.it> |
| In reply to | #1256504 |
Hi Robert, On 27/10/15 06:47, Robert Baldyga wrote: > On 10/26/2015 11:53 PM, Felipe Tonello wrote: >> Hi Robert, >> >> On Mon, Oct 26, 2015 at 10:30 PM, Robert Baldyga >> <r.baldyga@hackerion.com> wrote: >>> On 10/26/2015 05:55 PM, Felipe F. Tonello wrote: >>>> This avoids duplication of USB requests for OUT endpoint and >>>> re-enabling endpoints. >>>> >>>> Signed-off-by: Felipe F. Tonello <eu@felipetonello.com> >>>> --- >>>> drivers/usb/gadget/function/f_midi.c | 4 ++++ >>>> 1 file changed, 4 insertions(+) >>>> >>>> diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c >>>> index 0e9cdeb..a617df3 100644 >>>> --- a/drivers/usb/gadget/function/f_midi.c >>>> +++ b/drivers/usb/gadget/function/f_midi.c >>>> @@ -323,6 +323,10 @@ static int f_midi_set_alt(struct usb_function *f, unsigned intf, unsigned alt) >>>> unsigned i; >>>> int err; >>>> >>>> + /* We don't care if it is not MIDIStreaming interface */ >>>> + if (intf != ms_interface_desc.bInterfaceNumber) >>>> + return 0; >>>> + >>> >>> These global descriptors are overwritten in bind() of each instance of >>> f_midi, so you have no guarantee that your bInterfaceNumber is correct >>> for your current instance. Instead you should store value obtained from >>> usb_interface_id() during bind(). >> >> Ok. >> >> But then this interface descriptors shouldn't be global static, >> because they will always reflect the latest bind() only. Right? > > They are copied for each instance of USB function, so they are actually > template to fill and copy in bind(). I'm currently working on some > patches changing a bit behavior of set_alt() to make it clearer, but for > now the only way to distinguish between altsettings properly is to store > bInterfaceNumber value for each function instance in its bind(). Ok. Thanks. -- Felipe -- 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/
[toc] | [prev] | [next] | [standalone]
| From | Felipe Ferreri Tonello <eu@felipetonello.com> |
|---|---|
| Date | 2015-10-27 15:20 +0100 |
| Message-ID | <qodgt-6dy-5@gated-at.bofh.it> |
| In reply to | #1256164 |
Hi Balbi, On 26/10/15 16:55, Felipe F. Tonello wrote: > Patch 7 has changes on how to transmit IN USB requests. It implements a FIFO > of pre-allocated usb requests and uses then as needed, instead of allocating > then on demand. This is my initial implementation and is open for > suggestions and comments. > > Patches 1-6 is pretty much straight forward. > > changes in v4: > - pre-alocation of in requests. > - more code clean up > - fix memory leak on out requests > - configure endpoints only when setting up MIDIStreaming interface > > Felipe F. Tonello (7): > usb: gadget: f_midi: Transmit data only when IN ep is enabled > usb: gadget: f_midi: remove duplicated code > usb: gadget: define free_ep_req as universal function > usb: gadget: f_midi: fix leak on failed to enqueue out requests > usb: gadget: f_midi: set altsettings only for MIDIStreaming interface > usb: gadget: gmidi: Cleanup legacy code > usb: gadget: f_midi: pre-allocate IN requests > > drivers/usb/gadget/function/f_midi.c | 201 ++++++++++++++++++++--------- > drivers/usb/gadget/function/f_sourcesink.c | 6 - > drivers/usb/gadget/function/g_zero.h | 1 - > drivers/usb/gadget/legacy/gmidi.c | 12 +- > drivers/usb/gadget/u_f.c | 8 ++ > drivers/usb/gadget/u_f.h | 3 +- > 6 files changed, 151 insertions(+), 80 deletions(-) > I have rebased this patchset on top of your next branch. It removes the need for patch 1 and patch 5. I am waiting for more comments on other patches to fix things if needed before sending v5. -- Felipe -- 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/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web