public inbox for linux-arm-kernel@lists.infradead.org 
 help / color / mirror / Atom feed
* [PATCH 0/2] ASoC: mediatek: mt8183: Fix probe resource cleanup
@ 2026-05-27 13:41 Cássio Gabriel
  2026-05-27 13:41 ` [PATCH 1/2] ASoC: mediatek: mt8183: Release reserved memory on cleanup Cássio Gabriel
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Cássio Gabriel @ 2026-05-27 13:41 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Takashi Iwai, Jaroslav Kysela,
	Matthias Brugger, AngeloGioacchino Del Regno, Chen-Yu Tsai,
	Shunli Wang
  Cc: linux-sound, linux-kernel, linux-arm-kernel, linux-mediatek,
	notify, Cássio Gabriel, stable

The MT8183 AFE probe has two cleanup gaps that match issues
recently fixed in newer MediaTek AFE drivers.

First, reserved memory assigned with of_reserved_mem_device_init()
is never released on driver removal or later probe failures.

Second, the probe-time runtime PM resume used before reinitializing
the regmap cache is unchecked, and a regmap_reinit_cache() failure
skips the temporary PM put.

Fix both issues with a devm reserved-memory release action and
checked runtime PM resume handling.

Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail•com>
---
Cássio Gabriel (2):
      ASoC: mediatek: mt8183: Release reserved memory on cleanup
      ASoC: mediatek: mt8183: Check runtime resume during probe

 sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
---
base-commit: 8cd773d4f8235aaf0b04927b3c9d2d0326def09b
change-id: 20260525-asoc-mt8183-probe-cleanup-eff58c2d4715

Best regards,
--  
Cássio Gabriel <cassiogabrielcontato@gmail•com>



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] ASoC: mediatek: mt8183: Release reserved memory on cleanup
  2026-05-27 13:41 [PATCH 0/2] ASoC: mediatek: mt8183: Fix probe resource cleanup Cássio Gabriel
@ 2026-05-27 13:41 ` Cássio Gabriel
  2026-05-27 13:41 ` [PATCH 2/2] ASoC: mediatek: mt8183: Check runtime resume during probe Cássio Gabriel
  2026-06-02 15:11 ` [PATCH 0/2] ASoC: mediatek: mt8183: Fix probe resource cleanup Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Cássio Gabriel @ 2026-05-27 13:41 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Takashi Iwai, Jaroslav Kysela,
	Matthias Brugger, AngeloGioacchino Del Regno, Chen-Yu Tsai,
	Shunli Wang
  Cc: linux-sound, linux-kernel, linux-arm-kernel, linux-mediatek,
	notify, Cássio Gabriel, stable

The MT8183 AFE probe can assign reserved memory with
of_reserved_mem_device_init(), but the assignment is never released on
driver removal or later probe failures.

Register a devm cleanup action so the reserved memory assignment is
released consistently, matching newer Mediatek AFE drivers.

Fixes: ec4a10ca4a68 ("ASoC: mediatek: use reserved memory or enable buffer pre-allocation")
Cc: stable@vger•kernel.org
Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail•com>
---
 sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
index a7fef772760a..49a69728fd72 100644
--- a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
+++ b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
@@ -766,6 +766,11 @@ static const dai_register_cb dai_register_cbs[] = {
 	mt8183_dai_memif_register,
 };
 
+static void mt8183_afe_release_reserved_mem(void *data)
+{
+	of_reserved_mem_device_release(data);
+}
+
 static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev)
 {
 	struct mtk_base_afe *afe;
@@ -794,6 +799,12 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev)
 	if (ret) {
 		dev_info(dev, "no reserved memory found, pre-allocating buffers instead\n");
 		afe->preallocate_buffers = true;
+	} else {
+		ret = devm_add_action_or_reset(dev,
+					       mt8183_afe_release_reserved_mem,
+					       dev);
+		if (ret)
+			return ret;
 	}
 
 	/* initial audio related clock */

