mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ASoC: rockchip: rk3399_gru_sound: Allocate dai_link with ARRAY_SIZE()
@ 2026-09-17 21:14 Kees Cook
  0 siblings, 0 replies; only message in thread
From: Kees Cook @ 2026-09-17 21:14 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: Kees Cook, Kees Cook, Mark Brown, Jaroslav Kysela, Takashi Iwai,
	Heiko Stuebner, linux-sound, linux-arm-kernel, linux-rockchip,
	linux-kernel, linux-hardening

From: Kees Cook <kees+treewide@kernel.org>

In preparation for making the devm_kmalloc family of allocators type
aware, we need to make sure that the returned type from the allocation
matches the type of the variable being assigned. (Before, the allocator
would always return "void *", which can be implicitly cast to any
pointer type.)

This is allocating a copy of rockchip_dais, which is an array of struct
snd_soc_dai_link, but the size was taken from the whole array, which
would make the allocation type a pointer to the array rather than the
"struct snd_soc_dai_link *" being assigned. Allocate ARRAY_SIZE-many
entries instead. The resulting allocation size is the same.

Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0:
sound/soc/rockchip/rk3399_gru_sound.o

Assisted-by: LLM coccinelle
Signed-off-by: Kees Cook <kees+treewide@kernel.org>
---
Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: Heiko Stuebner <heiko@sntech.de>
Cc: <linux-sound@vger.kernel.org>
Cc: <linux-arm-kernel@lists.infradead.org>
Cc: <linux-rockchip@lists.infradead.org>
---
 sound/soc/rockchip/rk3399_gru_sound.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/soc/rockchip/rk3399_gru_sound.c b/sound/soc/rockchip/rk3399_gru_sound.c
index b80acb221d24..04e7bed8275d 100644
--- a/sound/soc/rockchip/rk3399_gru_sound.c
+++ b/sound/soc/rockchip/rk3399_gru_sound.c
@@ -505,8 +505,8 @@ static int rockchip_sound_of_parse_dais(struct device *dev,
 	int i, index;
 	int num_routes;
 
-	card->dai_link = devm_kzalloc(dev, sizeof(rockchip_dais),
-				      GFP_KERNEL);
+	card->dai_link = devm_kcalloc(dev, ARRAY_SIZE(rockchip_dais),
+				      sizeof(*card->dai_link), GFP_KERNEL);
 	if (!card->dai_link)
 		return -ENOMEM;
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-17 21:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 21:14 [PATCH] ASoC: rockchip: rk3399_gru_sound: Allocate dai_link with ARRAY_SIZE() Kees Cook

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

all inboxes | Powered by JetHome®