* [PATCH v2] ASoC: mediatek: mt8365: Add check for devm_kcalloc() in mt8365_afe_suspend()
@ 2025-09-22 15:34 Guangshuo Li
2025-09-22 15:43 ` Christophe JAILLET
0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2025-09-22 15:34 UTC (permalink / raw)
To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
Matthias Brugger, AngeloGioacchino Del Regno, Guangshuo Li,
Charles Keepax, Alexandre Mergnat, linux-sound, linux-kernel,
linux-arm-kernel, linux-mediatek
Cc: stable
devm_kcalloc() may fail. mt8365_afe_suspend() uses afe->reg_back_up
unconditionally after allocation and writes afe->reg_back_up[i], which
can lead to a NULL pointer dereference under low-memory conditions.
Add a NULL check and bail out with -ENOMEM, making sure to disable the
main clock via the existing error path to keep clock state balanced.
Fixes: e1991d102bc2 ("ASoC: mediatek: mt8365: Add the AFE driver support")
Cc: stable@vger.kernel.org
---
changelog:
v2:
- Return -ENOMEM directly on allocation failure without goto/label.
- Disable the main clock before returning to keep clock state balanced.
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
sound/soc/mediatek/mt8365/mt8365-afe-pcm.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c b/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c
index 10793bbe9275..55d832e05072 100644
--- a/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c
+++ b/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c
@@ -1975,11 +1975,15 @@ static int mt8365_afe_suspend(struct device *dev)
mt8365_afe_enable_main_clk(afe);
- if (!afe->reg_back_up)
+ if (!afe->reg_back_up) {
afe->reg_back_up =
devm_kcalloc(dev, afe->reg_back_up_list_num,
- sizeof(unsigned int), GFP_KERNEL);
-
+ 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],
&afe->reg_back_up[i]);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] ASoC: mediatek: mt8365: Add check for devm_kcalloc() in mt8365_afe_suspend()
2025-09-22 15:34 [PATCH v2] ASoC: mediatek: mt8365: Add check for devm_kcalloc() in mt8365_afe_suspend() Guangshuo Li
@ 2025-09-22 15:43 ` Christophe JAILLET
0 siblings, 0 replies; 2+ messages in thread
From: Christophe JAILLET @ 2025-09-22 15:43 UTC (permalink / raw)
To: Guangshuo Li, Liam Girdwood, Mark Brown, Jaroslav Kysela,
Takashi Iwai, Matthias Brugger, AngeloGioacchino Del Regno,
Charles Keepax, Alexandre Mergnat, linux-sound, linux-kernel,
linux-arm-kernel, linux-mediatek
Cc: stable
Le 22/09/2025 à 17:34, Guangshuo Li a écrit :
> devm_kcalloc() may fail. mt8365_afe_suspend() uses afe->reg_back_up
> unconditionally after allocation and writes afe->reg_back_up[i], which
> can lead to a NULL pointer dereference under low-memory conditions.
>
> Add a NULL check and bail out with -ENOMEM, making sure to disable the
> main clock via the existing error path to keep clock state balanced.
>
> Fixes: e1991d102bc2 ("ASoC: mediatek: mt8365: Add the AFE driver support")
> Cc: stable@vger.kernel.org
> ---
> changelog:
> v2:
> - Return -ENOMEM directly on allocation failure without goto/label.
> - Disable the main clock before returning to keep clock state balanced.
>
> Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
This should be above the ---
> ---
> sound/soc/mediatek/mt8365/mt8365-afe-pcm.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c b/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c
> index 10793bbe9275..55d832e05072 100644
> --- a/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c
> +++ b/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c
> @@ -1975,11 +1975,15 @@ static int mt8365_afe_suspend(struct device *dev)
>
> mt8365_afe_enable_main_clk(afe);
>
> - if (!afe->reg_back_up)
> + if (!afe->reg_back_up) {
> afe->reg_back_up =
> devm_kcalloc(dev, afe->reg_back_up_list_num,
> - sizeof(unsigned int), GFP_KERNEL);
> -
> + sizeof(unsigned int), GFP_KERNEL);
you should not remove a space here.
CJ
> + 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],
> &afe->reg_back_up[i]);
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-09-22 15:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-22 15:34 [PATCH v2] ASoC: mediatek: mt8365: Add check for devm_kcalloc() in mt8365_afe_suspend() Guangshuo Li
2025-09-22 15:43 ` Christophe JAILLET
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox