From: Kees Cook <[email protected]> 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 <[email protected]> --- Cc: Liam Girdwood <[email protected]> Cc: Mark Brown <[email protected]> Cc: Jaroslav Kysela <[email protected]> Cc: Takashi Iwai <[email protected]> Cc: Heiko Stuebner <[email protected]> Cc: <[email protected]> Cc: <[email protected]> Cc: <[email protected]> --- 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

