usb: gadget: audio: Use container_of to free audio_dev
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>
Tue, 22 Jul 2014 17:58:29 +0000 (19:58 +0200)
committerFelipe Balbi <balbi@ti.com>
Wed, 20 Aug 2014 19:04:02 +0000 (14:04 -0500)
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().

Tested-by: Sebastian Reimers <sebastian.reimers@googlemail.com>
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
drivers/usb/gadget/function/f_uac2.c
drivers/usb/gadget/legacy/audio.c

index 3ed89ec..9161561 100644 (file)
@@ -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;
-}
index 6eb695e..3c23283 100644 (file)
@@ -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
 };
 
 /*-------------------------------------------------------------------------*/