[PATCH 3/3] USB: Gadget: Webcam: Free resources in config unbind

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Resources allocated during configuration 'bind' should be
freed in configuration 'unbind'.

Signed-off-by: Jassi Brar <jaswinder.singh@xxxxxxxxxx>
---
 drivers/usb/gadget/f_uvc.c  |   12 ++++++++++--
 drivers/usb/gadget/webcam.c |    1 +
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/f_uvc.c b/drivers/usb/gadget/f_uvc.c
index c847b9e..ee3ed4f 100644
--- a/drivers/usb/gadget/f_uvc.c
+++ b/drivers/usb/gadget/f_uvc.c
@@ -481,8 +481,6 @@ uvc_function_unbind(struct usb_configuration *c, struct usb_function *f)
 
 	kfree(f->descriptors);
 	kfree(f->hs_descriptors);
-
-	kfree(uvc);
 }
 
 static int __init
@@ -648,6 +646,8 @@ uvc_bind_config(struct usb_configuration *c,
 	ret = usb_add_function(c, &uvc->func);
 	if (ret)
 		kfree(uvc);
+	else
+		c->data = (void *)uvc;
 
 	return ret;
 
@@ -656,6 +656,14 @@ error:
 	return ret;
 }
 
+void __exit uvc_unbind_config(struct usb_configuration *c)
+{
+	struct uvc_device *uvc = c->data;
+
+	kfree(uvc);
+	c->data = NULL;
+}
+
 module_param_named(trace, uvc_gadget_trace_param, uint, S_IRUGO|S_IWUSR);
 MODULE_PARM_DESC(trace, "Trace level bitmask");
 
diff --git a/drivers/usb/gadget/webcam.c b/drivers/usb/gadget/webcam.c
index a5a0fdb..c3ffb3d 100644
--- a/drivers/usb/gadget/webcam.c
+++ b/drivers/usb/gadget/webcam.c
@@ -317,6 +317,7 @@ webcam_config_bind(struct usb_configuration *c)
 
 static struct usb_configuration webcam_config_driver = {
 	.label			= webcam_config_label,
+	.unbind			= uvc_unbind_config,
 	.bConfigurationValue	= 1,
 	.iConfiguration		= 0, /* dynamic */
 	.bmAttributes		= USB_CONFIG_ATT_SELFPOWER,
-- 
1.7.4.1

--
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


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux