On Wed, 28 Aug 2013, Philippe De Swert wrote: > 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.deswert@xxxxxxxxxxxxxxx> > --- > 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; > } > } This is definitely a bug, but you should have fixed it the same way as the code 21 lines earlier. Or even better, change both of them to use this pattern: if (retval < 0) { while (--i >= 0) platform_device_del(the_udc_pdev[i]); goto err_add_udc; } Alan Stern -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html