2012-05-09 08:49:36

by Nicolas Ferre

[permalink] [raw]
Subject: [PATCH] USB: ohci-at91: add a reset function to fix race condition

A possible race condition appears because we are not initializing
the ohci->regs before calling usb_hcd_request_irqs().
We move the call to ohci_init() in hcd->driver->reset() instead of
hcd->driver->start() to fix this.
This was experienced when we share the same IRQ line between OHCI and EHCI
controllers.

Signed-off-by: Nicolas Ferre <[email protected]>
Tested-by: Christian Eggers <[email protected]>
Cc: stable <[email protected]>
---
drivers/usb/host/ohci-at91.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 13ebeca..55d3d64 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -223,7 +223,7 @@ static void __devexit usb_hcd_at91_remove(struct usb_hcd *hcd,
/*-------------------------------------------------------------------------*/

static int __devinit
-ohci_at91_start (struct usb_hcd *hcd)
+ohci_at91_reset (struct usb_hcd *hcd)
{
struct at91_usbh_data *board = hcd->self.controller->platform_data;
struct ohci_hcd *ohci = hcd_to_ohci (hcd);
@@ -233,6 +233,14 @@ ohci_at91_start (struct usb_hcd *hcd)
return ret;

ohci->num_ports = board->ports;
+ return 0;
+}
+
+static int __devinit
+ohci_at91_start (struct usb_hcd *hcd)
+{
+ struct ohci_hcd *ohci = hcd_to_ohci (hcd);
+ int ret;

if ((ret = ohci_run(ohci)) < 0) {
err("can't start %s", hcd->self.bus_name);
@@ -418,6 +426,7 @@ static const struct hc_driver ohci_at91_hc_driver = {
/*
* basic lifecycle operations
*/
+ .reset = ohci_at91_reset,
.start = ohci_at91_start,
.stop = ohci_stop,
.shutdown = ohci_shutdown,
--
1.7.10


2012-05-09 17:22:58

by Sergei Shtylyov

[permalink] [raw]
Subject: Re: [PATCH] USB: ohci-at91: add a reset function to fix race condition

Hello.

On 09-05-2012 12:48, Nicolas Ferre wrote:

> A possible race condition appears because we are not initializing
> the ohci->regs before calling usb_hcd_request_irqs().
> We move the call to ohci_init() in hcd->driver->reset() instead of
> hcd->driver->start() to fix this.
> This was experienced when we share the same IRQ line between OHCI and EHCI
> controllers.

> Signed-off-by: Nicolas Ferre<[email protected]>
> Tested-by: Christian Eggers<[email protected]>
> Cc: stable<[email protected]>
> ---
> drivers/usb/host/ohci-at91.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)

> diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
> index 13ebeca..55d3d64 100644
> --- a/drivers/usb/host/ohci-at91.c
> +++ b/drivers/usb/host/ohci-at91.c
> @@ -223,7 +223,7 @@ static void __devexit usb_hcd_at91_remove(struct usb_hcd *hcd,
> /*-------------------------------------------------------------------------*/
>
> static int __devinit
> -ohci_at91_start (struct usb_hcd *hcd)
> +ohci_at91_reset (struct usb_hcd *hcd)

Have you run the patch thru scripts/checkpatch.pl? There should be no
space between function name and '('.

> {
> struct at91_usbh_data *board = hcd->self.controller->platform_data;
> struct ohci_hcd *ohci = hcd_to_ohci (hcd);
> @@ -233,6 +233,14 @@ ohci_at91_start (struct usb_hcd *hcd)
> return ret;
>
> ohci->num_ports = board->ports;
> + return 0;
> +}
> +
> +static int __devinit
> +ohci_at91_start (struct usb_hcd *hcd)

Same here.

> +{
> + struct ohci_hcd *ohci = hcd_to_ohci (hcd);

And here.

WBR, Sergei

2012-05-09 17:45:38

by Alan Stern

[permalink] [raw]
Subject: Re: [PATCH] USB: ohci-at91: add a reset function to fix race condition

On Wed, 9 May 2012, Nicolas Ferre wrote:

> A possible race condition appears because we are not initializing
> the ohci->regs before calling usb_hcd_request_irqs().
> We move the call to ohci_init() in hcd->driver->reset() instead of
> hcd->driver->start() to fix this.
> This was experienced when we share the same IRQ line between OHCI and EHCI
> controllers.
>
> Signed-off-by: Nicolas Ferre <[email protected]>
> Tested-by: Christian Eggers <[email protected]>
> Cc: stable <[email protected]>

Acked-by: Alan Stern <[email protected]>

> ---
> drivers/usb/host/ohci-at91.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
> index 13ebeca..55d3d64 100644
> --- a/drivers/usb/host/ohci-at91.c
> +++ b/drivers/usb/host/ohci-at91.c
> @@ -223,7 +223,7 @@ static void __devexit usb_hcd_at91_remove(struct usb_hcd *hcd,
> /*-------------------------------------------------------------------------*/
>
> static int __devinit
> -ohci_at91_start (struct usb_hcd *hcd)
> +ohci_at91_reset (struct usb_hcd *hcd)
> {
> struct at91_usbh_data *board = hcd->self.controller->platform_data;
> struct ohci_hcd *ohci = hcd_to_ohci (hcd);
> @@ -233,6 +233,14 @@ ohci_at91_start (struct usb_hcd *hcd)
> return ret;
>
> ohci->num_ports = board->ports;
> + return 0;
> +}
> +
> +static int __devinit
> +ohci_at91_start (struct usb_hcd *hcd)
> +{
> + struct ohci_hcd *ohci = hcd_to_ohci (hcd);
> + int ret;
>
> if ((ret = ohci_run(ohci)) < 0) {
> err("can't start %s", hcd->self.bus_name);
> @@ -418,6 +426,7 @@ static const struct hc_driver ohci_at91_hc_driver = {
> /*
> * basic lifecycle operations
> */
> + .reset = ohci_at91_reset,
> .start = ohci_at91_start,
> .stop = ohci_stop,
> .shutdown = ohci_shutdown,

2012-05-10 07:39:04

by Nicolas Ferre

[permalink] [raw]
Subject: Re: [PATCH] USB: ohci-at91: add a reset function to fix race condition

On 05/09/2012 07:22 PM, Sergei Shtylyov :
> Hello.
>
> On 09-05-2012 12:48, Nicolas Ferre wrote:
>
>> A possible race condition appears because we are not initializing
>> the ohci->regs before calling usb_hcd_request_irqs().
>> We move the call to ohci_init() in hcd->driver->reset() instead of
>> hcd->driver->start() to fix this.
>> This was experienced when we share the same IRQ line between OHCI and
>> EHCI
>> controllers.
>
>> Signed-off-by: Nicolas Ferre<[email protected]>
>> Tested-by: Christian Eggers<[email protected]>
>> Cc: stable<[email protected]>
>> ---
>> drivers/usb/host/ohci-at91.c | 11 ++++++++++-
>> 1 file changed, 10 insertions(+), 1 deletion(-)
>
>> diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
>> index 13ebeca..55d3d64 100644
>> --- a/drivers/usb/host/ohci-at91.c
>> +++ b/drivers/usb/host/ohci-at91.c
>> @@ -223,7 +223,7 @@ static void __devexit usb_hcd_at91_remove(struct
>> usb_hcd *hcd,
>>
>> /*-------------------------------------------------------------------------*/
>>
>>
>> static int __devinit
>> -ohci_at91_start (struct usb_hcd *hcd)
>> +ohci_at91_reset (struct usb_hcd *hcd)
>
> Have you run the patch thru scripts/checkpatch.pl? There should be no
> space between function name and '('.
>
>> {
>> struct at91_usbh_data *board =
>> hcd->self.controller->platform_data;
>> struct ohci_hcd *ohci = hcd_to_ohci (hcd);
>> @@ -233,6 +233,14 @@ ohci_at91_start (struct usb_hcd *hcd)
>> return ret;
>>
>> ohci->num_ports = board->ports;
>> + return 0;
>> +}
>> +
>> +static int __devinit
>> +ohci_at91_start (struct usb_hcd *hcd)
>
> Same here.
>
>> +{
>> + struct ohci_hcd *ohci = hcd_to_ohci (hcd);
>
> And here.

Yes, I have run checkpatch.pl. But I also know that I have to conform to
existing code and the history of the file that I am touching.
This file is using this convention as well as
drivers/usb/host/ohci-hcd.c and several others dealing with USB. So I
kept this style in my patch.

Best regards,
--
Nicolas Ferre