linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware
@ 2012-10-19 17:19 Simon Haggett
  2012-10-19 17:37 ` Felipe Balbi
  0 siblings, 1 reply; 10+ messages in thread
From: Simon Haggett @ 2012-10-19 17:19 UTC (permalink / raw)
  To: Li Yang, Felipe Balbi
  Cc: Greg Kroah-Hartman, linux-usb, linuxppc-dev, linux-kernel, Simon Haggett

Some gadget drivers may attempt to dequeue requests for an endpoint that has
already been disabled. For example, in the UVC gadget driver, uvc_function_set_alt()
will call usb_ep_disable() when alt setting 0 is selected. When the userspace
application subsequently issues the VIDIOC_STREAMOFF ioctl, uvc_video_enable()
invokes usb_ep_dequeue() to ensure that all requests have been cancelled.

For the Freescale High Speed Dual-Role USB controller, fsl_ep_dequeue() provides
the implementation of usb_ep_dequeue(). If this is called for a disabled endpoint,
a kernel oops will occur when the ep->ep.desc field is dereferenced (by ep_index()).
fsl_ep_disable() sets this field to NULL, as well as deleting all pending requests
for the endpoint.

This patch adds an additional check to fsl_ep_dequeue() to ensure that the
endpoint has not already been disabled before attempting to dequeue requests.

Signed-off-by: Simon Haggett <simon.haggett@realvnc.com>
---
 drivers/usb/gadget/fsl_udc_core.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 6ae70cb..acd513b 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -955,7 +955,10 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 	int ep_num, stopped, ret = 0;
 	u32 epctrl;
 
-	if (!_ep || !_req)
+	/* Ensure that the ep and request are valid, and the ep is not
+	 * disabled
+	 */
+	if (!_ep || !_req || !ep->ep.desc)
 		return -EINVAL;
 
 	spin_lock_irqsave(&ep->udc->lock, flags);
-- 
1.7.4.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware
  2012-10-19 17:19 [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware Simon Haggett
@ 2012-10-19 17:37 ` Felipe Balbi
  2012-10-22  3:33   ` Li Yang-R58472
  0 siblings, 1 reply; 10+ messages in thread
From: Felipe Balbi @ 2012-10-19 17:37 UTC (permalink / raw)
  To: Simon Haggett
  Cc: Li Yang, Felipe Balbi, Greg Kroah-Hartman, linux-usb,
	linuxppc-dev, linux-kernel, Laurent Pinchart

[-- Attachment #1: Type: text/plain, Size: 1972 bytes --]

Hi,

On Fri, Oct 19, 2012 at 06:19:26PM +0100, Simon Haggett wrote:
> Some gadget drivers may attempt to dequeue requests for an endpoint that has
> already been disabled. For example, in the UVC gadget driver, uvc_function_set_alt()
> will call usb_ep_disable() when alt setting 0 is selected. When the userspace
> application subsequently issues the VIDIOC_STREAMOFF ioctl, uvc_video_enable()
> invokes usb_ep_dequeue() to ensure that all requests have been cancelled.

bug is on uvc gadget, then. Laurent ?

Also, fsl should be removed from the tree, I'm trying to persuade iMX
folks to use drivers/usb/chipidea instead.

> For the Freescale High Speed Dual-Role USB controller, fsl_ep_dequeue() provides
> the implementation of usb_ep_dequeue(). If this is called for a disabled endpoint,
> a kernel oops will occur when the ep->ep.desc field is dereferenced (by ep_index()).
> fsl_ep_disable() sets this field to NULL, as well as deleting all pending requests
> for the endpoint.
> 
> This patch adds an additional check to fsl_ep_dequeue() to ensure that the
> endpoint has not already been disabled before attempting to dequeue requests.
> 
> Signed-off-by: Simon Haggett <simon.haggett@realvnc.com>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |    5 ++++-
>  1 files changed, 4 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> index 6ae70cb..acd513b 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -955,7 +955,10 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
>  	int ep_num, stopped, ret = 0;
>  	u32 epctrl;
>  
> -	if (!_ep || !_req)
> +	/* Ensure that the ep and request are valid, and the ep is not
> +	 * disabled
> +	 */
> +	if (!_ep || !_req || !ep->ep.desc)
>  		return -EINVAL;
>  
>  	spin_lock_irqsave(&ep->udc->lock, flags);
> -- 
> 1.7.4.1
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware
  2012-10-19 17:37 ` Felipe Balbi
@ 2012-10-22  3:33   ` Li Yang-R58472
  2012-10-22  7:53     ` Felipe Balbi
  2012-10-22 10:47     ` Laurent Pinchart
  0 siblings, 2 replies; 10+ messages in thread
From: Li Yang-R58472 @ 2012-10-22  3:33 UTC (permalink / raw)
  To: balbi, Simon Haggett
  Cc: Greg Kroah-Hartman, linux-usb, linuxppc-dev, linux-kernel,
	Laurent Pinchart



> -----Original Message-----
> From: Felipe Balbi [mailto:balbi@ti.com]
> Sent: Saturday, October 20, 2012 1:37 AM
> To: Simon Haggett
> Cc: Li Yang-R58472; Felipe Balbi; Greg Kroah-Hartman; linux-
> usb@vger.kernel.org; linuxppc-dev@lists.ozlabs.org; linux-
> kernel@vger.kernel.org; Laurent Pinchart
> Subject: Re: [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests
> for a disabled USB endpoint on Freescale hardware
> 
> Hi,
> 
> On Fri, Oct 19, 2012 at 06:19:26PM +0100, Simon Haggett wrote:
> > Some gadget drivers may attempt to dequeue requests for an endpoint
> > that has already been disabled. For example, in the UVC gadget driver,
> > uvc_function_set_alt() will call usb_ep_disable() when alt setting 0
> > is selected. When the userspace application subsequently issues the
> > VIDIOC_STREAMOFF ioctl, uvc_video_enable() invokes usb_ep_dequeue() to
> ensure that all requests have been cancelled.
> 
> bug is on uvc gadget, then. Laurent ?
> 
> Also, fsl should be removed from the tree, I'm trying to persuade iMX
> folks to use drivers/usb/chipidea instead.

Besides the iMX usage, the driver is also being used by many Freescale PowerPC/Coldfire SoCs.  I agree that it's ideal to move to a common driver.  But it is a large task to make the chipidea driver works for all the hardware that fsl_udc had supported and been tested on.

> 
> > For the Freescale High Speed Dual-Role USB controller,
> > fsl_ep_dequeue() provides the implementation of usb_ep_dequeue(). If
> > this is called for a disabled endpoint, a kernel oops will occur when
> the ep->ep.desc field is dereferenced (by ep_index()).
> > fsl_ep_disable() sets this field to NULL, as well as deleting all
> > pending requests for the endpoint.
> >
> > This patch adds an additional check to fsl_ep_dequeue() to ensure that
> > the endpoint has not already been disabled before attempting to dequeue
> requests.
> >
> > Signed-off-by: Simon Haggett <simon.haggett@realvnc.com>
> > ---
> >  drivers/usb/gadget/fsl_udc_core.c |    5 ++++-
> >  1 files changed, 4 insertions(+), 1 deletions(-)
> >
> > diff --git a/drivers/usb/gadget/fsl_udc_core.c
> > b/drivers/usb/gadget/fsl_udc_core.c
> > index 6ae70cb..acd513b 100644
> > --- a/drivers/usb/gadget/fsl_udc_core.c
> > +++ b/drivers/usb/gadget/fsl_udc_core.c
> > @@ -955,7 +955,10 @@ static int fsl_ep_dequeue(struct usb_ep *_ep,
> struct usb_request *_req)
> >  	int ep_num, stopped, ret = 0;
> >  	u32 epctrl;
> >
> > -	if (!_ep || !_req)
> > +	/* Ensure that the ep and request are valid, and the ep is not
> > +	 * disabled
> > +	 */
> > +	if (!_ep || !_req || !ep->ep.desc)
> >  		return -EINVAL;
> >
> >  	spin_lock_irqsave(&ep->udc->lock, flags);
> > --
> > 1.7.4.1
> >
> 
> --
> balbi


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware
  2012-10-22  3:33   ` Li Yang-R58472
