From patchwork Fri Jun 23 21:14:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 112321 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp6049987vqr; Fri, 23 Jun 2023 14:27:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5TxSgohkweOn+1aiJX49ljcxiYbBhdtKiBcFdg/cb7IdABSnaVdTAlFNPZ1SRfDTflwqEL X-Received: by 2002:a05:6a20:9385:b0:10c:4ff5:38b7 with SMTP id x5-20020a056a20938500b0010c4ff538b7mr13742828pzh.6.1687555678599; Fri, 23 Jun 2023 14:27:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687555678; cv=none; d=google.com; s=arc-20160816; b=Rv6Ru3AyQLJ5YTyUaqo+wO+cGYlG2iieqRUhc1fytUGBrj4/z5tNmkbnGDewtxBvZX 0c0frXelxNqBt2HSEiJubMNfrKjdcfuq5Ih1HvxkAZbolc16/13fnm9O/1bJZEe+jsOE Kpd0RiSYGBPsdmsyzZPn4i61o4IbxcH81eH3hIN6WoMIQ+w6mLmmDznNu5HGeuqta3it kwvoRczitH7XIjwULCdIgadLCGZEoYFqDhX0HpbXmKcSG4i0kfkD8L2jzHDbkI3yYJT6 Ceo2WzMWSHKM57euFUS9D1lSkIql1jv6xnA4GoO+ZfLQSbsrOOCSjkx3iPhRjMKNm2+5 L43w== 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=GCWo4PVrP3ZeFd8PIff442f3VLqG/AMKNMFkIT9T6cA=; fh=kAwTNgFKZnElgUbacnbPeNcvgCOdjAyuqnkcwpNxIGk=; b=CCmIjglvNV9d6DyFDUXfpBy7ppb9GiFdbbZD6y9rB3wjyV7CttraXhQk2E4N9IM0li yaN2RxJL8Hrn6Xa4PLa5fGOC5i7pyggbkTLUhhrPxvaMoVvCJHp9Qr1G05ggf4mSMEm9 lijwZwzMVtyIBT8DvdRkNwwVAnwhSEZM/eWZNoiCfxAk+pGG7JnVrXREGXEHBha9YQdm yjkAfZAj/iLAO6HUrDETxZDfxuzproV2/YXz+ZzG+9RZRKd8YIe6zUAZ47kTWqC03B4n rkg6wp40qblaHci+SAt1M3b8l3LjUtyZ8rkogL9OTIxwhf0lPTozvyh4AiLMgQfykXcr G3gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@inria.fr header.s=dc header.b=K02CyeC0; 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 q20-20020a056a00151400b0065d3032fa22si15615pfu.289.2023.06.23.14.27.43; Fri, 23 Jun 2023 14:27:58 -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=K02CyeC0; 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 S233006AbjFWVU6 (ORCPT + 99 others); Fri, 23 Jun 2023 17:20:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232609AbjFWVUi (ORCPT ); Fri, 23 Jun 2023 17:20:38 -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 30BAC2D46; Fri, 23 Jun 2023 14:19:22 -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=GCWo4PVrP3ZeFd8PIff442f3VLqG/AMKNMFkIT9T6cA=; b=K02CyeC0TxO7IAr7a3O+52eMgvms+F1/AvW0vYiFyEyImYoyQe3rBgJa TpAOj/W+1u1Yyv5zigBnWDQbMKc4dofND330WeFJkbKNYeeW9PRFvUD6F JG+WW/GS1N7xtJpu/yozutxXj7AYxLY+aNccGkg1oAWTQTtopCJ72nAgU E=; 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="59686167" 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:11 +0200 From: Julia Lawall To: Shannon Nelson Cc: keescook@chromium.org, kernel-janitors@vger.kernel.org, Brett Creeley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/26] pds_core: use array_size Date: Fri, 23 Jun 2023 23:14:40 +0200 Message-Id: <20230623211457.102544-10-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=unavailable 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?1769530382920724963?= X-GMAIL-MSGID: =?utf-8?q?1769530382920724963?= 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 Acked-by: Shannon Nelson --- drivers/net/ethernet/amd/pds_core/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/amd/pds_core/core.c b/drivers/net/ethernet/amd/pds_core/core.c index 483a070d96fa..d87f45a1ee2f 100644 --- a/drivers/net/ethernet/amd/pds_core/core.c +++ b/drivers/net/ethernet/amd/pds_core/core.c @@ -196,7 +196,7 @@ int pdsc_qcq_alloc(struct pdsc *pdsc, unsigned int type, unsigned int index, dma_addr_t q_base_pa; int err; - qcq->q.info = vzalloc(num_descs * sizeof(*qcq->q.info)); + qcq->q.info = vzalloc(array_size(num_descs, sizeof(*qcq->q.info))); if (!qcq->q.info) { err = -ENOMEM; goto err_out; @@ -219,7 +219,7 @@ int pdsc_qcq_alloc(struct pdsc *pdsc, unsigned int type, unsigned int index, if (err) goto err_out_free_q_info; - qcq->cq.info = vzalloc(num_descs * sizeof(*qcq->cq.info)); + qcq->cq.info = vzalloc(array_size(num_descs, sizeof(*qcq->cq.info))); if (!qcq->cq.info) { err = -ENOMEM; goto err_out_free_irq;