Skip to contentSkip to conversation

sound/soc/sof:Use kmalloc_array instead of kmalloc

PATCH RESEND New [email protected] 1 participant 1 message Oct 3, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 sound/soc/sof:Use kmalloc_array instead of kmalloc

From: HariKrishna Sagala <[email protected]>

Documentation/process/deprecated.rst recommends to avoid the use of kmalloc with dynamic size calculations due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting.

Replace kmalloc() with kmalloc_array()

---

Resending the patch

 sound/soc/sof/ipc3-dtrace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/sof/ipc3-dtrace.c +1 -1
index e5c8fec173c4..6ec391fd39a9 100644
@@ -126,7 +126,7 @@ static int trace_filter_parse(struct snd_sof_dev *sdev, char *string,
 		capacity += TRACE_FILTER_ELEMENTS_PER_ENTRY;
 		entry = strchr(entry + 1, entry_delimiter[0]);
 	}
-	*out = kmalloc(capacity * sizeof(**out), GFP_KERNEL);
+	*out = kmalloc_array(capacity, sizeof(**out), GFP_KERNEL);
 	if (!*out)
 		return -ENOMEM;
 
Signature · 1 line
2.43.0