Re: [PATCH] ASoC: q6dsp: q6apm: change kzalloc to kcalloc

From: Markus Elfring
Date: Sun Feb 09 2025 - 05:16:30 EST


> We are replacing any instances of kzalloc(size * count, ...) with
> kcalloc(count, size, ...) due to risk of overflow [1].

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.13#n94



> +++ b/sound/soc/qcom/qdsp6/q6apm.c
> @@ -230,7 +230,7 @@ int q6apm_map_memory_regions(struct q6apm_graph *graph, unsigned int dir, phys_a
> return 0;
> }
>
> - buf = kzalloc(((sizeof(struct audio_buffer)) * periods), GFP_KERNEL);
> + buf = kcalloc(periods, sizeof(struct audio_buffer), GFP_KERNEL);


See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.13#n941


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

Regards,
Markus