Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] ASoC: mediatek: mt8365: Add check for devm_kcalloc() in mt8365_afe_suspend()
@ 2025-09-22 14:05 Guangshuo Li
  2025-09-22 15:35 ` [PATCH v?] " Markus Elfring
  0 siblings, 1 reply; 4+ messages in thread
From: Guangshuo Li @ 2025-09-22 14:05 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Matthias Brugger, AngeloGioacchino Del Regno, Charles Keepax,
	Guangshuo Li, 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
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 sound/soc/mediatek/mt8365/mt8365-afe-pcm.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c b/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c
index 10793bbe9275..eaeb14e1fce9 100644
--- a/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c
+++ b/sound/soc/mediatek/mt8365/mt8365-afe-pcm.c
@@ -1979,6 +1979,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],
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v?] ASoC: mediatek: mt8365: Add check for devm_kcalloc() in mt8365_afe_suspend()
  2025-09-22 14:05 [PATCH] ASoC: mediatek: mt8365: Add check for devm_kcalloc() in mt8365_afe_suspend() Guangshuo Li
@ 2025-09-22 15:35 ` Markus Elfring
  2025-09-23  8:03   ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2025-09-22 15:35 UTC (permalink / raw)
  To: Guangshuo Li, linux-mediatek, linux-arm-kernel, linux-sound
  Cc: stable, LKML, Alexandre Mergnat, Angelo Gioacchino Del Regno,
	Charles Keepax, Jaroslav Kysela, Liam Girdwood, Mark Brown,
	Matthias Brugger, Takashi Iwai

…
> 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.

How do you think about to increase the application of scope-based resource management?


…
> ---
>  sound/soc/mediatek/mt8365/mt8365-afe-pcm.c | 4 ++++
…

Some contributors would appreciate patch version descriptions.
https://lore.kernel.org/all/?q=%22This+looks+like+a+new+version+of+a+previously+submitted+patch%22
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.17-rc7#n310

See also:
https://lore.kernel.org/linux-sound/20250918140758.3583830-1-lgs201920130244@gmail.com/

Regards,
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v?] ASoC: mediatek: mt8365: Add check for devm_kcalloc() in mt8365_afe_suspend()
  2025-09-22 15:35 ` [PATCH v?] " Markus Elfring
@ 2025-09-23  8:03   ` Mark Brown
  2025-09-23  8:16     ` [v?] " Markus Elfring
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Brown @ 2025-09-23  8:03 UTC (permalink / raw)
  To: Markus Elfring
  Cc: Guangshuo Li, linux-mediatek, linux-arm-kernel, linux-sound,
	stable, LKML, Alexandre Mergnat, Angelo Gioacchino Del Regno,
	Charles Keepax, Jaroslav Kysela, Liam Girdwood, Matthias Brugger,
	Takashi Iwai

[-- Attachment #1: Type: text/plain, Size: 459 bytes --]

On Mon, Sep 22, 2025 at 05:35:35PM +0200, Markus Elfring wrote:
> …
> > 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.
> 
> How do you think about to increase the application of scope-based resource management?

Feel free to ignore Markus, he has a long history of sending
unhelpful review comments and continues to ignore repeated requests
to stop.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [v?] ASoC: mediatek: mt8365: Add check for devm_kcalloc() in mt8365_afe_suspend()
  2025-09-23  8:03   ` Mark Brown
@ 2025-09-23  8:16     ` Markus Elfring
  0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2025-09-23  8:16 UTC (permalink / raw)
  To: Mark Brown, Guangshuo Li, linux-mediatek, linux-arm-kernel,
	linux-sound
  Cc: stable, LKML, Alexandre Mergnat, Angelo Gioacchino Del Regno,
	Charles Keepax, Jaroslav Kysela, Liam Girdwood, Matthias Brugger,
	Takashi Iwai

>> …
>>> 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.
>>
>> How do you think about to increase the application of scope-based resource management?
> 
> Feel free to ignore Markus, he has a long history of sending
> unhelpful review comments and continues to ignore repeated requests
> to stop.

Can you take care for the mentioned development topic in more constructive ways?

Regards,
Markus

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-09-23  8:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-22 14:05 [PATCH] ASoC: mediatek: mt8365: Add check for devm_kcalloc() in mt8365_afe_suspend() Guangshuo Li
2025-09-22 15:35 ` [PATCH v?] " Markus Elfring
2025-09-23  8:03   ` Mark Brown
2025-09-23  8:16     ` [v?] " Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox