usb: chipidea: core: fix when building without CONFIG_PM support
Subsystems (2)
PATCH 1/3 usb: chipidea: core: fix when building without CONFIG_PM support
If CONFIG_PM or CONFIG_PM_SLEEP is not set, driver will not compile properly.
--- drivers/usb/chipidea/core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/usb/chipidea/core.c +5 -1
@@ -1009,18 +1009,22 @@ static int ci_runtime_resume(struct device *dev)return ci_controller_resume (dev); } -#endif /* CONFIG_PM */ static const struct dev_pm_ops ci_pm_ops = { +#ifdef CONFIG_PM_SLEEP SET_SYSTEM_SLEEP_PM_OPS(ci_suspend, ci_resume) +#endif /* CONFIG_PM_SLEEP */ SET_RUNTIME_PM_OPS (ci_runtime_suspend, ci_runtime_resume,NULL ) }; +#endif /* CONFIG_PM */ static struct platform_driver ci_hdrc_driver = { .probe = ci_hdrc_probe, .remove = ci_hdrc_remove, .driver = { .name ="ci_hdrc" , +#ifdef CONFIG_PM .pm = &ci_pm_ops, +#endif }, };
Signature · 1 line
2.1.4
PATCH 2/3 usb: gadget: f_midi: free usb request when done
req->actual == req->length means that there is no data left to enqueue, so free the request.
--- drivers/usb/gadget/function/f_midi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/usb/gadget/function/f_midi.c +4 -1
@@ -258,7 +258,10 @@ f_midi_complete(struct usb_ep *ep, struct usb_request *req) }else if (ep == midi->in_ep) {/* Our transmit completed. See if there's more to go. * f_midi_transmit eats req, don't queue it again. */ -f_midi_transmit (midi, req); +if (req->actual < req->length) +f_midi_transmit (midi, req); +else +free_ep_req (ep, req);return ; }break ;
Signature · 1 line
2.1.4
Re: [PATCH 2/3] usb: gadget: f_midi: free usb request when done
Quoted 13 lines · Felipe F. Tonello
req->actual==req->lengthmeans that there is no data left to enqueue, so free the request.Signed-off-by Felipe F. Tonello <[email protected]>--- drivers/usb/gadget/function/f_midi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/usb/gadget/function/f_midi.c +0
-0
drivers/usb/gadget/function/f_midi.c f_midi_complete(struct usb_ep *ep, struct usb_request *req) · line 264
Quoted 8 lines
drivers/usb/gadget/function/f_midi.c +4
-1@@ -258,7 +258,10 @@ f_midi_complete(struct usb_ep *ep, struct usb_request *req) }else if (ep == midi->in_ep) {/* Our transmit completed. See if there's more to go. * f_midi_transmit eats req, don't queue it again. */ -f_midi_transmit (midi, req); +if (req->actual < req->length) +f_midi_transmit (midi, req); +else +free_ep_req (ep, req);
I'd have to have a deeper look at f_midi, but this doesn't look correct to me. Why do you think that we should stop queueing requests when we transfer one in full ?
Signature · 1 line
balbi
Re: [PATCH 2/3] usb: gadget: f_midi: free usb request when done
In reply to Felipe F. TonelloQuoted 13 lines · Felipe F. Tonello
req->actual==req->lengthmeans that there is no data left to enqueue, so free the request.Signed-off-by Felipe F. Tonello <[email protected]>--- drivers/usb/gadget/function/f_midi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/usb/gadget/function/f_midi.c +0
-0
drivers/usb/gadget/function/f_midi.c f_midi_complete(struct usb_ep *ep, struct usb_request *req) · line 266
Quoted 10 lines
drivers/usb/gadget/function/f_midi.c +4
-1@@ -258,7 +258,10 @@ f_midi_complete(struct usb_ep *ep, struct usb_request *req) }else if (ep == midi->in_ep) {/* Our transmit completed. See if there's more to go. * f_midi_transmit eats req, don't queue it again. */ -f_midi_transmit (midi, req); +if (req->actual < req->length) +f_midi_transmit (midi, req); +else +free_ep_req (ep, req);return ; }
It is incorrect, if no reqeust in queue, how device knows when the host sends data?
Signature · 2 lines
Best Regards, Peter Chen
Re: [PATCH 2/3] usb: gadget: f_midi: free usb request when done
Hi Peter,
Quoted 19 lines · Peter Chen
Quoted 18 lines · Felipe F. Tonello
req->actual==req->lengthmeans that there is no data left to enqueue, so free the request.Signed-off-by Felipe F. Tonello <[email protected]>--- drivers/usb/gadget/function/f_midi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/usb/gadget/function/f_midi.c +1
-1@@ -258,7 +258,10 @@ f_midi_complete(struct usb_ep *ep, struct usb_request *req) }else if (ep == midi->in_ep) {/* Our transmit completed. See if there's more to go. * f_midi_transmit eats req, don't queue it again. */ -f_midi_transmit (midi, req); +if (req->actual < req->length)
Quoted 8 lines
drivers/usb/gadget/function/f_midi.c f_midi_complete(struct usb_ep *ep, struct usb_request *req) · line 266
Quoted 5 lines
drivers/usb/gadget/function/f_midi.c +3
-0+f_midi_transmit (midi, req); + else +free_ep_req (ep ,req );return ; }It is incorrect, if no reqeust in queue, how device knows when the host sends data?
This is the complete function of the IN endpoint.
Actually I believe the proper patch is to enqueue this request again if req->actual < req->length is true. Because the data is still there, just not fully completed. Asking to transmit the request again will cause to read new data from ALSA MIDI module, which it can possibly steal data from a real ALSA request from f_midi_in_trigger. If that doesn't happen (req->length == 0), the request will be freed anyway.
Any thoughts?
Felipe
Re: [PATCH 2/3] usb: gadget: f_midi: free usb request when done
Quoted 33 lines · Felipe Tonello
Hi Peter,
Quoted 19 lines · Peter Chen
Quoted 18 lines · Felipe F. Tonello
req->actual==req->lengthmeans that there is no data left to enqueue, so free the request.Signed-off-by Felipe F. Tonello <[email protected]>--- drivers/usb/gadget/function/f_midi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/usb/gadget/function/f_midi.c +1
-1@@ -258,7 +258,10 @@ f_midi_complete(struct usb_ep *ep, struct usb_request *req) }else if (ep == midi->in_ep) {/* Our transmit completed. See if there's more to go. * f_midi_transmit eats req, don't queue it again. */ -f_midi_transmit (midi, req); +if (req->actual < req->length)Quoted 8 lines
drivers/usb/gadget/function/f_midi.c f_midi_complete(struct usb_ep *ep, struct usb_request *req) · line 266
Quoted 5 lines
drivers/usb/gadget/function/f_midi.c +3
-0+f_midi_transmit (midi, req); + else +free_ep_req (ep ,req );return ; }It is incorrect, if no reqeust in queue, how device knows when the host sends data?
This is the complete function of the IN endpoint.
Quoted 8 lines
Actually I believe the proper patch is to enqueue this request again if
req->actual<req->lengthis true. Because the data is still there, just not fully completed. Asking to transmit the request again will cause to read new data from ALSA MIDI module, which it can possibly steal data from a real ALSA request fromf_midi_in_trigger. If that doesn't happen (req->length== 0), the request will be freed anyway.Any thoughts?
Please pardon me for jumping in in the middle of a conversation. I know practically zero about f_midi. But nevertheless...
How can you ever have req->actual < req->length for a usb_request on an IN endpoint? The only way that can happen is if some sort of error or exceptional event occurred, for example, if the transfer was cancelled before it could run to completion. In such cases I doubt that you really want to retransmit the data. Particularly since part of it probably was received by the host -- do you really want to send that part of the data a second time?
Don't bother to answer if this doesn't make any sense...
Alan Stern
Re: [PATCH 2/3] usb: gadget: f_midi: free usb request when done
Hi Alan,
Quoted 47 lines · Alan Stern
Quoted 33 lines · Felipe Tonello
Hi Peter,
Quoted 19 lines · Peter Chen
Quoted 18 lines · Felipe F. Tonello
req->actual==req->lengthmeans that there is no data left to enqueue, so free the request.Signed-off-by Felipe F. Tonello <[email protected]>--- drivers/usb/gadget/function/f_midi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/usb/gadget/function/f_midi.c +1
-1@@ -258,7 +258,10 @@ f_midi_complete(struct usb_ep *ep, struct usb_request *req) }else if (ep == midi->in_ep) {/* Our transmit completed. See if there's more to go. * f_midi_transmit eats req, don't queue it again. */ -f_midi_transmit (midi, req); +if (req->actual < req->length)Quoted 8 lines
drivers/usb/gadget/function/f_midi.c f_midi_complete(struct usb_ep *ep, struct usb_request *req) · line 266
Quoted 5 lines
drivers/usb/gadget/function/f_midi.c +3
-0+f_midi_transmit (midi, req); + else +free_ep_req (ep ,req );return ; }It is incorrect, if no reqeust in queue, how device knows when the host sends data?
This is the complete function of the IN endpoint.
Quoted 8 lines
Actually I believe the proper patch is to enqueue this request again if
req->actual<req->lengthis true. Because the data is still there, just not fully completed. Asking to transmit the request again will cause to read new data from ALSA MIDI module, which it can possibly steal data from a real ALSA request fromf_midi_in_trigger. If that doesn't happen (req->length== 0), the request will be freed anyway.Any thoughts?
Please pardon me for jumping in in the middle of a conversation. I know practically zero about
f_midi. But nevertheless...
Quoted 7 lines
How can you ever have
req->actual<req->lengthfor ausb_requeston an IN endpoint? The only way that can happen is if some sort of error or exceptional event occurred, for example, if the transfer was cancelled before it could run to completion. In such cases I doubt that you really want to retransmit the data. Particularly since part of it probably was received by the host -- do you really want to send that part of the data a second time?
That is a fair point.
IMO we should always free the request upon a completion. Never retransmit, since ALSA trigger will do that anyway.
Felipe
PATCH 3/3 usb: gadget: f_midi: free request when usb_ep_queue fails
In reply to Felipe F. TonelloThis fix a memory leak that will occur in this case.
--- drivers/usb/gadget/function/f_midi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/gadget/function/f_midi.c +3 -1
@@ -550,9 +550,11 @@ static void f_midi_transmit(struct f_midi *midi, struct usb_request *req)int err; err =usb_ep_queue (ep, req,GFP_ATOMIC ); -if (err <0 ) +if (err <0 ) {ERROR (midi,"%s queue req: %d\n" , midi->in_ep->name, err); +free_ep_req (ep, req); + } }else {free_ep_req (ep, req); }
Signature · 1 line
2.1.4
Re: [PATCH 3/3] usb: gadget: f_midi: free request when usb_ep_queue fails
Quoted 12 lines · Felipe F. Tonello
This fix a memory leak that will occur in this case.
Signed-off-by Felipe F. Tonello <[email protected]>--- drivers/usb/gadget/function/f_midi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/gadget/function/f_midi.c +0
-0
drivers/usb/gadget/function/f_midi.c static void f_midi_transmit(struct f_midi *midi, struct usb_request *req) · line 556
Quoted 8 lines
drivers/usb/gadget/function/f_midi.c +2
-1@@ -550,9 +550,11 @@ static void f_midi_transmit(struct f_midi *midi, struct usb_request *req)int err; err =usb_ep_queue (ep, req,GFP_ATOMIC ); -if (err <0 ) +if (err <0 ) {ERROR (midi,"%s queue req: %d\n" , midi->in_ep->name, err); +free_ep_req (ep, req);
sure this request won't be needed on the next time the tasklet is queued ?
Although, this looks correct, let's try to make sure really is correct.
Signature · 1 line
balbi
Re: [PATCH 3/3] usb: gadget: f_midi: free request when usb_ep_queue fails
In reply to Felipe F. TonelloQuoted 27 lines · Felipe F. Tonello
This fix a memory leak that will occur in this case.
Signed-off-by Felipe F. Tonello <[email protected]>--- drivers/usb/gadget/function/f_midi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/gadget/function/f_midi.c +3
-1@@ -550,9 +550,11 @@ static void f_midi_transmit(struct f_midi *midi, struct usb_request *req)int err; err =usb_ep_queue (ep, req,GFP_ATOMIC ); -if (err <0 ) +if (err <0 ) {ERROR (midi,"%s queue req: %d\n" , midi->in_ep->name, err); +free_ep_req (ep, req); + } }else {free_ep_req (ep, req); }Signature · 1 line
2.1.4
I may know your problem, current midi library, alsa and this driver allow device sends as much data as possible, but without block the sending until host reads data, it only allocates the request buffer (using midi_alloc_ep_req), but without free, so after you send enough data, it is out of memory.
Signature · 2 lines
Best Regards, Peter Chen
Re: [PATCH 3/3] usb: gadget: f_midi: free request when usb_ep_queue fails
Hi Peter,
Quoted 26 lines · Peter Chen
Quoted 25 lines · Felipe F. Tonello
This fix a memory leak that will occur in this case.
Signed-off-by Felipe F. Tonello <[email protected]>--- drivers/usb/gadget/function/f_midi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/gadget/function/f_midi.c +3
-2@@ -550,9 +550,11 @@ static void f_midi_transmit(struct f_midi *midi, struct usb_request *req)int err; err =usb_ep_queue (ep, req,GFP_ATOMIC ); -if (err <0 ) +if (err <0 ) {ERROR (midi,"%s queue req: %d\n" , midi->in_ep->name, err); +free_ep_req (ep, req); + } }else {free_ep_req (ep, req); } --
Quoted 8 lines
Quoted 2 lines
2.1.4
I may know your problem, current midi library, alsa and this driver allow device sends as much data as possible, but without block the sending until host reads data, it only allocates the request buffer (using
midi_alloc_ep_req), but without free, so after you send enough data, it is out of memory.
Yes. Also there is the case where the usb cable is not conected, thus failing to hardware enqueue the request, causing a memory leak on this request.
Felipe
Re: [PATCH 3/3] usb: gadget: f_midi: free request when usb_ep_queue fails
Quoted 38 lines · Felipe Tonello
Hi Peter,
Quoted 26 lines · Peter Chen
Quoted 25 lines · Felipe F. Tonello
This fix a memory leak that will occur in this case.
Signed-off-by Felipe F. Tonello <[email protected]>--- drivers/usb/gadget/function/f_midi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/gadget/function/f_midi.c +3
-2@@ -550,9 +550,11 @@ static void f_midi_transmit(struct f_midi *midi, struct usb_request *req)int err; err =usb_ep_queue (ep, req,GFP_ATOMIC ); -if (err <0 ) +if (err <0 ) {ERROR (midi,"%s queue req: %d\n" , midi->in_ep->name, err); +free_ep_req (ep, req); + } }else {free_ep_req (ep, req); } --Quoted 8 lines
Quoted 2 lines
2.1.4
I may know your problem, current midi library, alsa and this driver allow device sends as much data as possible, but without block the sending until host reads data, it only allocates the request buffer (using
midi_alloc_ep_req), but without free, so after you send enough data, it is out of memory.
Quoted 4 lines
Yes. Also there is the case where the usb cable is not conected, thus failing to hardware enqueue the request, causing a memory leak on this request.
If the usb cable is not connected, the related endpoints should be not enabled. Would you really observe enqueue the request without cable connected?
Signature · 2 lines
Best Regards, Peter Chen
Re: [PATCH 3/3] usb: gadget: f_midi: free request when usb_ep_queue fails
Quoted 39 lines · Peter Chen
Quoted 38 lines · Felipe Tonello
Hi Peter,
Quoted 34 lines · Peter Chen
Quoted 25 lines · Felipe F. Tonello
This fix a memory leak that will occur in this case.
Signed-off-by Felipe F. Tonello <[email protected]>--- drivers/usb/gadget/function/f_midi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/gadget/function/f_midi.c +3
-2@@ -550,9 +550,11 @@ static void f_midi_transmit(struct f_midi *midi, struct usb_request *req)int err; err =usb_ep_queue (ep, req,GFP_ATOMIC ); -if (err <0 ) +if (err <0 ) {ERROR (midi,"%s queue req: %d\n" , midi->in_ep->name, err); +free_ep_req (ep, req); + } }else {free_ep_req (ep, req); } --Quoted 2 lines
2.1.4
I may know your problem, current midi library, alsa and this driver allow device sends as much data as possible, but without block the sending until host reads data, it only allocates the request buffer (using
midi_alloc_ep_req), but without free, so after you send enough data, it is out of memory.
Quoted 8 lines
Quoted 4 lines
Yes. Also there is the case where the usb cable is not conected, thus failing to hardware enqueue the request, causing a memory leak on this request.
If the usb cable is not connected, the related endpoints should be not enabled. Would you really observe enqueue the request without cable connected?
The usb_ep_queue() returns an error if it is not connected, causing the request never to be freed and never to be queued. Thus a memory leak happens.
Felipe
Re: [PATCH 3/3] usb: gadget: f_midi: free request when usb_ep_queue fails
Quoted 45 lines · Felipe Tonello
Quoted 44 lines · Peter Chen
Quoted 42 lines · Felipe Tonello
Hi Peter,
Quoted 26 lines · Peter Chen
Quoted 25 lines · Felipe F. Tonello
This fix a memory leak that will occur in this case.
Signed-off-by Felipe F. Tonello <[email protected]>--- drivers/usb/gadget/function/f_midi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/gadget/function/f_midi.c +3
-2@@ -550,9 +550,11 @@ static void f_midi_transmit(struct f_midi *midi, struct usb_request *req)int err; err =usb_ep_queue (ep, req,GFP_ATOMIC ); -if (err <0 ) +if (err <0 ) {ERROR (midi,"%s queue req: %d\n" , midi->in_ep->name, err); +free_ep_req (ep, req); + } }else {free_ep_req (ep, req); } --Quoted 8 lines
Quoted 2 lines
2.1.4
I may know your problem, current midi library, alsa and this driver allow device sends as much data as possible, but without block the sending until host reads data, it only allocates the request buffer (using
midi_alloc_ep_req), but without free, so after you send enough data, it is out of memory.Yes. Also there is the case where the usb cable is not conected, thus failing to hardware enqueue the request, causing a memory leak on this request.
Quoted 8 lines
Quoted 3 lines
If the usb cable is not connected, the related endpoints should be not enabled. Would you really observe enqueue the request without cable connected?
The
usb_ep_queue()returns an error if it is not connected, causing the request never to be freed and never to be queued. Thus a memory leak happens.
If it is not connected, the ep is not enabled, why we will call usb_ep_queue? If it really does, there must be something wrong.
Signature · 2 lines
Best Regards, Peter Chen
Re: [PATCH 3/3] usb: gadget: f_midi: free request when usb_ep_queue fails
Quoted 50 lines · Peter Chen
Quoted 49 lines · Felipe Tonello
Quoted 47 lines · Peter Chen
Quoted 38 lines · Felipe Tonello
Hi Peter,
Quoted 26 lines · Peter Chen
Quoted 25 lines · Felipe F. Tonello
This fix a memory leak that will occur in this case.
Signed-off-by Felipe F. Tonello <[email protected]>--- drivers/usb/gadget/function/f_midi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/usb/gadget/function/f_midi.c +3
-2@@ -550,9 +550,11 @@ static void f_midi_transmit(struct f_midi *midi, struct usb_request *req)int err; err =usb_ep_queue (ep, req,GFP_ATOMIC ); -if (err <0 ) +if (err <0 ) {ERROR (midi,"%s queue req: %d\n" , midi->in_ep->name, err); +free_ep_req (ep, req); + } }else {free_ep_req (ep, req); } --Quoted 8 lines
Quoted 2 lines
2.1.4
I may know your problem, current midi library, alsa and this driver allow device sends as much data as possible, but without block the sending until host reads data, it only allocates the request buffer (using
midi_alloc_ep_req), but without free, so after you send enough data, it is out of memory.Quoted 4 lines
Yes. Also there is the case where the usb cable is not conected, thus failing to hardware enqueue the request, causing a memory leak on this request.
If the usb cable is not connected, the related endpoints should be not enabled. Would you really observe enqueue the request without cable connected?
Quoted 7 lines
Quoted 4 lines
The
usb_ep_queue()returns an error if it is not connected, causing the request never to be freed and never to be queued. Thus a memory leak happens.If it is not connected, the ep is not enabled, why we will call
usb_ep_queue? If it really does, there must be something wrong.
Ok. I can do another patch to check for that. But this patch still applies, because if for some reason the usb_ep_queue() returns an error, it will not leak memory.
Felipe
Felipe Balbi
NAKHi,
Quoted 13 lines · Felipe F. Tonello
If
CONFIG_PMorCONFIG_PM_SLEEPis not set, driver will not compile properly.Signed-off-by Felipe F. Tonello <[email protected]>--- drivers/usb/chipidea/core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/usb/chipidea/core.c +0
-0
drivers/usb/chipidea/core.c static int ci_runtime_resume(struct device *dev) · line 1015
Quoted 8 lines
drivers/usb/chipidea/core.c +2
-1@@ -1009,18 +1009,22 @@ static int ci_runtime_resume(struct device *dev)return ci_controller_resume (dev); } -#endif /* CONFIG_PM */ static const struct dev_pm_ops ci_pm_ops = { +#ifdef CONFIG_PM_SLEEPSET_SYSTEM_SLEEP_PM_OPS (ci_suspend, ci_resume) +#endif /* CONFIG_PM_SLEEP */
NAK, this is not the right way to do it. Look at the definition of SET_SYSTEM_SLEEP_PM_OPS() and other users in the kernel.
Quoted 18 lines
drivers/usb/chipidea/core.c +3
-0SET_RUNTIME_PM_OPS (ci_runtime_suspend, ci_runtime_resume,NULL ) }; +#endif /* CONFIG_PM */ static struct platform_driver ci_hdrc_driver = { .probe = ci_hdrc_probe, .remove = ci_hdrc_remove, .driver = { .name ="ci_hdrc" , +#ifdef CONFIG_PM .pm = &ci_pm_ops, +#endif }, };Signature · 1 line
2.1.4
Signature · 1 line
balbi