Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp13033347rwd; Fri, 23 Jun 2023 14:40:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ47p0Ow/8gsEk3IvRbBvEMZg1KhzRgSkCvk4+/jaEMDMram8Ag5AxPCh35Cbx+ehtJydJv5 X-Received: by 2002:a05:6a20:158a:b0:114:7637:3451 with SMTP id h10-20020a056a20158a00b0011476373451mr18579910pzj.37.1687556418924; Fri, 23 Jun 2023 14:40:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687556418; cv=none; d=google.com; s=arc-20160816; b=xou0aRzgcEHe26w5edxdCvZ+msgauR5rpi5dVBQ2S5AgRYfQbzKfeI5XojIQLn6TaE B+guDrf7BlS57wxEYtuEdJwCkLnBljSqWT1I01/ldMkAAdEOIne7GcIBuWqjTEXOjQsq zzzy1L2z7sSbQ49WYzqFdCiukos4sKenWlXNi4eMYac5Et64HSmv3LnBL88Y+w/6nLPR 1IWtQ6yzxIovnICS7U1/mvfyWk3MIttWUEOgN3BOZdzyxpjSmVzeApgj3O4fFF3Yuq5G X9h3Yk4wH/Bpj+FP/IyYVPodVg3rUisf/POp3EDOzEIPUKAtXwtfDLcDlYCYAD9E8Nvq I8mA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1b2qOiijM2SOFY49y/T4nNKOOzZTttGdtrLG5Lh64bI=; fh=0ygwvk59cds318uqho8S6soxx405nxeWPfQubYxJsD8=; b=avSC55nzzUBGnE3w1Z/FA8fYLUnuu/CsUxrHpoiCJbkUGVQ5hzevpGNWhBxoGbzmya Seh/3loL+KoimuyQ6TGPPbTT/0XOr767odiMm6kPjjR4XUkGPytSQzrPGogaLjDkfZmn xgLxR9SEWmSngcY2UaTnliowXPGnWcKCM0ciVK+PnMhs0F31okU4HD6nskAOrdYb/qVn Qbh49ACoL8XTiY/9kpEasVyA2eGb1sUl8jPMyu7AkvBeVmFQkg/7ccHnvmzWr8LiKlqX QvPQRuuC4jBuj9U6DlNQfF+jKvWCTkA3SzmuNdRc/vWoVKai3badjr/+QkcrNTTcE6k+ Jc5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=uyu8z8wz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q14-20020a170902bd8e00b001ab1279d418si54564pls.474.2023.06.23.14.40.06; Fri, 23 Jun 2023 14:40:18 -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=@inria.fr header.s=dc header.b=uyu8z8wz; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=inria.fr Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232037AbjFWVQK (ORCPT + 99 others); Fri, 23 Jun 2023 17:16:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232856AbjFWVPc (ORCPT ); Fri, 23 Jun 2023 17:15:32 -0400 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E048726B9; Fri, 23 Jun 2023 14:15:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1b2qOiijM2SOFY49y/T4nNKOOzZTttGdtrLG5Lh64bI=; b=uyu8z8wzWEtEgebrWGzG9i5oWEcHT9BaIjP0Cs8YqJ4Dnb9025dIo99d UntoRq5hk/R+vCjtxjxaQzUluEwwNY91uXDdnCSwbykFbM7jOIMaPWqbb mmDU8w2Ro+9cTiPSvq7ACpxLUR8sUeZ+2YhiHhuPAojA3G8yl102Og3hU A=; Authentication-Results: mail3-relais-sop.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=Julia.Lawall@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.01,153,1684792800"; d="scan'208";a="59686176" Received: from i80.paris.inria.fr (HELO i80.paris.inria.fr.) ([128.93.90.48]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jun 2023 23:15:13 +0200 From: Julia Lawall To: Claudiu Manoil Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 18/26] net: enetc: use array_size Date: Fri, 23 Jun 2023 23:14:49 +0200 Message-Id: <20230623211457.102544-19-Julia.Lawall@inria.fr> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20230623211457.102544-1-Julia.Lawall@inria.fr> References: <20230623211457.102544-1-Julia.Lawall@inria.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED 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 Use array_size to protect against multiplication overflows. The changes were done using the following Coccinelle semantic patch: // @@ expression E1, E2; constant C1, C2; identifier alloc = {vmalloc,vzalloc}; @@ ( alloc(C1 * C2,...) | alloc( - (E1) * (E2) + array_size(E1, E2) ,...) ) // Signed-off-by: Julia Lawall --- drivers/net/ethernet/freescale/enetc/enetc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 9e1b2536e9a9..7231f8ea1ba4 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -1790,7 +1790,7 @@ static int enetc_alloc_tx_resource(struct enetc_bdr_resource *res, res->bd_count = bd_count; res->bd_size = sizeof(union enetc_tx_bd); - res->tx_swbd = vzalloc(bd_count * sizeof(*res->tx_swbd)); + res->tx_swbd = vzalloc(array_size(bd_count, sizeof(*res->tx_swbd))); if (!res->tx_swbd) return -ENOMEM; @@ -1878,7 +1878,7 @@ static int enetc_alloc_rx_resource(struct enetc_bdr_resource *res, if (extended) res->bd_size *= 2; - res->rx_swbd = vzalloc(bd_count * sizeof(struct enetc_rx_swbd)); + res->rx_swbd = vzalloc(array_size(bd_count, sizeof(struct enetc_rx_swbd))); if (!res->rx_swbd) return -ENOMEM;