From patchwork Thu Jun 1 17:30:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 102115 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp503515vqr; Thu, 1 Jun 2023 10:39:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7RoqP6tdv1gsPmYRfjgqnWfOhgLIomgIGNLzvWsW+5HlzjtrPOYNjwEGEIz2kT7eTMTFel X-Received: by 2002:a05:6a21:3388:b0:10c:2fe0:b3d with SMTP id yy8-20020a056a21338800b0010c2fe00b3dmr8442534pzb.33.1685641189054; Thu, 01 Jun 2023 10:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685641189; cv=none; d=google.com; s=arc-20160816; b=xef6JJm3HtPH8b3P7w9Zpo7o2cyklCtxchRCP5rteF81+59AVdLDeBgbBLqTzyK0ZA IdQ5OmWRMQFYaGNs5RONSn6cEOCz4cNW6UFUGp9KM3Tud+vo+pa7HPJGJX9OobKDhVvc 3hguFCW9pG2FqPDit8OphUCEYr4B4htn8DgjOcGGE4ISN7qNRGuZYjzQrXaTcm4cAp3c xJn1612w1ysfUcuAgZ1h+Sj6atvzdMTANJ+NHeGWZtCLEK5bda5ZvpCmdH/ylF2pSu0T LkjKfdmsTL7EI39ju/nvv3G9ovspHFoTqbaS+Pui6/0ZRbdLRqFvGuNcs6d3tY0uCb/t I0Iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=rhggJM25UscX66J1Ug1pJJ1oVkQChGg3ni6GqVZhFI0=; b=UjkD+AnWcop2Gw2uWqt+sCZomITxY6JDBH/KD7SkqrHISrk9KrF5EPs4b+Gy37OAYE u7VahpF+kDoH4o/FppnMvsf7QVzwE2MoTCjC31trL0gQ5nF4FbZdz14lOkt8GCR4Dyuk 03vd9UQLkm/jzwUO8aHrIo2wBAcJTS5gh2Xgxfd4oJy41cBQvDAeCv9G+7sERWkB1rDO gZ4SBB5z1UE7E0rMynMn5vds8841vXO6XnJwilM2loHHluoCGTJmmgmBd3gcLQvdno5+ 6PlFGcSLGIURiYYOIKWOWzo3qra3AQLOp+faEovVUpURVdO6MEYH68lNASoK8t2OROZP FBxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b="hEQw/usF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i12-20020a633c4c000000b0051b930ef847si3148648pgn.134.2023.06.01.10.39.34; Thu, 01 Jun 2023 10:39:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@wanadoo.fr header.s=t20230301 header.b="hEQw/usF"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231678AbjFARac (ORCPT + 99 others); Thu, 1 Jun 2023 13:30:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232172AbjFARab (ORCPT ); Thu, 1 Jun 2023 13:30:31 -0400 Received: from smtp.smtpout.orange.fr (smtp-20.smtpout.orange.fr [80.12.242.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A3411A2 for ; Thu, 1 Jun 2023 10:30:25 -0700 (PDT) Received: from pop-os.home ([86.243.2.178]) by smtp.orange.fr with ESMTPA id 4m7qqKkRYe9XV4m7qqJitg; Thu, 01 Jun 2023 19:30:18 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1685640618; bh=rhggJM25UscX66J1Ug1pJJ1oVkQChGg3ni6GqVZhFI0=; h=From:To:Cc:Subject:Date; b=hEQw/usFf5yS+y9l4ClFR8rgeZwr2277zC+d2Mk73yPZjHgov2C9HuWtcnxXuChk3 wD8vpbixpGVJtCJoCRO3FNPLN8dON09RpnfHLZbYdz8sheqbwP/nrdWgN1ERr2kIMx LkrEFfXDsYMJmUDxGpbh3sfPP0cK5Lxe4hKUc0Br7+GXhSSe4WUjwFnwA18lEb9nXh fYQCz1GoLvK946K59PwI7IAbtVItKflaWfb0yS6dsU3uK6k4uTe1mPyBwtkQ0A99cu S0OphpjdSucfnF2u9NJ4wUzWLIVvUAaq08Xx8GayAB5iILrKzn7Xke+Ja+ZT/Ov3Yi HcGfLUBumtO1A== X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Thu, 01 Jun 2023 19:30:18 +0200 X-ME-IP: 86.243.2.178 From: Christophe JAILLET To: Pierre-Louis Bossart , Liam Girdwood , Peter Ujfalusi , Bard Liao , Ranjani Sridharan , Daniel Baluta , Kai Vehmanen , 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: ipc4-topology: Use size_t for variable passed to kzalloc() Date: Thu, 1 Jun 2023 19:30:12 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767522895275647139?= X-GMAIL-MSGID: =?utf-8?q?1767522895275647139?= struct_size() checks for overflow, but assigning its result to just a u32 may still overflow after a successful check. Use a size_t instead in order to be cleaner. Signed-off-by: Christophe JAILLET --- Based on analysis from Dan Carpenter on another patch (see [1]). [1]: https://lore.kernel.org/all/00e84595-e2c9-48ea-8737-18da34eaafbf@kili.mountain/ --- sound/soc/sof/ipc4-topology.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/sof/ipc4-topology.c b/sound/soc/sof/ipc4-topology.c index db64e0cb8663..50faa4c88b97 100644 --- a/sound/soc/sof/ipc4-topology.c +++ b/sound/soc/sof/ipc4-topology.c @@ -881,7 +881,7 @@ static int sof_ipc4_widget_setup_comp_process(struct snd_sof_widget *swidget) /* allocate memory for base config extension if needed */ if (process->init_config == SOF_IPC4_MODULE_INIT_CONFIG_TYPE_BASE_CFG_WITH_EXT) { struct sof_ipc4_base_module_cfg_ext *base_cfg_ext; - u32 ext_size = struct_size(base_cfg_ext, pin_formats, + size_t ext_size = struct_size(base_cfg_ext, pin_formats, swidget->num_input_pins + swidget->num_output_pins); base_cfg_ext = kzalloc(ext_size, GFP_KERNEL);