* [PATCH 0/2] ASoC: mediatek: clear afe->regmap on devm_regmap_init_mmio() error
@ 2026-11-20 19:22 Elkin Cruz
2026-11-20 19:22 ` [PATCH 1/2] ASoC: mediatek: mt8196: " Elkin Cruz
2026-11-20 19:22 ` [PATCH 2/2] ASoC: mediatek: mt8189: " Elkin Cruz
0 siblings, 2 replies; 4+ messages in thread
From: Elkin Cruz @ 2026-11-20 19:22 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-sound, linux-kernel, linux-arm-kernel, linux-mediatek, llvm,
irogers, Elkin Cruz
I am trying out a new Clang static analysis linter for ERR_PTR/NULL
handling, and it flagged this code as possibly buggy. The findings were triaged
and fixed with an AI coding assistant, then checked against linux-next (not
runtime-tested on hardware).
Thanks,
Elkin
Elkin Cruz (2):
ASoC: mediatek: mt8196: clear afe->regmap on devm_regmap_init_mmio()
error
ASoC: mediatek: mt8189: clear afe->regmap on devm_regmap_init_mmio()
error
sound/soc/mediatek/mt8189/mt8189-afe-pcm.c | 1 +
sound/soc/mediatek/mt8196/mt8196-afe-pcm.c | 1 +
2 files changed, 2 insertions(+)
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 1/2] ASoC: mediatek: mt8196: clear afe->regmap on devm_regmap_init_mmio() error
2026-11-20 19:22 [PATCH 0/2] ASoC: mediatek: clear afe->regmap on devm_regmap_init_mmio() error Elkin Cruz
@ 2026-11-20 19:22 ` Elkin Cruz
2026-11-20 19:22 ` [PATCH 2/2] ASoC: mediatek: mt8189: " Elkin Cruz
1 sibling, 0 replies; 4+ messages in thread
From: Elkin Cruz @ 2026-11-20 19:22 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-sound, linux-kernel, linux-arm-kernel, linux-mediatek, llvm,
irogers, Elkin Cruz
When devm_regmap_init_mmio() fails in mt8196_afe_pcm_dev_probe(),
afe->regmap holds an ERR_PTR() while unwinding through err_pm_put ->
pm_runtime_put_sync(), which invokes mt8196_afe_runtime_suspend().
Because mt8196_afe_runtime_suspend() only guards if (!afe->regmap), it
passes the error pointer into regcache_cache_only() and crashes.
Clear afe->regmap to NULL before jumping to err_pm_put.
Fixes: e38353138a09 ("ASoC: mediatek: mt8196: Fix probe resource cleanup")
Signed-off-by: Elkin Cruz <elkin@google.com>
---
sound/soc/mediatek/mt8196/mt8196-afe-pcm.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c b/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c
index 82b5ae91751a..3028aa82c4a8 100644
--- a/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c
+++ b/sound/soc/mediatek/mt8196/mt8196-afe-pcm.c
@@ -2450,6 +2450,7 @@ static int mt8196_afe_pcm_dev_probe(struct platform_device *pdev)
&mt8196_afe_regmap_config);
if (IS_ERR(afe->regmap)) {
ret = PTR_ERR(afe->regmap);
+ afe->regmap = NULL;
goto err_pm_put;
}
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] ASoC: mediatek: mt8189: clear afe->regmap on devm_regmap_init_mmio() error
2026-11-20 19:22 [PATCH 0/2] ASoC: mediatek: clear afe->regmap on devm_regmap_init_mmio() error Elkin Cruz
2026-11-20 19:22 ` [PATCH 1/2] ASoC: mediatek: mt8196: " Elkin Cruz
@ 2026-11-20 19:22 ` Elkin Cruz
2026-11-20 19:42 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Elkin Cruz @ 2026-11-20 19:22 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Matthias Brugger, AngeloGioacchino Del Regno
Cc: linux-sound, linux-kernel, linux-arm-kernel, linux-mediatek, llvm,
irogers, Elkin Cruz
When devm_regmap_init_mmio() fails in mt8189_afe_pcm_dev_probe(),
afe->regmap holds an ERR_PTR() while unwinding through err_pm_put ->
pm_runtime_put_sync(), which invokes mt8189_afe_runtime_suspend().
Because mt8189_afe_runtime_suspend() only checks if (!afe->regmap), the
ERR_PTR() value is passed to regmap_write() and regcache_cache_only().
Clear afe->regmap to NULL before jumping to err_pm_put.
Fixes: 5404599c3292 ("ASoC: mediatek: mt8189: Fix probe resource cleanup")
Signed-off-by: Elkin Cruz <elkin@google.com>
---
sound/soc/mediatek/mt8189/mt8189-afe-pcm.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c b/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c
index f39b01590f71..85b5be6d45ec 100644
--- a/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c
+++ b/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c
@@ -2563,6 +2563,7 @@ static int mt8189_afe_pcm_dev_probe(struct platform_device *pdev)
&mt8189_afe_regmap_config);
if (IS_ERR(afe->regmap)) {
ret = PTR_ERR(afe->regmap);
+ afe->regmap = NULL;
goto err_pm_put;
}
--
2.56.1.750.gf70dc682cf-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH 2/2] ASoC: mediatek: mt8189: clear afe->regmap on devm_regmap_init_mmio() error
2026-11-20 19:22 ` [PATCH 2/2] ASoC: mediatek: mt8189: " Elkin Cruz
@ 2026-11-20 19:42 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-20 19:42 UTC (permalink / raw)
To: Elkin Cruz; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] ASoC: mediatek: mt8189: clock disable underflow in
mt8189_afe_pcm_dev_remove() [1]
--
commit d8496ec5beb278c4f15ca503ecbd50eb2598abc9
Author: Elkin Cruz <elkin@google.com>
ASoC: mediatek: mt8189: clear afe->regmap on devm_regmap_init_mmio() error
This commit clears afe->regmap to NULL when devm_regmap_init_mmio() fails
in mt8189_afe_pcm_dev_probe() so that mt8189_afe_runtime_suspend() does
not pass an ERR_PTR() to regmap functions during error unwinding.
> diff --git a/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c b/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c
> index f39b01590f714..85b5be6d45ec6 100644
> --- a/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c
> +++ b/sound/soc/mediatek/mt8189/mt8189-afe-pcm.c
> @@ -2563,6 +2563,7 @@ static int mt8189_afe_pcm_dev_probe(struct platform_device *pdev)
> &mt8189_afe_regmap_config);
> if (IS_ERR(afe->regmap)) {
> ret = PTR_ERR(afe->regmap);
> + afe->regmap = NULL;
> goto err_pm_put;
> }
[Severity: High]
This problem wasn't introduced by this patch, but does
mt8189_afe_pcm_dev_remove() [1] underflow the clock enable counts by
disabling the AFE main and register read/write clocks after
mt8189_afe_runtime_suspend()?
sound/soc/mediatek/mt8189/mt8189-afe-pcm.c:mt8189_afe_pcm_dev_remove() {
...
if (!pm_runtime_status_suspended(dev))
mt8189_afe_runtime_suspend(dev);
mt8189_afe_disable_main_clock(afe);
/* disable afe clock */
mt8189_afe_disable_reg_rw_clk(afe);
}
mt8189_afe_runtime_suspend() already calls mt8189_afe_disable_main_clock()
and mt8189_afe_disable_reg_rw_clk(). Unconditionally disabling both
clocks a second time on device unbind corrupts the Common Clock Framework
reference counts and can shut down shared parent clocks still in use by
other peripherals.
[1] https://sashiko.dev/#/bug/linux-7209342b-8b8a-4947-a765-7c521cb675e9
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261120192237.2870582-1-elkin@google.com?part=2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-20 19:42 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 19:22 [PATCH 0/2] ASoC: mediatek: clear afe->regmap on devm_regmap_init_mmio() error Elkin Cruz
2026-11-20 19:22 ` [PATCH 1/2] ASoC: mediatek: mt8196: " Elkin Cruz
2026-11-20 19:22 ` [PATCH 2/2] ASoC: mediatek: mt8189: " Elkin Cruz
2026-11-20 19:42 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.