Skip to content

Commit ba9ea6b

Browse files
committed
ASoC: mediatek: mt8183: Fix probe resource cleanup
Cássio Gabriel <cassiogabrielcontato@gmail.com> says: 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. Link: https://patch.msgid.link/20260527-asoc-mt8183-probe-cleanup-v1-0-4f4f5593c8d1@gmail.com
2 parents 0cf3489 + f0334fb commit ba9ea6b

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

sound/soc/mediatek/mt8183/mt8183-afe-pcm.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,6 +766,11 @@ static const dai_register_cb dai_register_cbs[] = {
766766
mt8183_dai_memif_register,
767767
};
768768

769+
static void mt8183_afe_release_reserved_mem(void *data)
770+
{
771+
of_reserved_mem_device_release(data);
772+
}
773+
769774
static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev)
770775
{
771776
struct mtk_base_afe *afe;
@@ -794,6 +799,12 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev)
794799
if (ret) {
795800
dev_info(dev, "no reserved memory found, pre-allocating buffers instead\n");
796801
afe->preallocate_buffers = true;
802+
} else {
803+
ret = devm_add_action_or_reset(dev,
804+
mt8183_afe_release_reserved_mem,
805+
dev);
806+
if (ret)
807+
return ret;
797808
}
798809

799810
/* initial audio related clock */
@@ -833,17 +844,21 @@ static int mt8183_afe_pcm_dev_probe(struct platform_device *pdev)
833844

834845
/* enable clock for regcache get default value from hw */
835846
afe_priv->pm_runtime_bypass_reg_ctl = true;
836-
pm_runtime_get_sync(dev);
837-
838-
ret = regmap_reinit_cache(afe->regmap, &mt8183_afe_regmap_config);
847+
ret = pm_runtime_resume_and_get(dev);
839848
if (ret) {
840-
dev_err(dev, "regmap_reinit_cache fail, ret %d\n", ret);
849+
afe_priv->pm_runtime_bypass_reg_ctl = false;
841850
goto err_pm_disable;
842851
}
843852

853+
ret = regmap_reinit_cache(afe->regmap, &mt8183_afe_regmap_config);
844854
pm_runtime_put_sync(dev);
845855
afe_priv->pm_runtime_bypass_reg_ctl = false;
846856

857+
if (ret) {
858+
dev_err(dev, "regmap_reinit_cache fail, ret %d\n", ret);
859+
goto err_pm_disable;
860+
}
861+
847862
regcache_cache_only(afe->regmap, true);
848863
regcache_mark_dirty(afe->regmap);
849864

0 commit comments

Comments
 (0)