Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1041319AbdDUSZf (ORCPT ); Fri, 21 Apr 2017 14:25:35 -0400 Received: from mout.web.de ([212.227.15.4]:51841 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161710AbdDUSZT (ORCPT ); Fri, 21 Apr 2017 14:25:19 -0400 Subject: [PATCH v2 02/17] IB/mlx: Use kmalloc_array() in six functions From: SF Markus Elfring To: Doug Ledford , Hal Rosenstock , Leon Romanovsky , Majd Dibbiny , Matan Barak , Sean Hefty , Yishai Hadas , linux-rdma@vger.kernel.org Cc: LKML , kernel-janitors@vger.kernel.org References: <1935365a-bd7c-461e-6a84-0c5d3a501fff@users.sourceforge.net> <1492720654.3041.16.camel@redhat.com> Message-ID: Date: Fri, 21 Apr 2017 20:24:37 +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: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:nQuyw6PkD+SK42HDzMrbjCa1NOy9kRAyc9G1qjVXv7Rgf72/zbk ZKqtrXEnv1+T3UYq3SN6EEECuonVW7K6JFBf9POk0BdjtWO23z7O/k4yNKRVEYoEVWSaoCx ZJJS5rGmCTN21nlSryIuoAw1yXvdodE6JLq41+q1W7O9Ig0W7edmO+Ck1H44NBwfv9Dg3lU uDKILl4lfNKzneqs+qDqg== X-UI-Out-Filterresults: notjunk:1;V01:K0:sRhAZbgaAd0=:KJgrSryjAqP5xPX4o9mp12 cFZ9DK/NsQd1GK8ibHJzaL+kC5VAtt5IhCQ/MRHr4O41YE40Kv1j8IY6hdEavx8Qv0iMusk/T Yu8n9fd7X1+yx/pFJ0nmuYxFzYc680HEhzrB2O5DYxr3IP823OqB1j6MPJY0U62chjcnYC810 qVt6ng2bJZ39nCJxP2qylmoUwRI0OJnNPHWsHvvhGhHpxFPIohMdjN/SReT4sbVFxm5SquIRF jf3voQYcj5u6N5P7u99HvvhhQnhQqEHU/2ke2zNYR63kFSdJ4lEdqExrVE1u3JE7ByYaPAc+M RbALnZSsPP/PPWUlLiY9vRDZ1nuZnlnPo89RzwjLuTx3Qzs1+prrQe2GQ8eqkwk2U36ywWaKx xaivOFur6Ig/CcRnWZw4B7tLvHXhy8Za7Lo/YYPFyxu7XaPGdpwHUH/InjE3ZbQsoMTYrZA4v 88a2/D600OKKzjnldyEDwIj4qTrU+qoeiXrShtwD3xUjFuroXrb9JLitRdtRJTqjJVZQ+mmAP xFc9VOpX/605XRVAcXiXyQw7p4+XAfrt+eqP7qynUCafRkJcxV+c9ylXmd7JUtMpblptqvH66 OCpzwhRGowaKnEi3UWWEj9BwZyPS9vRyBTxDUvoCtbupaxTj4M3/OsK3YPOhy6Rd4jorOvfmG Olytx4e491zIXVdvtdaqNf5eMSDh2imfrY166wnUKQED00Q0g5Vg/OmS944TLWa3W5oUtLwnw N9oouQ7IVKCJ6E1QFHTBZt7nJFv3EXHizfQ+kKW3SSMza53OumOBItzFgGAKNG2mxCYs7g3Vx bjNpBdB Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4706 Lines: 132 From: Markus Elfring Date: Fri, 21 Apr 2017 10:45:49 +0200 * Multiplications for the size determination of memory allocations indicated that array data structures should be processed. Thus use the corresponding function "kmalloc_array". This issue was detected by using the Coccinelle software. * Replace the specification of data types by pointer dereferences to make the corresponding size determination 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/mlx4/main.c | 14 +++++++++----- drivers/infiniband/hw/mlx4/qp.c | 6 +++--- drivers/infiniband/hw/mlx5/qp.c | 21 +++++++++++++++------ drivers/infiniband/hw/mlx5/srq.c | 5 +++-- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index fba94df28cf1..30a70fa95fec 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -307,7 +307,9 @@ static int mlx4_ib_add_gid(struct ib_device *device, ctx->refcount++; } if (!ret && hw_update) { - gids = kmalloc(sizeof(*gids) * MLX4_MAX_PORT_GIDS, GFP_ATOMIC); + gids = kmalloc_array(MLX4_MAX_PORT_GIDS, + sizeof(*gids), + GFP_ATOMIC); if (!gids) { ret = -ENOMEM; } else { @@ -362,7 +364,9 @@ static int mlx4_ib_del_gid(struct ib_device *device, if (!ret && hw_update) { int i; - gids = kmalloc(sizeof(*gids) * MLX4_MAX_PORT_GIDS, GFP_ATOMIC); + gids = kmalloc_array(MLX4_MAX_PORT_GIDS, + sizeof(*gids), + GFP_ATOMIC); if (!gids) { ret = -ENOMEM; } else { @@ -2831,9 +2835,9 @@ static void *mlx4_ib_add(struct mlx4_dev *dev) goto err_counter; ibdev->ib_uc_qpns_bitmap = - kmalloc(BITS_TO_LONGS(ibdev->steer_qpn_count) * - sizeof(long), - GFP_KERNEL); + kmalloc_array(BITS_TO_LONGS(ibdev->steer_qpn_count), + sizeof(long), + GFP_KERNEL); if (!ibdev->ib_uc_qpns_bitmap) goto err_steer_qp_release; diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c index c34eebc7db65..1d9d949c66d0 100644 --- a/drivers/infiniband/hw/mlx4/qp.c +++ b/drivers/infiniband/hw/mlx4/qp.c @@ -554,9 +554,9 @@ static int alloc_proxy_bufs(struct ib_device *dev, struct mlx4_ib_qp *qp) { int i; - qp->sqp_proxy_rcv = - kmalloc(sizeof (struct mlx4_ib_buf) * qp->rq.wqe_cnt, - GFP_KERNEL); + qp->sqp_proxy_rcv = kmalloc_array(qp->rq.wqe_cnt, + sizeof(*qp->sqp_proxy_rcv), + GFP_KERNEL); if (!qp->sqp_proxy_rcv) return -ENOMEM; for (i = 0; i < qp->rq.wqe_cnt; i++) { diff --git a/drivers/infiniband/hw/mlx5/qp.c b/drivers/infiniband/hw/mlx5/qp.c index ed6320186f89..1e98a8c9fab8 100644 --- a/drivers/infiniband/hw/mlx5/qp.c +++ b/drivers/infiniband/hw/mlx5/qp.c @@ -959,12 +959,21 @@ static int create_kernel_qp(struct mlx5_ib_dev *dev, goto err_free; } - qp->sq.wrid = kmalloc(qp->sq.wqe_cnt * sizeof(*qp->sq.wrid), GFP_KERNEL); - qp->sq.wr_data = kmalloc(qp->sq.wqe_cnt * sizeof(*qp->sq.wr_data), GFP_KERNEL); - qp->rq.wrid = kmalloc(qp->rq.wqe_cnt * sizeof(*qp->rq.wrid), GFP_KERNEL); - qp->sq.w_list = kmalloc(qp->sq.wqe_cnt * sizeof(*qp->sq.w_list), GFP_KERNEL); - qp->sq.wqe_head = kmalloc(qp->sq.wqe_cnt * sizeof(*qp->sq.wqe_head), GFP_KERNEL); - + qp->sq.wrid = kmalloc_array(qp->sq.wqe_cnt, + sizeof(*qp->sq.wrid), + GFP_KERNEL); + qp->sq.wr_data = kmalloc_array(qp->sq.wqe_cnt, + sizeof(*qp->sq.wr_data), + GFP_KERNEL); + qp->rq.wrid = kmalloc_array(qp->rq.wqe_cnt, + sizeof(*qp->rq.wrid), + GFP_KERNEL); + qp->sq.w_list = kmalloc_array(qp->sq.wqe_cnt, + sizeof(*qp->sq.w_list), + GFP_KERNEL); + qp->sq.wqe_head = kmalloc_array(qp->sq.wqe_cnt, + sizeof(*qp->sq.wqe_head), + GFP_KERNEL); if (!qp->sq.wrid || !qp->sq.wr_data || !qp->rq.wrid || !qp->sq.w_list || !qp->sq.wqe_head) { err = -ENOMEM; diff --git a/drivers/infiniband/hw/mlx5/srq.c b/drivers/infiniband/hw/mlx5/srq.c index 7cb145f9a6db..8ba1953177af 100644 --- a/drivers/infiniband/hw/mlx5/srq.c +++ b/drivers/infiniband/hw/mlx5/srq.c @@ -195,8 +195,9 @@ static int create_srq_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_srq *srq, goto err_buf; } mlx5_fill_page_array(&srq->buf, in->pas); - - srq->wrid = kmalloc(srq->msrq.max * sizeof(u64), GFP_KERNEL); + srq->wrid = kmalloc_array(srq->msrq.max, + sizeof(*srq->wrid), + GFP_KERNEL); if (!srq->wrid) { err = -ENOMEM; goto err_in; -- 2.12.2