Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ASoC: Intel: avs: Add check for kcalloc() when setting constraints
@ 2025-09-18 13:56 Guangshuo Li
  2025-09-18 14:11 ` Cezary Rojewski
  0 siblings, 1 reply; 2+ messages in thread
From: Guangshuo Li @ 2025-09-18 13:56 UTC (permalink / raw)
  To: Cezary Rojewski, Liam Girdwood, Peter Ujfalusi, Bard Liao,
	Ranjani Sridharan, Kai Vehmanen, Pierre-Louis Bossart, Mark Brown,
	Jaroslav Kysela, Takashi Iwai, Amadeusz Sławiński,
	Piotr Maziarz, Guangshuo Li, linux-sound, linux-kernel
  Cc: stable

kcalloc() may fail. avs_path_set_constraint() writes to rlist[i],
clist[i], and slist[i] unconditionally, which can cause a NULL pointer
dereference under low-memory conditions.

Add checks for the three kcalloc() calls. If any allocation fails,
free any previously allocated lists and return -ENOMEM.

Fixes: f2f847461fb7 ("ASoC: Intel: avs: Constrain path based on BE capabilities")
Cc: stable@vger.kernel.org
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
---
 sound/soc/intel/avs/path.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sound/soc/intel/avs/path.c b/sound/soc/intel/avs/path.c
index cafb8c6198be..cb641d37d565 100644
--- a/sound/soc/intel/avs/path.c
+++ b/sound/soc/intel/avs/path.c
@@ -135,6 +135,9 @@ int avs_path_set_constraint(struct avs_dev *adev, struct avs_tplg_path_template
 	clist = kcalloc(i, sizeof(clist), GFP_KERNEL);
 	slist = kcalloc(i, sizeof(slist), GFP_KERNEL);
 
+	if (!rlist || !clist || !slist)
+		return -ENOMEM;
+
 	i = 0;
 	list_for_each_entry(path_template, &template->path_list, node) {
 		struct avs_tplg_pipeline *pipeline_template;
-- 
2.43.0


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

end of thread, other threads:[~2025-09-18 14:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-18 13:56 [PATCH] ASoC: Intel: avs: Add check for kcalloc() when setting constraints Guangshuo Li
2025-09-18 14:11 ` Cezary Rojewski

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