From patchwork Sat Apr 22 14:33:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9694397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5169C600CA for ; Sat, 22 Apr 2017 14:33:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 406B8277D9 for ; Sat, 22 Apr 2017 14:33:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3476927EED; Sat, 22 Apr 2017 14:33:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6C23277D9 for ; Sat, 22 Apr 2017 14:33:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1424185AbdDVOde (ORCPT ); Sat, 22 Apr 2017 10:33:34 -0400 Received: from mout.web.de ([212.227.15.4]:54836 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423913AbdDVOdc (ORCPT ); Sat, 22 Apr 2017 10:33:32 -0400 Received: from [192.168.1.2] ([77.181.100.232]) by smtp.web.de (mrweb002 [213.165.67.108]) with ESMTPSA (Nemesis) id 0Lj2XW-1cRDts2sNq-00dGwQ; Sat, 22 Apr 2017 16:33:15 +0200 Subject: [PATCH v2 02/12] IB/ocrdma: Use kcalloc() in five functions From: SF Markus Elfring To: Devesh Sharma , Doug Ledford , Hal Rosenstock , Sean Hefty , Selvin Xavier , Yuval Shaia , linux-rdma@vger.kernel.org Cc: LKML , kernel-janitors@vger.kernel.org References: <1492720999.3041.18.camel@redhat.com> <86425035-7da8-d2b1-8544-d4f7540d50c6@users.sourceforge.net> Message-ID: Date: Sat, 22 Apr 2017 16:33:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0.1 MIME-Version: 1.0 In-Reply-To: <86425035-7da8-d2b1-8544-d4f7540d50c6@users.sourceforge.net> Content-Language: en-GB X-Provags-ID: V03:K0:6a7jxEdzQKVZODnBDJXpHFGUprm2C7ronzsfSlJguYaPyLdxQQv nDlq7GX58zL5UK1MBIizt5gs9y97uAlKA48Qdz6mzFQCeQZ08mSLQZu2z76EC3NoThwLmZK tjcHNwckrOcnPwxh/PNW2nA6t7Lcq1cZe3dVUy+jtDJZsq6618A+8Bjp2Mm66owaJx4Yl29 RW72nn2wV2MNGgn9ovWiw== X-UI-Out-Filterresults: notjunk:1; V01:K0:890AFKZffio=:wbknHiJjINUuEvA/hhomj6 XsH+ASNMtTXRCnQH+A5fFw5WZdSi6SWxPLaI+Glgj9XgT1gp2BGqntvvoBMl4rf8ZzEwDxXKJ qEz3llIrf1B82rM3HTWCjBiynDn0bUhoemahJ7yavtL3PMa1WIV7gGXHAsZpu5ZeK4oIRVgCZ uSmRrSBqcFQwKoWfcZCrwMM0t/lHM79Bhqq2JFUqirUAfgUXVxXYmV3ZXh4uKAvNjwI3amc48 OTCpuOcf0vLXBr5nwXpm6ZOqVtaJcEVWEpfkOVuLZgk+myReJUJUpU25HOOI71/SEaPYWijky JK4Hslga6Nwlbk5hjOtPcKzcRTwEJKlkquWXbECkdNcLOTpDeylHfALaFZPxqsT1dr3PT0cOS Ck0JppTzqIu1z/JUHRAqTHPaJ8MDtctgKjmi4otzBPBFxYyno9C3u/v673f1tmPBMuwCrqEPI s5jrGVzFGoCPPbvJBI5YVl3rXWLuTDtKFlxuoFo7V3Gf//3lyAJiiNmG06bSfPMxibvp1qkhQ wsL0hg24Mzz6u7JbAzw6TMSocdcI1x4eBAKkwQ3QoDslLq22l9dCUmfWtSMoN6f9BVTtnkHrf RyW0Vl9jvGU4U1EoMKaddDpNAHky7StpBQKAmnyvoamPYliKK231o+dCu8OHqGugj7o0TugJE yLIbogP1aVOOQBFwIsKIvgPMwURZqqnIgnoeosCcfgYZZkU833mnYGmQrAAxJb1/7dYgfradj r4+c4kvXy+ZQTX7ubJhdhDJUWj9QfI/Mvn5f4i7t+hBWwF4YfTnbEqoLHPQ3/jLzmxBvAR222 aRL2HY/ Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sat, 22 Apr 2017 11:41:55 +0200 * Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kcalloc". This issue was detected by using the Coccinelle software. * Replace the specification of data types by pointer dereferences to make the corresponding size determinations a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring --- v2: Changes were rebased on source files from Linux next-20170421. These were recombined as requested by Doug Ledford. drivers/infiniband/hw/ocrdma/ocrdma_hw.c | 2 +- drivers/infiniband/hw/ocrdma/ocrdma_main.c | 10 +++++----- drivers/infiniband/hw/ocrdma/ocrdma_verbs.c | 19 +++++++++---------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c index c868314222b9..d5a3127b6df8 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_hw.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_hw.c @@ -3103,7 +3103,7 @@ static int ocrdma_create_eqs(struct ocrdma_dev *dev) if (!num_eq) return -EINVAL; - dev->eq_tbl = kzalloc(sizeof(struct ocrdma_eq) * num_eq, GFP_KERNEL); + dev->eq_tbl = kcalloc(num_eq, sizeof(*dev->eq_tbl), GFP_KERNEL); if (!dev->eq_tbl) return -ENOMEM; diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_main.c b/drivers/infiniband/hw/ocrdma/ocrdma_main.c index 57c9a2ad0260..91705b10f269 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_main.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_main.c @@ -225,19 +225,19 @@ static int ocrdma_register_device(struct ocrdma_dev *dev) static int ocrdma_alloc_resources(struct ocrdma_dev *dev) { mutex_init(&dev->dev_lock); - dev->cq_tbl = kzalloc(sizeof(struct ocrdma_cq *) * - OCRDMA_MAX_CQ, GFP_KERNEL); + dev->cq_tbl = kcalloc(OCRDMA_MAX_CQ, sizeof(*dev->cq_tbl), GFP_KERNEL); if (!dev->cq_tbl) goto alloc_err; if (dev->attr.max_qp) { - dev->qp_tbl = kzalloc(sizeof(struct ocrdma_qp *) * - OCRDMA_MAX_QP, GFP_KERNEL); + dev->qp_tbl = kcalloc(OCRDMA_MAX_QP, sizeof(*dev->qp_tbl), + GFP_KERNEL); if (!dev->qp_tbl) goto alloc_err; } - dev->stag_arr = kzalloc(sizeof(u64) * OCRDMA_MAX_STAG, GFP_KERNEL); + dev->stag_arr = kcalloc(OCRDMA_MAX_STAG, sizeof(*dev->stag_arr), + GFP_KERNEL); if (dev->stag_arr == NULL) goto alloc_err; diff --git a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c index c52edeafd616..146601c97158 100644 --- a/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c +++ b/drivers/infiniband/hw/ocrdma/ocrdma_verbs.c @@ -879,9 +879,8 @@ static int ocrdma_build_pbl_tbl(struct ocrdma_dev *dev, struct ocrdma_hw_mr *mr) void *va; dma_addr_t pa; - mr->pbl_table = kzalloc(sizeof(struct ocrdma_pbl) * - mr->num_pbls, GFP_KERNEL); - + mr->pbl_table = kcalloc(mr->num_pbls, sizeof(*mr->pbl_table), + GFP_KERNEL); if (!mr->pbl_table) return -ENOMEM; @@ -1362,13 +1361,12 @@ static void ocrdma_set_qp_db(struct ocrdma_dev *dev, struct ocrdma_qp *qp, static int ocrdma_alloc_wr_id_tbl(struct ocrdma_qp *qp) { - qp->wqe_wr_id_tbl = - kzalloc(sizeof(*(qp->wqe_wr_id_tbl)) * qp->sq.max_cnt, - GFP_KERNEL); + qp->wqe_wr_id_tbl = kcalloc(qp->sq.max_cnt, sizeof(*qp->wqe_wr_id_tbl), + GFP_KERNEL); if (qp->wqe_wr_id_tbl == NULL) return -ENOMEM; - qp->rqe_wr_id_tbl = - kzalloc(sizeof(u64) * qp->rq.max_cnt, GFP_KERNEL); + qp->rqe_wr_id_tbl = kcalloc(qp->rq.max_cnt, sizeof(*qp->rqe_wr_id_tbl), + GFP_KERNEL); if (qp->rqe_wr_id_tbl == NULL) return -ENOMEM; @@ -1903,8 +1901,9 @@ struct ib_srq *ocrdma_create_srq(struct ib_pd *ibpd, goto err; if (udata == NULL) { - srq->rqe_wr_id_tbl = kzalloc(sizeof(u64) * srq->rq.max_cnt, - GFP_KERNEL); + srq->rqe_wr_id_tbl = kcalloc(srq->rq.max_cnt, + sizeof(*srq->rqe_wr_id_tbl), + GFP_KERNEL); if (srq->rqe_wr_id_tbl == NULL) goto arm_err;