ASoC: mediatek: clear afe->regmap on devm_regmap_init_mmio() error
Subsystems (3)
cover ASoC: mediatek: clear afe->regmap on devm_regmap_init_mmio() error
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(+)
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 1/2 ASoC: mediatek: mt8196: clear afe->regmap on devm_regmap_init_mmio() error
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.
--- sound/soc/mediatek/mt8196/mt8196-afe-pcm.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/mediatek/mt8196/mt8196-afe-pcm.c +1 -0
@@ -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; }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
PATCH 2/2 ASoC: mediatek: mt8189: clear afe->regmap on devm_regmap_init_mmio() error
In reply to Elkin CruzWhen 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.
--- sound/soc/mediatek/mt8189/mt8189-afe-pcm.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/mediatek/mt8189/mt8189-afe-pcm.c +1 -0
@@ -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; }
Signature · 1 line
2.56.1.750.gf70dc682cf-goog
[email protected]
AI reviewRe: [PATCH 2/2] ASoC: mediatek: mt8189: clear afe->regmap on devm_regmap_init_mmio() error
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…
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 <[email protected]>
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.
sound/soc/mediatek/mt8189/mt8189-afe-pcm.c static int mt8189_afe_pcm_dev_probe(struct platform_device *pdev) · line 2568
Quoted 11 lines
sound/soc/mediatek/mt8189/mt8189-afe-pcm.c +1
-0@@ -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
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Mark Brown
maintainerQuoted 8 lines · Elkin Cruz
ASoC: mediatek: clear
afe->regmapondevm_regmap_init_mmio()errorI 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).
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.5
Thanks!
[1/2] ASoC: mediatek: mt8196: clear afe->regmap on devm_regmap_init_mmio() error
https://git.kernel.org/broonie/sound/c/4d5ed6cd0a14 [2/2] ASoC: mediatek: mt8189: clear afe->regmap on devm_regmap_init_mmio() error https://git.kernel.org/broonie/sound/c/18246650ab69
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