Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1863130pxb; Sun, 5 Sep 2021 01:20:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2CEfRyeQbr0VTBjLD/St0KgwpVAA4cQQ9zAJuzE9YjfAbHLNu6l3IQ6tRsYVwiFjAiLri X-Received: by 2002:a92:d852:: with SMTP id h18mr4934406ilq.211.1630830044570; Sun, 05 Sep 2021 01:20:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630830044; cv=none; d=google.com; s=arc-20160816; b=Hctzv00kihEwK0al9IIs7jPmFqBdk+8mD7ua/eaD+IovlDOKeyjDd8zjPBjZY1D+wA VD+IDiFH43x3bcQJhytQp4aj9JIWcTsAvQom1r63W9FZv1uA2SPr1aG5v7MjNqe9Hwlf 4h+UhSCS+2wYeEeURA1x2M9XRI6OeEL6OFf57T3xS06fhUoKw5pMSPoFkxMeAjpWwsiO HSPHRK8JzIF6e2peckx6oPXWWFlLnZOcJP0VKdgYszzSNuxnLk5gWQRViIIQpYsPvLMT USem0800j0rGGs5SSUY/XVqyj+LscOiGzcd96P2xGbJYE1483UNCMVv8i0a0Zhwqdx7M caRg== 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=/5WhgAsy4f1ktzymF74Z56H35mNigYFiOR31FPxyhAM=; b=Ai54cWE7GgoDG03grg2YZuZew4wcMPjLC05iVli/vyH3m4hB9Rd9322xoMBWlklWf9 l9/tY6crL5W9FALPDrJ/xoTaHVLgc+2bxxgp9yljHVUrv0g7Xh+eDtwvuLUB/VO5VVCB kD+S1ajE2PaYwPqcUX7AnpYK5udpZntBgFqLfwF1hD95bMrqWI+WIyzP3dtIs2bwpORV HocVCr50tkk6RmUcOBQwZw/2AJPZHPit7q/16zGuNK/ida29tbTKoN17QGeuiJqEQD5t 2iVKsS3pvEuQM3yH9ATjGrhLrX/r1VHDzHXTlNjOfSWty31hjH9XS8E7Kuuc7uqNwZW6 YCbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=MKhhkRe7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w31si4848186jal.3.2021.09.05.01.20.17; Sun, 05 Sep 2021 01:20:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmx.net header.s=badeba3b8450 header.b=MKhhkRe7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmx.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235633AbhIEITz (ORCPT + 99 others); Sun, 5 Sep 2021 04:19:55 -0400 Received: from mout.gmx.net ([212.227.15.15]:49905 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229482AbhIEITz (ORCPT ); Sun, 5 Sep 2021 04:19:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1630829927; bh=fTBXvKxZl6B/IHLAHmbTOQkcjt7hvW0fG3GfH17J/Fo=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date; b=MKhhkRe79drF0yldxNMv8bw7RvqDGYCpPKLRJ8T6cHob+tjK0KBTyC0kmiWKPjnuF GRj2bhslB2MACSgwtLe4wImcRzoZzw97MQgf/E2//kLkdOmhNJat1kQa0MmwUZBwoZ gtaZnHGqEyR3QLCV5nlhzMBlmAQdimYzE99mwqG4= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from localhost.localdomain ([79.150.72.99]) by mail.gmx.net (mrgmx005 [212.227.17.184]) with ESMTPSA (Nemesis) id 1MoO6M-1ml4UZ1JpQ-00oq2c; Sun, 05 Sep 2021 10:18:47 +0200 From: Len Baker To: Selvin Xavier , Naresh Kumar PBS , Doug Ledford , Jason Gunthorpe Cc: Len Baker , Kees Cook , linux-rdma@vger.kernel.org, linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] RDMA/bnxt_re: Prefer kcalloc over open coded arithmetic Date: Sun, 5 Sep 2021 10:18:12 +0200 Message-Id: <20210905081812.17113-1-len.baker@gmx.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:vzAhzYJz4CiUc9w8Raus6XPXj/K19h+cFftCVKPdHnD4ICkrkCu 7XoRcMK28P6FVNJAkB5J+Uh68r9xW4RJ96AUzolLL5sB/gd6R5NhZi9Bd1mTNBXpId7tnuH GItLhPLWaDlDzjdLvGTKA5/qMkvNIrXqe3NYeKn7X2+20/wggFuycRphjbgkSvdmLWSD+Rr TW6J58OCRhYABkn+jzNXw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:f7gIwwtcx9A=:XxVo3HNf616woWeFi8zZq+ 5D7nCIn5pEcUHG5vSvZ200ZzIMNo/YWu4j4GIp0VULBni31LlbnoyYKDyxL3KT22WDMzxuLPM aE7fFznWCXIvVRyZ3kPOnXO9OOYPdh3GHAZv/VCoqSBb9hgU4qcDuJ+VCAFC4cBvPrbY4xGqr rrChP7/WxGZU3zUtB3trQtM+VmW0otfvEWSd4AK2RTvH7I44DWVcQHIs09FDjgCN/qDCmkczb e2ROm5Rpbv4CT4jr6Fr52QwSMFAJA7BK5LHDm2mqrNuQphmUb948Ui6ABe3oa5FszqlbTpFWe 2LIUVU5j5/H49bzG3WLalfTYOTKQRVaq10QRaX5evKqI+r2njf9eoLsn30qcnN5li8Wh0hRWW MFQP6GoKQoxRGvF+7v6BtKjF+v3IY241Bf11vw4MS06bugtWaL6stPM6LQFh32VSPhto0L+RE ePiCVB3JlLeWjgCMiH81B9VZasS2D0TKS6ds95w4C6Oo5hgTef4T/yTxJK6wir3PT9EdiY2Bz J4lQ6INNolzp0Cx6OtpAqYg0i5MM1SUYf6pTJq04yxIY9M3PXmGlgVzwxvaE2XM1Ge0+bWzi1 A9DZmpXu03Y6Ju7FJT3V7/tclCV8dDkufM+s3fPFZs9YPTQJ2zorWegFNRa9GoOa0EDGbj2rw pPl0sMpL7DYla6vMit264JgMqIiiZSHwLH7MH/2H1hIv5n7wR3eKp8tvB5+JAbsKXTyrstkAB QesQ+VBuvkFc9IkQVlfkH0jAjA+ojMUsSnMTe0P3KEJSN2gVX23lmPS04XYWBjnIz8aQGYw1Y hekMx3d6YQJkpTSnMPdd15W+aoDtkaEb0ZP+bZ0V1auoZGkg/yUcBXfZNJfHP7GGU0B0xgO/0 m7lNF6eUxOxWtQMfNF09W6Z8Eae041rhRO5UcC2YvbgJk3/Q3zb0tmbGpb4uO3Jbr3eqE9qLw A9Bes/uM3wvh/cGpg0kXuKjJlqIxK2l+ozrF24oMmDF+TnyIna0IMbXS5nSiub1YcCc2DegTp 3xLw2w2ErNdpZeLoMLQUjYEP9zr6H6xNxmpLvg01sQyaz6hXm7rJMVgpJvTwlb9DQ9LD1wDm9 2yayfwbWyoz13I/5qINqRqtHxwLcKR/mGMEw6qyAejHRlwiXZ0rVQ5Y9A== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As noted in the "Deprecated Interfaces, Language Features, Attributes, and Conventions" documentation [1], size calculations (especially multiplication) should not be performed in memory allocator (or similar) function arguments due to the risk of them overflowing. This could lead to values wrapping around and a smaller allocation being made than the caller was expecting. Using those allocations could lead to linear overflows of heap memory and other misbehaviors. In this case this is not actually dynamic sizes: both sides of the multiplication are constant values. However it is best to refactor this anyway, just to keep the open-coded math idiom out of code. So, use the purpose specific kcalloc() function instead of the argument size * count in the kzalloc() function. Also, remove the unnecessary initialization of the sqp_tbl variable since it is set a few lines later. [1] https://www.kernel.org/doc/html/v5.14/process/deprecated.html#open-cod= ed-arithmetic-in-allocator-arguments Signed-off-by: Len Baker =2D-- drivers/infiniband/hw/bnxt_re/ib_verbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/bnxt_re/ib_verbs.c b/drivers/infiniband= /hw/bnxt_re/ib_verbs.c index ea0054c60fbc..6fd4b87832b4 100644 =2D-- a/drivers/infiniband/hw/bnxt_re/ib_verbs.c +++ b/drivers/infiniband/hw/bnxt_re/ib_verbs.c @@ -1312,7 +1312,7 @@ static int bnxt_re_init_qp_attr(struct bnxt_re_qp *q= p, struct bnxt_re_pd *pd, static int bnxt_re_create_shadow_gsi(struct bnxt_re_qp *qp, struct bnxt_re_pd *pd) { - struct bnxt_re_sqp_entries *sqp_tbl =3D NULL; + struct bnxt_re_sqp_entries *sqp_tbl; struct bnxt_re_dev *rdev; struct bnxt_re_qp *sqp; struct bnxt_re_ah *sah; @@ -1320,7 +1320,7 @@ static int bnxt_re_create_shadow_gsi(struct bnxt_re_= qp *qp, rdev =3D qp->rdev; /* Create a shadow QP to handle the QP1 traffic */ - sqp_tbl =3D kzalloc(sizeof(*sqp_tbl) * BNXT_RE_MAX_GSI_SQP_ENTRIES, + sqp_tbl =3D kcalloc(BNXT_RE_MAX_GSI_SQP_ENTRIES, sizeof(*sqp_tbl), GFP_KERNEL); if (!sqp_tbl) return -ENOMEM; =2D- 2.25.1