Skip to contentSkip to conversation

ASoC: soc-core: tidyup error handling for rtd

PATCH In review Kuninori Morimoto 2 participants 4 messages Mar 30, 2021 – Apr 1, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover ASoC: soc-core: tidyup error handling for rtd

Hi Mark

These are small clanup patches for soc-core.
[1/2] patch adds missing explanation, and
[2/2] patch fixup error handling of rtd.

Kuninori Morimoto (2):
ASoC: soc-core: add comment for rtd freeing
ASoC: soc-core: use device_unregister() if rtd allocation failed

 sound/soc/soc-core.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 ASoC: soc-core: add comment for rtd freeing

From: Kuninori Morimoto <[email protected]>

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.

---
 sound/soc/soc-core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
sound/soc/soc-core.c +8 -0
index 4d7e0d8f7269..e71aa1c92e66 100644
@@ -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);
 }
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 ASoC: soc-core: use device_unregister() if rtd allocation failed

In reply to Kuninori Morimoto

From: Kuninori Morimoto <[email protected]>

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.

---
 sound/soc/soc-core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
sound/soc/soc-core.c +4 -2
index e71aa1c92e66..92d1d9240d4d 100644
@@ -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);
Signature · 1 line
2.25.1
maintainer
#3 lore raw
In reply to Kuninori Morimoto
Quoted 9 lines · Kuninori Morimoto

These are small clanup patches for soc-core.
[1/2] patch adds missing explanation, and
[2/2] patch fixup error handling of rtd.

Kuninori Morimoto (2):
ASoC: soc-core: add comment for rtd freeing
ASoC: soc-core: use device_unregister() if rtd allocation failed

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/2] ASoC: soc-core: add comment for rtd freeing

      commit: f1b3ee789f4b7a41ad93ff42d4efbae607622ae7
[2/2] ASoC: soc-core: use device_unregister() if rtd allocation failed
      commit: 5fa7553dcd83c576c589fd3e617dc599e4fe15dc

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark