ASoC: soc-core: remove snd_soc_rtdcom_del_all()
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Thu, 12 Sep 2019 04:42:44 +0000 (13:42 +0900)
committerMark Brown <broonie@kernel.org>
Tue, 1 Oct 2019 11:13:37 +0000 (12:13 +0100)
If we can use devm_kzalloc(rtd->dev, xxx) for rtdcom,
we don't need to call snd_soc_rtdcom_del_all() for kfree().
This patch uses devm_kzalloc(rtd->dev, xxx) for rtdcom,
and remove snd_soc_rtdcom_del_all().

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://lore.kernel.org/r/875zlyf7ln.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/soc-core.c

index b722074..d2842a3 100644 (file)
@@ -288,28 +288,29 @@ static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd,
                        return 0;
        }
 
-       rtdcom = kmalloc(sizeof(*rtdcom), GFP_KERNEL);
+       /*
+        * created rtdcom here will be freed when rtd->dev was freed.
+        * see
+        *      soc_free_pcm_runtime() :: device_unregister(rtd->dev)
+        */
+       rtdcom = devm_kzalloc(rtd->dev, sizeof(*rtdcom), GFP_KERNEL);
        if (!rtdcom)
                return -ENOMEM;
 
        rtdcom->component = component;
        INIT_LIST_HEAD(&rtdcom->list);
 
+       /*
+        * When rtd was freed, created rtdcom here will be
+        * also freed.
+        * And we don't need to call list_del(&rtdcom->list)
+        * when freed, because rtd is also freed.
+        */
        list_add_tail(&rtdcom->list, &rtd->component_list);
 
        return 0;
 }
 
-static void snd_soc_rtdcom_del_all(struct snd_soc_pcm_runtime *rtd)
-{
-       struct snd_soc_rtdcom_list *rtdcom1, *rtdcom2;
-
-       for_each_rtdcom_safe(rtd, rtdcom1, rtdcom2)
-               kfree(rtdcom1);
-
-       INIT_LIST_HEAD(&rtd->component_list);
-}
-
 struct snd_soc_component *snd_soc_rtdcom_lookup(struct snd_soc_pcm_runtime *rtd,
                                                const char *driver_name)
 {
@@ -370,7 +371,6 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
                return;
 
        kfree(rtd->codec_dais);
-       snd_soc_rtdcom_del_all(rtd);
        list_del(&rtd->list);
 
        /*