-- 
2.54.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] ASoC: mediatek: mt8183: Check runtime resume during probe
  2026-05-27 13:41 [PATCH 0/2] ASoC: mediatek: mt8183: Fix probe resource cleanup Cássio Gabriel
  2026-05-27 13:41 ` [PATCH 1/2] ASoC: mediatek: mt8183: Release reserved memory on cleanup Cássio Gabriel
@ 2026-05-27 13:41 ` Cássio Gabriel
  2026-06-02 15:11 ` [PATCH 0/2] ASoC: mediatek: mt8183: Fix probe resource cleanup Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Cássio Gabriel @ 2026-05-27 13:41 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Takashi Iwai, Jaroslav Kysela,
	Matthias Brugger, AngeloGioacchino Del Regno, Chen-Yu Tsai,
	Shunli Wang
  Cc: linux-sound, linux-kernel, linux-arm-kernel, linux-mediatek,
	notify, Cássio Gabriel, stable

The MT8183 AFE probe uses pm_runtime_get_sync() before reading hardware
defaults into the regmap cache, but does not check whether runtime resume
failed. If regmap_reinit_cache() then fails, the temporary runtime PM
usage count is also not released.

Use pm_runtime_resume_and_get() so resume failures abort probe without
leaking a usage count, and release the temporary reference before
handling the regmap cache result.

Fixes: a94aec035a12 ("ASoC: mediatek: mt8183: add platform driver")
Cc: stable@vger•kernel.org
Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail•com>
---
 sound/soc/mediatek/mt8183/mt8183-afe-pcm.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
index 49a69728fd72..2634699534db 100644
--- a/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
+++ b/sound/soc/mediatek/mt8183/mt8183-afe-pcm.c
@@ -844,17 +844,21 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev)
 
 	/* enable clock for regcache get default value from hw */
 	afe_priv->pm_runtime_bypass_reg_ctl = true;
-	pm_runtime_get_sync(dev);
-
-	ret = regmap_reinit_cache(afe->regmap, &mt8183_afe_regmap_config);
+	ret = pm_runtime_resume_and_get(dev);
 	if (ret) {
-		dev_err(dev, "regmap_reinit_cache fail, ret %d\n", ret);
+		afe_priv->pm_runtime_bypass_reg_ctl = false;
 		goto err_pm_disable;
 	}
 
+	ret = regmap_reinit_cache(afe->regmap, &mt8183_afe_regmap_config);
 	pm_runtime_put_sync(dev);
 	afe_priv->pm_runtime_bypass_reg_ctl = false;
 
+	if (ret) {
+		dev_err(dev, "regmap_reinit_cache fail, ret %d\n", ret);
+		goto err_pm_disable;
+	}
+
 	regcache_cache_only(afe->regmap, true);
 	regcache_mark_dirty(afe->regmap);
 

-- 
2.54.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] ASoC: mediatek: mt8183: Fix probe resource cleanup
  2026-05-27 13:41 [PATCH 0/2] ASoC: mediatek: mt8183: Fix probe resource cleanup Cássio Gabriel
  2026-05-27 13:41 ` [PATCH 1/2] ASoC: mediatek: mt8183: Release reserved memory on cleanup Cássio Gabriel
  2026-05-27 13:41 ` [PATCH 2/2] ASoC: mediatek: mt8183: Check runtime resume during probe Cássio Gabriel
@ 2026-06-02 15:11 ` Mark Brown
  2 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2026-06-02 15:11 UTC (permalink / raw)
  To: Liam Girdwood, Takashi Iwai, Jaroslav Kysela, Matthias Brugger,
	AngeloGioacchino Del Regno, Chen-Yu Tsai, Shunli Wang,
	Cássio Gabriel
  Cc: linux-sound, linux-kernel, linux-arm-kernel, linux-mediatek,
	notify, stable

On Wed, 27 May 2026 10:41:47 -0300, Cássio Gabriel wrote:
> ASoC: mediatek: mt8183: Fix probe resource cleanup
> 
> The MT8183 AFE probe has two cleanup gaps that match issues
> recently fixed in newer MediaTek AFE drivers.
> 
> First, reserved memory assigned with of_reserved_mem_device_init()
> is never released on driver removal or later probe failures.
> 
> [...]

Applied to

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

Thanks!

[1/2] ASoC: mediatek: mt8183: Release reserved memory on cleanup
      https://git.kernel.org/broonie/sound/c/bee65e00c092
[2/2] ASoC: mediatek: mt8183: Check runtime resume during probe
      https://git.kernel.org/broonie/sound/c/f0334fbfd107

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-06-03  7:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-27 13:41 [PATCH 0/2] ASoC: mediatek: mt8183: Fix probe resource cleanup Cássio Gabriel
2026-05-27 13:41 ` [PATCH 1/2] ASoC: mediatek: mt8183: Release reserved memory on cleanup Cássio Gabriel
2026-05-27 13:41 ` [PATCH 2/2] ASoC: mediatek: mt8183: Check runtime resume during probe Cássio Gabriel
2026-06-02 15:11 ` [PATCH 0/2] ASoC: mediatek: mt8183: Fix probe resource cleanup Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox