From nobody Mon Jun 22 16:54:25 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36B88C433EF for ; Sun, 20 Mar 2022 06:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244800AbiCTGYG (ORCPT ); Sun, 20 Mar 2022 02:24:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231753AbiCTGX5 (ORCPT ); Sun, 20 Mar 2022 02:23:57 -0400 Received: from smtp.smtpout.orange.fr (smtp09.smtpout.orange.fr [80.12.242.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D88B511DD32 for ; Sat, 19 Mar 2022 23:22:33 -0700 (PDT) Received: from pop-os.home ([90.126.236.122]) by smtp.orange.fr with ESMTPA id VoxRnDXVQAWDQVoxRnHo6V; Sun, 20 Mar 2022 07:22:31 +0100 X-ME-Helo: pop-os.home X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Sun, 20 Mar 2022 07:22:31 +0100 X-ME-IP: 90.126.236.122 From: Christophe JAILLET To: Pierre-Louis Bossart , Liam Girdwood , Ranjani Sridharan , Kai Vehmanen , Daniel Baluta , Mark Brown , Jaroslav Kysela , Takashi Iwai Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , sound-open-firmware@alsa-project.org, alsa-devel@alsa-project.org Subject: [PATCH] ASoC: SOF: topology: Avoid open coded arithmetic in memory allocation Date: Sun, 20 Mar 2022 07:22:26 +0100 Message-Id: <3bbf03cfd1966bc6fb6dd0939e039fc161078a61.1647757329.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use kcalloc() instead of kzalloc()+open coded multiplication. This is safer and saves a few lines of code. Signed-off-by: Christophe JAILLET --- sound/soc/sof/topology.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/sound/soc/sof/topology.c b/sound/soc/sof/topology.c index 369693cc6d10..8e9d8e079d68 100644 --- a/sound/soc/sof/topology.c +++ b/sound/soc/sof/topology.c @@ -1096,7 +1096,6 @@ static int sof_widget_parse_tokens(struct snd_soc_com= ponent *scomp, struct snd_s const struct sof_token_info *token_list =3D ipc_tplg_ops->token_list; struct snd_soc_tplg_private *private =3D &tw->priv; int num_tuples =3D 0; - size_t size; int ret, i; =20 if (count > 0 && !object_token_list) { @@ -1109,8 +1108,7 @@ static int sof_widget_parse_tokens(struct snd_soc_com= ponent *scomp, struct snd_s num_tuples +=3D token_list[object_token_list[i]].count; =20 /* allocate memory for tuples array */ - size =3D sizeof(struct snd_sof_tuple) * num_tuples; - swidget->tuples =3D kzalloc(size, GFP_KERNEL); + swidget->tuples =3D kcalloc(num_tuples, sizeof(*swidget->tuples), GFP_KER= NEL); if (!swidget->tuples) return -ENOMEM; =20 @@ -1547,7 +1545,6 @@ static int sof_link_load(struct snd_soc_component *sc= omp, int index, struct snd_ const struct sof_token_info *token_list =3D ipc_tplg_ops->token_list; struct snd_soc_tplg_private *private =3D &cfg->priv; struct snd_sof_dai_link *slink; - size_t size; u32 token_id =3D 0; int num_tuples =3D 0; int ret, num_sets; @@ -1659,8 +1656,7 @@ static int sof_link_load(struct snd_soc_component *sc= omp, int index, struct snd_ } =20 /* allocate memory for tuples array */ - size =3D sizeof(struct snd_sof_tuple) * num_tuples; - slink->tuples =3D kzalloc(size, GFP_KERNEL); + slink->tuples =3D kcalloc(num_tuples, sizeof(*slink->tuples), GFP_KERNEL); if (!slink->tuples) { kfree(slink->hw_configs); kfree(slink); --=20 2.32.0