diff mbox

usb: gadget: composite: Correct recovery path for register

Message ID 1455645559-23552-1-git-send-email-semen.protsenko@linaro.org
State Accepted
Commit 8038f6d2881d58f5322109a2f5ec2de5aaa6fc30
Headers show

Commit Message

Sam Protsenko Feb. 16, 2016, 5:59 p.m. UTC
From: Sam Protsenko <semen.protsenko@linaro.org>


In case when usb_composite_register() failed once (for whatever reason),
it will fail further even if all conditions are correct. Example:

    => fastboot 2
    Invalid Controller Index
    couldn't find an available UDC
    g_dnl_register: failed!, error: -19
    exit not allowed from main input shell.

    => fastboot 0
    g_dnl_register: failed!, error: -22
    exit not allowed from main input shell.

Despite that 0 is correct index for USB controller, "fastboot 0" command
will fail, because "composite" structure wasn't cleared properly on
previous fail (on "fastboot 2" command).

This patch fixes that erroneous behavior, allowing us to use composite
even after previous failure.

Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>

---
 drivers/usb/gadget/composite.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

-- 
2.7.0

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Comments

Sam Protsenko Feb. 19, 2016, 7:34 p.m. UTC | #1
+ Praneeth Bajjuri
+ Tom Rini
+ Rob Herring

On Tue, Feb 16, 2016 at 7:59 PM, Semen Protsenko
<semen.protsenko@linaro.org> wrote:
> From: Sam Protsenko <semen.protsenko@linaro.org>

>

> In case when usb_composite_register() failed once (for whatever reason),

> it will fail further even if all conditions are correct. Example:

>

>     => fastboot 2

>     Invalid Controller Index

>     couldn't find an available UDC

>     g_dnl_register: failed!, error: -19

>     exit not allowed from main input shell.

>

>     => fastboot 0

>     g_dnl_register: failed!, error: -22

>     exit not allowed from main input shell.

>

> Despite that 0 is correct index for USB controller, "fastboot 0" command

> will fail, because "composite" structure wasn't cleared properly on

> previous fail (on "fastboot 2" command).

>

> This patch fixes that erroneous behavior, allowing us to use composite

> even after previous failure.

>

> Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>

> ---

>  drivers/usb/gadget/composite.c | 8 +++++++-

>  1 file changed, 7 insertions(+), 1 deletion(-)

>

> diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c

> index 60f9272..d0ee784 100644

> --- a/drivers/usb/gadget/composite.c

> +++ b/drivers/usb/gadget/composite.c

> @@ -1077,6 +1077,8 @@ static struct usb_gadget_driver composite_driver = {

>   */

>  int usb_composite_register(struct usb_composite_driver *driver)

>  {

> +       int res;

> +

>         if (!driver || !driver->dev || !driver->bind || composite)

>                 return -EINVAL;

>

> @@ -1084,7 +1086,11 @@ int usb_composite_register(struct usb_composite_driver *driver)

>                 driver->name = "composite";

>         composite = driver;

>

> -       return usb_gadget_register_driver(&composite_driver);

> +       res = usb_gadget_register_driver(&composite_driver);

> +       if (res != 0)

> +               composite = NULL;

> +

> +       return res;

>  }

>

>  /**

> --

> 2.7.0

>

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
Sam Protsenko Feb. 26, 2016, 7:43 p.m. UTC | #2
On Fri, Feb 19, 2016 at 9:34 PM, Sam Protsenko
<semen.protsenko@linaro.org> wrote:
> + Praneeth Bajjuri

> + Tom Rini

> + Rob Herring

>

> On Tue, Feb 16, 2016 at 7:59 PM, Semen Protsenko

> <semen.protsenko@linaro.org> wrote:

>> From: Sam Protsenko <semen.protsenko@linaro.org>

>>

>> In case when usb_composite_register() failed once (for whatever reason),

>> it will fail further even if all conditions are correct. Example:

>>

>>     => fastboot 2

>>     Invalid Controller Index

>>     couldn't find an available UDC

>>     g_dnl_register: failed!, error: -19

>>     exit not allowed from main input shell.

>>

>>     => fastboot 0

>>     g_dnl_register: failed!, error: -22

>>     exit not allowed from main input shell.

>>

>> Despite that 0 is correct index for USB controller, "fastboot 0" command

>> will fail, because "composite" structure wasn't cleared properly on

>> previous fail (on "fastboot 2" command).

>>

>> This patch fixes that erroneous behavior, allowing us to use composite

>> even after previous failure.

>>

>> Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org>

>> ---

>>  drivers/usb/gadget/composite.c | 8 +++++++-

>>  1 file changed, 7 insertions(+), 1 deletion(-)

>>

>> diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c

>> index 60f9272..d0ee784 100644

>> --- a/drivers/usb/gadget/composite.c

>> +++ b/drivers/usb/gadget/composite.c

>> @@ -1077,6 +1077,8 @@ static struct usb_gadget_driver composite_driver = {

>>   */

>>  int usb_composite_register(struct usb_composite_driver *driver)

>>  {

>> +       int res;

>> +

>>         if (!driver || !driver->dev || !driver->bind || composite)

>>                 return -EINVAL;

>>

>> @@ -1084,7 +1086,11 @@ int usb_composite_register(struct usb_composite_driver *driver)

>>                 driver->name = "composite";

>>         composite = driver;

>>

>> -       return usb_gadget_register_driver(&composite_driver);

>> +       res = usb_gadget_register_driver(&composite_driver);

>> +       if (res != 0)

>> +               composite = NULL;

>> +

>> +       return res;

>>  }

>>

>>  /**

>> --

>> 2.7.0

>>


bump
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot
diff mbox

Patch

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 60f9272..d0ee784 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1077,6 +1077,8 @@  static struct usb_gadget_driver composite_driver = {
  */
 int usb_composite_register(struct usb_composite_driver *driver)
 {
+	int res;
+
 	if (!driver || !driver->dev || !driver->bind || composite)
 		return -EINVAL;
 
@@ -1084,7 +1086,11 @@  int usb_composite_register(struct usb_composite_driver *driver)
 		driver->name = "composite";
 	composite = driver;
 
-	return usb_gadget_register_driver(&composite_driver);
+	res = usb_gadget_register_driver(&composite_driver);
+	if (res != 0)
+		composite = NULL;
+
+	return res;
 }
 
 /**