Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[firefly-linux-kernel-4.4.55.git] / drivers / usb / gadget / function / f_fs.c
index 6e7be91e6097cf0cfb4d6106decc141aeb8a5eb3..adc6d52efa4639387c30bcde2ae7cee95331b1bc 100644 (file)
@@ -2897,11 +2897,17 @@ static int ffs_func_bind(struct usb_configuration *c,
                         struct usb_function *f)
 {
        struct f_fs_opts *ffs_opts = ffs_do_functionfs_bind(f, c);
+       struct ffs_function *func = ffs_func_from_usb(f);
+       int ret;
 
        if (IS_ERR(ffs_opts))
                return PTR_ERR(ffs_opts);
 
-       return _ffs_func_bind(c, f);
+       ret = _ffs_func_bind(c, f);
+       if (ret && !--ffs_opts->refcnt)
+               functionfs_unbind(func->ffs);
+
+       return ret;
 }