When an error occurs adding a platform device there is a risk of an infinite 
loop.
If more than one platform device was added i will remain >= than 0. The 
intention seems
to clean up all the different already added platform devices before the failure 
occurs,
so fixed the code to actually do so. We decrement first because the adding at 
the current
index of i is the one that failed.

Found with coverity : CID 751073

Signed-off-by: Philippe De Swert <philippe.desw...@jollamobile.com>
---
 drivers/usb/gadget/dummy_hcd.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index c588e8e..5c506fb 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -2705,9 +2705,10 @@ static int __init init(void)
        for (i = 0; i < mod_data.num; i++) {
                retval = platform_device_add(the_udc_pdev[i]);
                if (retval < 0) {
-                       i--;
-                       while (i >= 0)
+                       while (i >= 0) {
+                               i--;
                                platform_device_del(the_udc_pdev[i]);
+                       }
                        goto err_add_udc;
                }
        }
-- 
1.8.1.2

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to