From patchwork Fri Jun 23 21:14:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 112337 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6055566vqr; Fri, 23 Jun 2023 14:42:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4PPADxXgiDnITk4/aDeS78A5/S/v/+pv/c8in+ATkvblqDQf4PK1pN0HQfdde3fdKJ3hxi X-Received: by 2002:a05:6a20:7d9a:b0:118:95f1:5a78 with SMTP id v26-20020a056a207d9a00b0011895f15a78mr19303396pzj.31.1687556564145; Fri, 23 Jun 2023 14:42:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687556564; cv=none; d=google.com; s=arc-20160816; b=KumV8gR2AS8TwW+2HXaSKr6yBrvO6+1Sil2L7BOnarHzgC8sOrKs7zIqN/aTGlge4j BcaNnvYYO5lgQTkpHn+z4dV0AxtxCM6EwqjRz4YHC1zXzi7CpAA1LFIM3w1X8dvYtEPn PMoAT4TTC2uRGSfdCxX/SqymxtGqf+0AMgS+cW2oGEVI8TwRUZsEEWXrGG/OwOgc1v7T qpewyqDmmvn/OCJK3I078RdxbDKEGoLhq/tscvQF9fuXvLVa9V/y/u21DYx2Pr+szdbY e2q39UNh1HpywEXLpOngxUyvo9NJDVJweeoLqv4la2yymJUhLc6KIjmiSiyNtoUDy0UN bYnw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w136-20020a627b8e000000b006689f89b186si41985pfc.208.2023.06.23.14.42.31; Fri, 23 Jun 2023 14:42:44 -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 S230264AbjFWVQK (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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769531311896078509?= X-GMAIL-MSGID: =?utf-8?q?1769531311896078509?= 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 Reviewed-by: Simon Horman --- 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;