[PATCH 01/15] usb: gadget: audio: Use container_of to free audio_dev

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

 



Eliminate static struct *agdev_g from f_uac2.c.
It is used for freeing its memory, but the same address can be found
by calling container_of in afunc_unbind(). This implies eliminating
uac2_unbind_config(). The audio_config_driver in audio.c does not have
its unbind method any more. It has been used only when uac2 is used,
so uac2 itself can handle unbinding in afunc_unbind().

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@xxxxxxxxxxx>
---
 drivers/usb/gadget/function/f_uac2.c | 35 ++++++++++++++---------------------
 drivers/usb/gadget/legacy/audio.c    |  3 ---
 2 files changed, 14 insertions(+), 24 deletions(-)

diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
index 3ed89ec..9161561 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -149,8 +149,6 @@ struct audio_dev {
 	struct snd_uac2_chip uac2;
 };
 
-static struct audio_dev *agdev_g;
-
 static inline
 struct audio_dev *func_to_agdev(struct usb_function *f)
 {
@@ -1039,6 +1037,7 @@ afunc_unbind(struct usb_configuration *cfg, struct usb_function *fn)
 		agdev->in_ep->driver_data = NULL;
 	if (agdev->out_ep)
 		agdev->out_ep->driver_data = NULL;
+	kfree(agdev);
 }
 
 static int
@@ -1311,10 +1310,11 @@ afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr)
 
 static int audio_bind_config(struct usb_configuration *cfg)
 {
+	struct audio_dev *agdev;
 	int res;
 
-	agdev_g = kzalloc(sizeof *agdev_g, GFP_KERNEL);
-	if (agdev_g == NULL)
+	agdev = kzalloc(sizeof(*agdev), GFP_KERNEL);
+	if (agdev == NULL)
 		return -ENOMEM;
 
 	res = usb_string_ids_tab(cfg->cdev, strings_fn);
@@ -1333,14 +1333,14 @@ static int audio_bind_config(struct usb_configuration *cfg)
 	std_as_in_if0_desc.iInterface = strings_fn[STR_AS_IN_ALT0].id;
 	std_as_in_if1_desc.iInterface = strings_fn[STR_AS_IN_ALT1].id;
 
-	agdev_g->func.name = "uac2_func";
-	agdev_g->func.strings = fn_strings;
-	agdev_g->func.bind = afunc_bind;
-	agdev_g->func.unbind = afunc_unbind;
-	agdev_g->func.set_alt = afunc_set_alt;
-	agdev_g->func.get_alt = afunc_get_alt;
-	agdev_g->func.disable = afunc_disable;
-	agdev_g->func.setup = afunc_setup;
+	agdev->func.name = "uac2_func";
+	agdev->func.strings = fn_strings;
+	agdev->func.bind = afunc_bind;
+	agdev->func.unbind = afunc_unbind;
+	agdev->func.set_alt = afunc_set_alt;
+	agdev->func.get_alt = afunc_get_alt;
+	agdev->func.disable = afunc_disable;
+	agdev->func.setup = afunc_setup;
 
 	/* Initialize the configurable parameters */
 	usb_out_it_desc.bNrChannels = num_channels(c_chmask);
@@ -1359,16 +1359,9 @@ static int audio_bind_config(struct usb_configuration *cfg)
 	snprintf(clksrc_in, sizeof(clksrc_in), "%uHz", p_srate);
 	snprintf(clksrc_out, sizeof(clksrc_out), "%uHz", c_srate);
 
-	res = usb_add_function(cfg, &agdev_g->func);
+	res = usb_add_function(cfg, &agdev->func);
 	if (res < 0)
-		kfree(agdev_g);
+		kfree(agdev);
 
 	return res;
 }
-
-static void
-uac2_unbind_config(struct usb_configuration *cfg)
-{
-	kfree(agdev_g);
-	agdev_g = NULL;
-}
diff --git a/drivers/usb/gadget/legacy/audio.c b/drivers/usb/gadget/legacy/audio.c
index 6eb695e..3c23283 100644
--- a/drivers/usb/gadget/legacy/audio.c
+++ b/drivers/usb/gadget/legacy/audio.c
@@ -126,9 +126,6 @@ static struct usb_configuration audio_config_driver = {
 	.bConfigurationValue	= 1,
 	/* .iConfiguration = DYNAMIC */
 	.bmAttributes		= USB_CONFIG_ATT_SELFPOWER,
-#ifndef CONFIG_GADGET_UAC1
-	.unbind			= uac2_unbind_config,
-#endif
 };
 
 /*-------------------------------------------------------------------------*/
-- 
1.9.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