From patchwork Sat Feb 18 20:59:51 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: 9581265 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 92B9B604A4 for ; Sat, 18 Feb 2017 21:06:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8315E28618 for ; Sat, 18 Feb 2017 21:06:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7678A2877A; Sat, 18 Feb 2017 21:06:52 +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 1B59328618 for ; Sat, 18 Feb 2017 21:06:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753525AbdBRVGu (ORCPT ); Sat, 18 Feb 2017 16:06:50 -0500 Received: from mout.web.de ([212.227.15.14]:50336 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753492AbdBRVGt (ORCPT ); Sat, 18 Feb 2017 16:06:49 -0500 Received: from [192.168.1.2] ([77.181.107.93]) by smtp.web.de (mrweb001 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MfYXz-1czsYc0n2R-00P6Rv; Sat, 18 Feb 2017 21:59:53 +0100 Subject: [PATCH 11/29] IB/mlx4: Use kmalloc_array() in three functions To: linux-rdma@vger.kernel.org, Doug Ledford , Hal Rosenstock , Leon Romanovsky , Matan Barak , Sean Hefty , Yishai Hadas References: <1935365a-bd7c-461e-6a84-0c5d3a501fff@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: <3002f281-292a-c53e-0b37-d23a3be0d5d7@users.sourceforge.net> Date: Sat, 18 Feb 2017 21:59:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.1 MIME-Version: 1.0 In-Reply-To: <1935365a-bd7c-461e-6a84-0c5d3a501fff@users.sourceforge.net> X-Provags-ID: V03:K0:BspZEWsvXB32tUDZPt8LLjXyt1bzQf0GG0zu05cOXRrGRXZChhp HxDXS2m+WM5ftvU5av9zDCxnpvc/xLpSHOIwwuXevbCLKkkMfv2DtOR0b1bgJuDPP8Je1WE f/AtKOViq5f30KjOs5iuynlISaa9dL1lXW2BlMzw3XRqZdfFlYrnPqJjeeWboakFsrv7paO sh3uK4vizybH/adusmOBg== X-UI-Out-Filterresults: notjunk:1; V01:K0:41CvFi+KVGI=:ijc1vl4BZHtzZDREfVi3SN N62mdIhtj8nPszjPqFVE0eK4I4zWxtSjYOK/WiCp7rwI84FG0t7Sj9d5HocVD9+i37WIsw1aC RGENiso6//i8stNuc7wnHPRxEqiMvODvzs0deUj2H4IGCf+Wq1A2X7th/PPYOp9ZTKO3sz4Sr yrbbaDOYA5/9YZYwZAnLIP5L0L5jrZnaJcoYQvJMLAcbz9vA0LzMIVahr40AIqoP2OuQNXKLl 4VjB/D2LZL78Yw+BmFSE09BRsoHp7vwXxSQHyQnydEI2vXPX1ycch/M2K/PapGbZY0E6XO7hT tdQ+J/iC8SpH4oUCx6gMGZkzr3r4387/p5xd7v0VsLTqr7LuOMDmUwfEVRfZ5cn4Bmtgukzzk 45ZTpQcact6ohZ4ZQhwCnvqamqURSIS+3BQDgSMFaiuM0zNRBQ4FrIl7OAv58VbA7upBpRmkv gkVpEFidPcsZvgfGozC20zNZ721qd1oq+5KpmyMsAlstxHFHYudQzhO3WOayeWCRh9jYjF+ZH PMwVuzCYsWD+nSPm5vyFc8J61HNcvKopJIbqPjouBexSLotz8DSo/LU/uk9kRTmk7wvx+Jk5T Dvg7zoVxMFjgqEEd9vlw9/ABwSALAxm68rn5orp3R67rgs2gmXGZG+8LkvDTTiQ9ZN9dZj4JO ccRq4+KvKZro3Lu+wexfVY0jNEoGu0SYkSCFD//+osUpwe3DqqtsgCEuV1BPOdnIe3/rV3Nvn HOAI5Tcet4IsRDEiIcjDP+8XCBOy61JS26D4rbJ8cPPzN58auCGJu7B9pjXheiRop8eK2CkL1 t7zddhg 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, 18 Feb 2017 10:32:32 +0100 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. Signed-off-by: Markus Elfring Reviewed-by: Majd Dibbiny --- drivers/infiniband/hw/mlx4/main.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c index ba6af84cc236..350c9148340e 100644 --- a/drivers/infiniband/hw/mlx4/main.c +++ b/drivers/infiniband/hw/mlx4/main.c @@ -304,7 +304,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 { @@ -359,7 +361,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 { @@ -2828,9 +2832,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;