From patchwork Thu Feb 16 09:02:58 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: 9576677 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 BDC6160244 for ; Thu, 16 Feb 2017 09:03:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEFE82848E for ; Thu, 16 Feb 2017 09:03:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A27602849B; Thu, 16 Feb 2017 09:03:33 +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.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 4C5E22848E for ; Thu, 16 Feb 2017 09:03:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752688AbdBPJDa (ORCPT ); Thu, 16 Feb 2017 04:03:30 -0500 Received: from mout.web.de ([212.227.17.12]:62595 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752649AbdBPJD2 (ORCPT ); Thu, 16 Feb 2017 04:03:28 -0500 Received: from [192.168.1.2] ([77.181.106.122]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LrK0u-1cF1Hu0Q28-0133mx; Thu, 16 Feb 2017 10:03:10 +0100 Subject: [PATCH 1/2] IB/hns: Use kmalloc_array() in hns_roce_cmd_use_events() To: linux-rdma@vger.kernel.org, Doug Ledford , Hal Rosenstock , Sean Hefty , Wei Hu References: <4863af1d-ca80-1818-213e-7eadda35e8a1@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org From: SF Markus Elfring Message-ID: <362af670-98b7-42f6-1e8d-6ec4818c5943@users.sourceforge.net> Date: Thu, 16 Feb 2017 10:02:58 +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: <4863af1d-ca80-1818-213e-7eadda35e8a1@users.sourceforge.net> X-Provags-ID: V03:K0:2To5cAvW9zU0v8PaeboujFGvpbHQ40nTndqsgvt/mjgovksTQHD vRF0ic4xJu/oetJy0y1dg0OHSRhmW+359gB/X5NpH4Ns7GXX3HI/Xb0SDuzjcjeXWQu8fmt LsizD6Fn20HXyiFUKLlCQJ0ZUgJMfy2XKRU5VfMYnL6bv3THHVKvQIlXJOGA3XxQUfniena NpQMeLx/5/tmhJwX8noOA== X-UI-Out-Filterresults: notjunk:1; V01:K0:awRCK6nMFyk=:FJ4ckGKk2lJGdmAJ0dG6kq xGbuFwOXknZ6oXUc74I8eTIcxuYGWH0zTTtAM2YHpdIVHNTwYOLl6/vYGv2xy6NPhrY+5f6Kw neFL7qZoINc/kY1ZBqB+0IR1BqEoou3Sd/hraJBy9asujymOcKP/7y2XDEugSdYsfHTCt7B9P S9cNbtHeeGAlNA3PPQeGMTEC732ja7rvmkzZCxF0RhSLT06Om8NxUcnbfFUqq2m8LViakdVWb 0tGlFYeWa+VsZdUH1RpavnNKDV9JfrAe/DDSBBIdtad0+HVDrrYNMaI14QQ2vbTFNtMJIXF1c rcFutvnHeEQ42PAhlrizYv1HvuTN1kvBaepyH8Y0ssdswAL8wQAaXlg88FfmHpGIqDY/xEXcE oTc5TA6K77e34OlUe4Dq76N5mOr3t8IRyY+B8HPd8xQoVR2U3Vffcl3jcPw+PG6vkinPIh4nC grZk7EdvCiLJlh5bLoNlZqCZbG1MOBAnaGwwCeksZ20KGfFA8+cBjAOdN32xdUpBX56DDiqYl DD49QW69Pby4KLUdbXx1CQSgkc/oHjPGtL8T7Pj9OwG2lzkpJINTHiAQxG+EaXYA2Tqp8UojT 3wBCi0EwSMuIKEclCR8Nha7pVEiQgaqVN8Vi2/8hvCP5zwjtvijPvZX80Ho9UY/2UPC0xI/ba ReRHaHXQfQBp+tb49Ajusuw+7SHGhZ35CHGNnGyocecRcRtrVHM6Gx1D5ba7a12H/5aY6SW2f iwjRsyLxC/opkWpdrCxf6wDILozGgwLFO0d/4ZiUAGjWp54uL1172g49Ltphms8N1dCkek0me RhQ63Bq 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: Thu, 16 Feb 2017 08:50:11 +0100 * A multiplication for the size determination of a memory allocation indicated that an array data structure should be processed. Thus use the corresponding function "kmalloc_array". This issue was detected by using the Coccinelle software. * Replace the specification of a data structure by a pointer dereference to make the corresponding size determination a bit safer according to the Linux coding style convention. Signed-off-by: Markus Elfring --- drivers/infiniband/hw/hns/hns_roce_cmd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_cmd.c b/drivers/infiniband/hw/hns/hns_roce_cmd.c index 8c1f7a6f84d2..b94dcd823ad1 100644 --- a/drivers/infiniband/hw/hns/hns_roce_cmd.c +++ b/drivers/infiniband/hw/hns/hns_roce_cmd.c @@ -299,9 +299,9 @@ int hns_roce_cmd_use_events(struct hns_roce_dev *hr_dev) struct hns_roce_cmdq *hr_cmd = &hr_dev->cmd; int i; - hr_cmd->context = kmalloc(hr_cmd->max_cmds * - sizeof(struct hns_roce_cmd_context), - GFP_KERNEL); + hr_cmd->context = kmalloc_array(hr_cmd->max_cmds, + sizeof(*hr_cmd->context), + GFP_KERNEL); if (!hr_cmd->context) return -ENOMEM;