diff mbox

[2/3] USB: Gadget: Zero: Free resources in config unbind

Message ID 1308945905-682-1-git-send-email-jaswinder.singh@linaro.org
State New
Headers show

Commit Message

Jassi Brar June 24, 2011, 8:05 p.m. UTC
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(-)

Comments

Jassi Brar June 24, 2011, 8:14 p.m. UTC | #1
On 25 June 2011 01:35, Jassi Brar <jaswinder.singh@linaro.org> wrote:

> +static void __exit loopback_unbind_config(struct usb_configuration *c)
> +{
> +       struct f_loopback *loop = c->data;
> +
> +       kfree(loop)

Sorry, I posted penultimate version of the patch. Just a semicolon is
missing here.

> +       c->data = NULL;
> +}
> +
diff mbox

Patch

diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c
index b37960f..932f38d 100644
--- a/drivers/usb/gadget/f_loopback.c
+++ b/drivers/usb/gadget/f_loopback.c
@@ -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 */
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
index e403a53..9ab0bde 100644
--- a/drivers/usb/gadget/f_sourcesink.c
+++ b/drivers/usb/gadget/f_sourcesink.c
@@ -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,