]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/usb/gadget/function/f_mass_storage.c
usb: gadget: f_mass_storage: stop thread in bind failure case
[karo-tx-linux.git] / drivers / usb / gadget / function / f_mass_storage.c
index a2291946ca7e36f6957b5c6070ff031f59c09f46..f94a8e2e9b60c05ea837cd9db3055825336d939a 100644 (file)
@@ -3081,7 +3081,7 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
        /* New interface */
        i = usb_interface_id(c, f);
        if (i < 0)
-               return i;
+               goto fail;
        fsg_intf_desc.bInterfaceNumber = i;
        fsg->interface_number = i;
 
@@ -3124,7 +3124,14 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
 
 autoconf_fail:
        ERROR(fsg, "unable to autoconfigure all endpoints\n");
-       return -ENOTSUPP;
+       i = -ENOTSUPP;
+fail:
+       /* terminate the thread */
+       if (fsg->common->state != FSG_STATE_TERMINATED) {
+               raise_exception(fsg->common, FSG_STATE_EXIT);
+               wait_for_completion(&fsg->common->thread_notifier);
+       }
+       return i;
 }
 
 /****************************** ALLOCATE FUNCTION *************************/