@ 2012-10-22  7:53     ` Felipe Balbi
  2012-10-22 10:47     ` Laurent Pinchart
  1 sibling, 0 replies; 10+ messages in thread
From: Felipe Balbi @ 2012-10-22  7:53 UTC (permalink / raw)
  To: Li Yang-R58472
  Cc: balbi, Simon Haggett, Greg Kroah-Hartman, linux-usb,
	linuxppc-dev, linux-kernel, Laurent Pinchart

[-- Attachment #1: Type: text/plain, Size: 1964 bytes --]

On Mon, Oct 22, 2012 at 03:33:19AM +0000, Li Yang-R58472 wrote:
> 
> 
> > -----Original Message-----
> > From: Felipe Balbi [mailto:balbi@ti.com]
> > Sent: Saturday, October 20, 2012 1:37 AM
> > To: Simon Haggett
> > Cc: Li Yang-R58472; Felipe Balbi; Greg Kroah-Hartman; linux-
> > usb@vger.kernel.org; linuxppc-dev@lists.ozlabs.org; linux-
> > kernel@vger.kernel.org; Laurent Pinchart
> > Subject: Re: [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests
> > for a disabled USB endpoint on Freescale hardware
> > 
> > Hi,
> > 
> > On Fri, Oct 19, 2012 at 06:19:26PM +0100, Simon Haggett wrote:
> > > Some gadget drivers may attempt to dequeue requests for an endpoint
> > > that has already been disabled. For example, in the UVC gadget driver,
> > > uvc_function_set_alt() will call usb_ep_disable() when alt setting 0
> > > is selected. When the userspace application subsequently issues the
> > > VIDIOC_STREAMOFF ioctl, uvc_video_enable() invokes usb_ep_dequeue() to
> > ensure that all requests have been cancelled.
> > 
> > bug is on uvc gadget, then. Laurent ?
> > 
> > Also, fsl should be removed from the tree, I'm trying to persuade iMX
> > folks to use drivers/usb/chipidea instead.
> 
> Besides the iMX usage, the driver is also being used by many Freescale
> PowerPC/Coldfire SoCs.  I agree that it's ideal to move to a common
> driver.  But it is a large task to make the chipidea driver works for
> all the hardware that fsl_udc had supported and been tested on.

I understand that, but we just can't keep so many duplicated drivers in
mainline. chipidea udc had at least 3 different implementations. Now
it's the time to combine all of those and stick to a single driver.

Just make a plan to slowly move towards chipidea in the upcoming few
merge windows. I can continue to take in bugfixes for fsl_udc, but only
if I see that you guys are working towards merging with chipidea driver.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware
  2012-10-22  3:33   ` Li Yang-R58472
  2012-10-22  7:53     ` Felipe Balbi
@ 2012-10-22 10:47     ` Laurent Pinchart
  2012-10-22 10:56       ` Felipe Balbi
  2012-10-22 11:49       ` Simon Haggett
  1 sibling, 2 replies; 10+ messages in thread
From: Laurent Pinchart @ 2012-10-22 10:47 UTC (permalink / raw)
  To: Li Yang-R58472
  Cc: balbi, Simon Haggett, Greg Kroah-Hartman, linux-usb,
	linuxppc-dev, linux-kernel

Hi,

On Monday 22 October 2012 03:33:19 Li Yang-R58472 wrote:
> On Saturday, October 20, 2012 1:37 AM Felipe Balbi wrote:
> > On Fri, Oct 19, 2012 at 06:19:26PM +0100, Simon Haggett wrote:
> > > Some gadget drivers may attempt to dequeue requests for an endpoint
> > > that has already been disabled. For example, in the UVC gadget driver,
> > > uvc_function_set_alt() will call usb_ep_disable() when alt setting 0
> > > is selected. When the userspace application subsequently issues the
> > > VIDIOC_STREAMOFF ioctl, uvc_video_enable() invokes usb_ep_dequeue() to
> > 
> > ensure that all requests have been cancelled.
> > 
> > bug is on uvc gadget, then. Laurent ?

We've discussed this topic a couple of months before. I believe that's not a 
bug.

http://68.183.106.108/lists/linux-usb/msg68869.html

> > Also, fsl should be removed from the tree, I'm trying to persuade iMX
> > folks to use drivers/usb/chipidea instead.
> 
> Besides the iMX usage, the driver is also being used by many Freescale
> PowerPC/Coldfire SoCs.  I agree that it's ideal to move to a common driver.
> But it is a large task to make the chipidea driver works for all the
> hardware that fsl_udc had supported and been tested on.
>
> > > For the Freescale High Speed Dual-Role USB controller,
> > > fsl_ep_dequeue() provides the implementation of usb_ep_dequeue(). If
> > > this is called for a disabled endpoint, a kernel oops will occur when
> > 
> > the ep->ep.desc field is dereferenced (by ep_index()).
> > 
> > > fsl_ep_disable() sets this field to NULL, as well as deleting all
> > > pending requests for the endpoint.
> > > 
> > > This patch adds an additional check to fsl_ep_dequeue() to ensure that
> > > the endpoint has not already been disabled before attempting to dequeue
> > 
> > requests.
> > 
> > > Signed-off-by: Simon Haggett <simon.haggett@realvnc.com>
> > > ---
> > > 
> > >  drivers/usb/gadget/fsl_udc_core.c |    5 ++++-
> > >  1 files changed, 4 insertions(+), 1 deletions(-)
> > > 
> > > diff --git a/drivers/usb/gadget/fsl_udc_core.c
> > > b/drivers/usb/gadget/fsl_udc_core.c
> > > index 6ae70cb..acd513b 100644
> > > --- a/drivers/usb/gadget/fsl_udc_core.c
> > > +++ b/drivers/usb/gadget/fsl_udc_core.c
> > > @@ -955,7 +955,10 @@ static int fsl_ep_dequeue(struct usb_ep *_ep,
> > struct usb_request *_req)
> > 
> > >  	int ep_num, stopped, ret = 0;
> > >  	u32 epctrl;
> > > 
> > > -	if (!_ep || !_req)
> > > +	/* Ensure that the ep and request are valid, and the ep is not
> > > +	 * disabled
> > > +	 */
> > > +	if (!_ep || !_req || !ep->ep.desc)
> > >  		return -EINVAL;

Shouldn't that last check be done with a lock taken ?

> > >  	spin_lock_irqsave(&ep->udc->lock, flags);

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware
  2012-10-22 10:47     ` Laurent Pinchart
@ 2012-10-22 10:56       ` Felipe Balbi
  2012-10-25  0:36         ` Laurent Pinchart
  2012-10-22 11:49       ` Simon Haggett
  1 sibling, 1 reply; 10+ messages in thread
From: Felipe Balbi @ 2012-10-22 10:56 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Li Yang-R58472, balbi, Simon Haggett, Greg Kroah-Hartman,
	linux-usb, linuxppc-dev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1189 bytes --]

Hi,

On Mon, Oct 22, 2012 at 12:47:21PM +0200, Laurent Pinchart wrote:
> Hi,
> 
> On Monday 22 October 2012 03:33:19 Li Yang-R58472 wrote:
> > On Saturday, October 20, 2012 1:37 AM Felipe Balbi wrote:
> > > On Fri, Oct 19, 2012 at 06:19:26PM +0100, Simon Haggett wrote:
> > > > Some gadget drivers may attempt to dequeue requests for an endpoint
> > > > that has already been disabled. For example, in the UVC gadget driver,
> > > > uvc_function_set_alt() will call usb_ep_disable() when alt setting 0
> > > > is selected. When the userspace application subsequently issues the
> > > > VIDIOC_STREAMOFF ioctl, uvc_video_enable() invokes usb_ep_dequeue() to
> > > 
> > > ensure that all requests have been cancelled.
> > > 
> > > bug is on uvc gadget, then. Laurent ?
> 
> We've discussed this topic a couple of months before. I believe that's not a 
> bug.
> 
> http://68.183.106.108/lists/linux-usb/msg68869.html

fair enough :-)

That's a different case, however. At the link above we're discussing
dequeueing a request which is already being dequeued. $SUBJECT is trying
to fix dequeueing of a request for an endpoint which isn't even enabled.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware
  2012-10-22 10:47     ` Laurent Pinchart
  2012-10-22 10:56       ` Felipe Balbi
@ 2012-10-22 11:49       ` Simon Haggett
  2012-10-25  0:33         ` Laurent Pinchart
  1 sibling, 1 reply; 10+ messages in thread
From: Simon Haggett @ 2012-10-22 11:49 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: Li Yang-R58472, balbi, Greg Kroah-Hartman, linux-usb,
	linuxppc-dev, linux-kernel

Hi

On 22/10/12 11:47, Laurent Pinchart wrote:
> Hi,
>
> On Monday 22 October 2012 03:33:19 Li Yang-R58472 wrote:
>> On Saturday, October 20, 2012 1:37 AM Felipe Balbi wrote:
>>> On Fri, Oct 19, 2012 at 06:19:26PM +0100, Simon Haggett wrote:
>>>> Some gadget drivers may attempt to dequeue requests for an endpoint
>>>> that has already been disabled. For example, in the UVC gadget driver,
>>>> uvc_function_set_alt() will call usb_ep_disable() when alt setting 0
>>>> is selected. When the userspace application subsequently issues the
>>>> VIDIOC_STREAMOFF ioctl, uvc_video_enable() invokes usb_ep_dequeue() to
>>>
>>> ensure that all requests have been cancelled.
>>>
>>> bug is on uvc gadget, then. Laurent ?
>
> We've discussed this topic a couple of months before. I believe that's not a
> bug.
>
> http://68.183.106.108/lists/linux-usb/msg68869.html
>
>>> Also, fsl should be removed from the tree, I'm trying to persuade iMX
>>> folks to use drivers/usb/chipidea instead.
>>
>> Besides the iMX usage, the driver is also being used by many Freescale
>> PowerPC/Coldfire SoCs.  I agree that it's ideal to move to a common driver.
>> But it is a large task to make the chipidea driver works for all the
>> hardware that fsl_udc had supported and been tested on.
>>
>>>> For the Freescale High Speed Dual-Role USB controller,
>>>> fsl_ep_dequeue() provides the implementation of usb_ep_dequeue(). If
>>>> this is called for a disabled endpoint, a kernel oops will occur when
>>>
>>> the ep->ep.desc field is dereferenced (by ep_index()).
>>>
>>>> fsl_ep_disable() sets this field to NULL, as well as deleting all
>>>> pending requests for the endpoint.
>>>>
>>>> This patch adds an additional check to fsl_ep_dequeue() to ensure that
>>>> the endpoint has not already been disabled before attempting to dequeue
>>>
>>> requests.
>>>
>>>> Signed-off-by: Simon Haggett <simon.haggett@realvnc.com>
>>>> ---
>>>>
>>>>   drivers/usb/gadget/fsl_udc_core.c |    5 ++++-
>>>>   1 files changed, 4 insertions(+), 1 deletions(-)
>>>>
>>>> diff --git a/drivers/usb/gadget/fsl_udc_core.c
>>>> b/drivers/usb/gadget/fsl_udc_core.c
>>>> index 6ae70cb..acd513b 100644
>>>> --- a/drivers/usb/gadget/fsl_udc_core.c
>>>> +++ b/drivers/usb/gadget/fsl_udc_core.c
>>>> @@ -955,7 +955,10 @@ static int fsl_ep_dequeue(struct usb_ep *_ep,
>>> struct usb_request *_req)
>>>
>>>>   	int ep_num, stopped, ret = 0;
>>>>   	u32 epctrl;
>>>>
>>>> -	if (!_ep || !_req)
>>>> +	/* Ensure that the ep and request are valid, and the ep is not
>>>> +	 * disabled
>>>> +	 */
>>>> +	if (!_ep || !_req || !ep->ep.desc)
>>>>   		return -EINVAL;
>
> Shouldn't that last check be done with a lock taken ?

I had presumed a lock wasn't necessary because ep->ep.desc is only set 
to NULL by fsl_ep_disable() which, since it is called by 
usb_ep_disable(), should only be invoked when no other task is using the 
endpoint (according to include/linux/usb/gadget.h). Furthermore, the 
chipidea UDC driver does check the equivalent of this field is not NULL 
without taking a lock (ep_dequeue() in drivers/usb/chipidea/udc.c).

However, it is possible that I'm misunderstanding something here, so 
apologies if I am.

>
>>>>   	spin_lock_irqsave(&ep->udc->lock, flags);
>

Many thanks

Simon


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware
  2012-10-22 11:49       ` Simon Haggett
@ 2012-10-25  0:33         ` Laurent Pinchart
  0 siblings, 0 replies; 10+ messages in thread
From: Laurent Pinchart @ 2012-10-25  0:33 UTC (permalink / raw)
  To: Simon Haggett
  Cc: Li Yang-R58472, balbi, Greg Kroah-Hartman, linux-usb,
	linuxppc-dev, linux-kernel

Hi Simon,

On Monday 22 October 2012 12:49:51 Simon Haggett wrote:
> On 22/10/12 11:47, Laurent Pinchart wrote:
> > On Monday 22 October 2012 03:33:19 Li Yang-R58472 wrote:
> >> On Saturday, October 20, 2012 1:37 AM Felipe Balbi wrote:
> >>> On Fri, Oct 19, 2012 at 06:19:26PM +0100, Simon Haggett wrote:
> >>>> Some gadget drivers may attempt to dequeue requests for an endpoint
> >>>> that has already been disabled. For example, in the UVC gadget driver,
> >>>> uvc_function_set_alt() will call usb_ep_disable() when alt setting 0
> >>>> is selected. When the userspace application subsequently issues the
> >>>> VIDIOC_STREAMOFF ioctl, uvc_video_enable() invokes usb_ep_dequeue() to
> >>> 
> >>> ensure that all requests have been cancelled.
> >>> 
> >>> bug is on uvc gadget, then. Laurent ?
> > 
> > We've discussed this topic a couple of months before. I believe that's not
> > a bug.
> > 
> > http://68.183.106.108/lists/linux-usb/msg68869.html
> > 
> >>> Also, fsl should be removed from the tree, I'm trying to persuade iMX
> >>> folks to use drivers/usb/chipidea instead.
> >> 
> >> Besides the iMX usage, the driver is also being used by many Freescale
> >> PowerPC/Coldfire SoCs.  I agree that it's ideal to move to a common
> >> driver.
> >> But it is a large task to make the chipidea driver works for all the
> >> hardware that fsl_udc had supported and been tested on.
> >> 
> >>>> For the Freescale High Speed Dual-Role USB controller,
> >>>> fsl_ep_dequeue() provides the implementation of usb_ep_dequeue(). If
> >>>> this is called for a disabled endpoint, a kernel oops will occur when
> >>> 
> >>> the ep->ep.desc field is dereferenced (by ep_index()).
> >>> 
> >>>> fsl_ep_disable() sets this field to NULL, as well as deleting all
> >>>> pending requests for the endpoint.
> >>>> 
> >>>> This patch adds an additional check to fsl_ep_dequeue() to ensure that
> >>>> the endpoint has not already been disabled before attempting to dequeue
> >>> 
> >>> requests.
> >>> 
> >>>> Signed-off-by: Simon Haggett <simon.haggett@realvnc.com>
> >>>> ---
> >>>> 
> >>>>   drivers/usb/gadget/fsl_udc_core.c |    5 ++++-
> >>>>   1 files changed, 4 insertions(+), 1 deletions(-)
> >>>> 
> >>>> diff --git a/drivers/usb/gadget/fsl_udc_core.c
> >>>> b/drivers/usb/gadget/fsl_udc_core.c
> >>>> index 6ae70cb..acd513b 100644
> >>>> --- a/drivers/usb/gadget/fsl_udc_core.c
> >>>> +++ b/drivers/usb/gadget/fsl_udc_core.c
> >>>> @@ -955,7 +955,10 @@ static int fsl_ep_dequeue(struct usb_ep *_ep,
> >>> 
> >>> struct usb_request *_req)
> >>> 
> >>>>   	int ep_num, stopped, ret = 0;
> >>>>   	u32 epctrl;
> >>>> 
> >>>> -	if (!_ep || !_req)
> >>>> +	/* Ensure that the ep and request are valid, and the ep is not
> >>>> +	 * disabled
> >>>> +	 */
> >>>> +	if (!_ep || !_req || !ep->ep.desc)
> >>>> 
> >>>>   		return -EINVAL;
> > 
> > Shouldn't that last check be done with a lock taken ?
> 
> I had presumed a lock wasn't necessary because ep->ep.desc is only set
> to NULL by fsl_ep_disable() which, since it is called by
> usb_ep_disable(), should only be invoked when no other task is using the
> endpoint (according to include/linux/usb/gadget.h). Furthermore, the
> chipidea UDC driver does check the equivalent of this field is not NULL
> without taking a lock (ep_dequeue() in drivers/usb/chipidea/udc.c).
> 
> However, it is possible that I'm misunderstanding something here, so
> apologies if I am.

I might be wrong as well :-) I just wanted to point out something that 
appeared to me as a possible issue.

> >>>>   	spin_lock_irqsave(&ep->udc->lock, flags);

-- 
Regards,

Laurent Pinchart


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware
  2012-10-22 10:56       ` Felipe Balbi
@ 2012-10-25  0:36         ` Laurent Pinchart
  2012-10-26  8:14           ` Felipe Balbi
  0 siblings, 1 reply; 10+ messages in thread
From: Laurent Pinchart @ 2012-10-25  0:36 UTC (permalink / raw)
  To: balbi
  Cc: Li Yang-R58472, Simon Haggett, Greg Kroah-Hartman, linux-usb,
	linuxppc-dev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1428 bytes --]

Hi Felipe,

On Monday 22 October 2012 13:56:01 Felipe Balbi wrote:
> On Mon, Oct 22, 2012 at 12:47:21PM +0200, Laurent Pinchart wrote:
> > On Monday 22 October 2012 03:33:19 Li Yang-R58472 wrote:
> > > On Saturday, October 20, 2012 1:37 AM Felipe Balbi wrote:
> > > > On Fri, Oct 19, 2012 at 06:19:26PM +0100, Simon Haggett wrote:
> > > > > Some gadget drivers may attempt to dequeue requests for an endpoint
> > > > > that has already been disabled. For example, in the UVC gadget
> > > > > driver, uvc_function_set_alt() will call usb_ep_disable() when alt
> > > > > setting 0 is selected. When the userspace application subsequently
> > > > > issues the VIDIOC_STREAMOFF ioctl, uvc_video_enable() invokes
> > > > > usb_ep_dequeue() to ensure that all requests have been cancelled.
> > > > 
> > > > bug is on uvc gadget, then. Laurent ?
> > 
> > We've discussed this topic a couple of months before. I believe that's not
> > a bug.
> > 
> > http://68.183.106.108/lists/linux-usb/msg68869.html
> 
> fair enough :-)
> 
> That's a different case, however. At the link above we're discussing
> dequeueing a request which is already being dequeued. $SUBJECT is trying
> to fix dequeueing of a request for an endpoint which isn't even enabled.

