@@ -181,12 +181,6 @@ autoconf_fail:
return 0;
}
-static void
-loopback_unbind(struct usb_configuration *c, struct usb_function *f)
-{
- kfree(func_to_loop(f));
-}
-
static void loopback_complete(struct usb_ep *ep, struct usb_request *req)
{
struct f_loopback *loop = ep->driver_data;
@@ -336,19 +330,30 @@ static int __init loopback_bind_config(struct usb_configuration *c)
loop->function.name = "loopback";
loop->function.descriptors = fs_loopback_descs;
loop->function.bind = loopback_bind;
- loop->function.unbind = loopback_unbind;
loop->function.set_alt = loopback_set_alt;
loop->function.disable = loopback_disable;
status = usb_add_function(c, &loop->function);
if (status)
kfree(loop);
+ else
+ c->data = (void *)loop;
+
return status;
}
+static void __exit loopback_unbind_config(struct usb_configuration *c)
+{
+ struct f_loopback *loop = c->data;
+
+ kfree(loop)
+ c->data = NULL;
+}
+
static struct usb_configuration loopback_driver = {
.label = "loopback",
.strings = loopback_strings,
+ .unbind = loopback_unbind_config,
.bConfigurationValue = 2,
.bmAttributes = USB_CONFIG_ATT_SELFPOWER,
/* .iConfiguration = DYNAMIC */
@@ -193,12 +193,6 @@ autoconf_fail:
return 0;
}
-static void
-sourcesink_unbind(struct usb_configuration *c, struct usb_function *f)
-{
- kfree(func_to_ss(f));
-}
-
/* optionally require specific source/sink data patterns */
static int check_read_data(struct f_sourcesink *ss, struct usb_request *req)
{
@@ -416,16 +410,25 @@ static int __init sourcesink_bind_config(struct usb_configuration *c)
ss->function.name = "source/sink";
ss->function.descriptors = fs_source_sink_descs;
ss->function.bind = sourcesink_bind;
- ss->function.unbind = sourcesink_unbind;
ss->function.set_alt = sourcesink_set_alt;
ss->function.disable = sourcesink_disable;
status = usb_add_function(c, &ss->function);
if (status)
kfree(ss);
+ else
+ c->data = (void *)ss;
return status;
}
+static void __exit sourcesink_unbind_config(struct usb_configuration *c)
+{
+ struct f_sourcesink *ss = c->data;
+
+ kfree(ss);
+ c->data = NULL;
+}
+
static int sourcesink_setup(struct usb_configuration *c,
const struct usb_ctrlrequest *ctrl)
{
@@ -498,6 +501,7 @@ unknown:
static struct usb_configuration sourcesink_driver = {
.label = "source/sink",
.strings = sourcesink_strings,
+ .unbind = sourcesink_unbind_config,
.setup = sourcesink_setup,
.bConfigurationValue = 3,
.bmAttributes = USB_CONFIG_ATT_SELFPOWER,
Resources allocated during configuration 'bind' should be freed in configuration 'unbind'. Signed-off-by: Jassi Brar <jaswinder.singh@linaro.org> --- drivers/usb/gadget/f_loopback.c | 19 ++++++++++++------- drivers/usb/gadget/f_sourcesink.c | 18 +++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-)