From f1b3ee789f4b7a41ad93ff42d4efbae607622ae7 Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Tue, 30 Mar 2021 14:26:28 +0900 Subject: [PATCH 1/2] ASoC: soc-core: add comment for rtd freeing We don't need to mind freeing for rtd, because it was created from devm_kzalloc(dev, xxx) which is rtd->dev. This means, if rtd->dev was freed, rtd will be also freed automatically. soc_new_pcm_runtime(...) { ... rtd = devm_kzalloc(dev, ...); rtd->dev = dev; ... } This explanation was missing at soc_free_pcm_runtime() comment. This patch indicates it. Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/87sg4dxldn.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/soc-core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 522bae73640a..88694746dc11 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -413,6 +413,14 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd) * it is alloced *before* rtd. * see * soc_new_pcm_runtime() + * + * We don't need to mind freeing for rtd, + * because it was created from dev (= rtd->dev) + * see + * soc_new_pcm_runtime() + * + * rtd = devm_kzalloc(dev, ...); + * rtd->dev = dev */ device_unregister(rtd->dev); } From 5fa7553dcd83c576c589fd3e617dc599e4fe15dc Mon Sep 17 00:00:00 2001 From: Kuninori Morimoto Date: Tue, 30 Mar 2021 14:26:38 +0900 Subject: [PATCH 2/2] ASoC: soc-core: use device_unregister() if rtd allocation failed Because soc_free_pcm_runtime(rtd) checks rtd pointer and freeing rtd->xxx, it doesn't work correctly in case of rtd allocation failed. We need to use device_unregister(dev) in such case. This patch fixup it. Signed-off-by: Kuninori Morimoto Link: https://lore.kernel.org/r/87r1jxxldd.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown --- sound/soc/soc-core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 88694746dc11..236e075b9e57 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -470,8 +470,10 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime( dai_link->num_codecs + dai_link->num_platforms), GFP_KERNEL); - if (!rtd) - goto free_rtd; + if (!rtd) { + device_unregister(dev); + return NULL; + } rtd->dev = dev; INIT_LIST_HEAD(&rtd->list);