You've got a point there :-) That's a different case indeed, I'm open to (at 
least evaluating) a fix in the UVC gadget driver if you think that's better.

-- 
Regards,

Laurent Pinchart

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 490 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware
  2012-10-25  0:36         ` Laurent Pinchart
@ 2012-10-26  8:14           ` Felipe Balbi
  0 siblings, 0 replies; 10+ messages in thread
From: Felipe Balbi @ 2012-10-26  8:14 UTC (permalink / raw)
  To: Laurent Pinchart
  Cc: balbi, Li Yang-R58472, Simon Haggett, Greg Kroah-Hartman,
	linux-usb, linuxppc-dev, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1695 bytes --]

Hi,

On Thu, Oct 25, 2012 at 02:36:24AM +0200, Laurent Pinchart wrote:
> Hi Felipe,
> 
> On Monday 22 October 2012 13:56:01 Felipe Balbi wrote:
> > On Mon, Oct 22, 2012 at 12:47:21PM +0200, Laurent Pinchart wrote:
> > > On Monday 22 October 2012 03:33:19 Li Yang-R58472 wrote:
> > > > On Saturday, October 20, 2012 1:37 AM Felipe Balbi wrote:
> > > > > On Fri, Oct 19, 2012 at 06:19:26PM +0100, Simon Haggett wrote:
> > > > > > Some gadget drivers may attempt to dequeue requests for an endpoint
> > > > > > that has already been disabled. For example, in the UVC gadget
> > > > > > driver, uvc_function_set_alt() will call usb_ep_disable() when alt
> > > > > > setting 0 is selected. When the userspace application subsequently
> > > > > > issues the VIDIOC_STREAMOFF ioctl, uvc_video_enable() invokes
> > > > > > usb_ep_dequeue() to ensure that all requests have been cancelled.
> > > > > 
> > > > > bug is on uvc gadget, then. Laurent ?
> > > 
> > > We've discussed this topic a couple of months before. I believe that's not
> > > a bug.
> > > 
> > > http://68.183.106.108/lists/linux-usb/msg68869.html
> > 
> > fair enough :-)
> > 
> > That's a different case, however. At the link above we're discussing
> > dequeueing a request which is already being dequeued. $SUBJECT is trying
> > to fix dequeueing of a request for an endpoint which isn't even enabled.
> 
> You've got a point there :-) That's a different case indeed, I'm open to (at 
> least evaluating) a fix in the UVC gadget driver if you think that's better.

I _do_ think that's better. If the endpoint isn't even enabled, why are
you trying to dequeue a request ? :-)

cheers

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-10-26  8:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-19 17:19 [PATCH 1/1] usb: gadget: Don't attempt to dequeue requests for a disabled USB endpoint on Freescale hardware Simon Haggett
2012-10-19 17:37 ` Felipe Balbi
2012-10-22  3:33   ` Li Yang-R58472
2012-10-22  7:53     ` Felipe Balbi
2012-10-22 10:47     ` Laurent Pinchart
2012-10-22 10:56       ` Felipe Balbi
2012-10-25  0:36         ` Laurent Pinchart
2012-10-26  8:14           ` Felipe Balbi
2012-10-22 11:49       ` Simon Haggett
2012-10-25  0:33         ` Laurent Pinchart

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).