Skip to contentSkip to conversation

ASoC: mediatek: mt8365: check suspend backup allocation

PATCH New Ruoyu Wang 1 participant 1 message Jun 6

Subsystems (3)
lore
Share & tools
lore

Ruoyu Wang

author
#0 lore raw

PATCH 1/1 ASoC: mediatek: mt8365: check suspend backup allocation

mt8365_afe_suspend() lazily allocates the register backup array and then stores register values into it. If devm_kcalloc() fails, the suspend path dereferences afe->reg_back_up in the backup loop.

Check the allocation result before using the array. Disable the main clock before returning so the error path balances the clock enable at the start of suspend.

---
 sound/soc/mediatek/mt8365/mt8365-afe-pcm.c | 4 ++++
 1 file changed, 4 insertions(+)
sound/soc/mediatek/mt8365/mt8365-afe-pcm.c +4 -0
index d01793394f225..74e4f53b31605 100644
@@ -1978,6 +1978,10 @@ static int mt8365_afe_suspend(struct device *dev)
 		afe->reg_back_up =
 			devm_kcalloc(dev, afe->reg_back_up_list_num,
 				     sizeof(unsigned int), GFP_KERNEL);
+	if (!afe->reg_back_up) {
+		mt8365_afe_disable_main_clk(afe);
+		return -ENOMEM;
+	}
 
 	for (i = 0; i < afe->reg_back_up_list_num; i++)
 		regmap_read(regmap, afe->reg_back_up_list[i],
Signature · 1 line
2.34.1