From patchwork Thu Sep 22 06:20:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9345761 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 565F16077A for ; Thu, 22 Sep 2016 16:06:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 464372AB72 for ; Thu, 22 Sep 2016 16:06:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AFD12ABA8; Thu, 22 Sep 2016 16:06:09 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C34772AB72 for ; Thu, 22 Sep 2016 16:06:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F1D1F6E8CE; Thu, 22 Sep 2016 16:06:07 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mout.web.de (mout.web.de [212.227.17.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id D31FD6E8CE for ; Thu, 22 Sep 2016 16:06:05 +0000 (UTC) Received: from [192.168.1.2] ([77.182.99.72]) by smtp.web.de (mrweb101) with ESMTPSA (Nemesis) id 0MXpdL-1bR7Ws0ADf-00Wmge; Thu, 22 Sep 2016 08:20:13 +0200 Subject: [PATCH 1/4] GPU-DRM-QXL: Use kmalloc_array() in qxl_device_init() To: dri-devel@lists.freedesktop.org, Bhaktipriya Shridhar , Daniel Vetter , David Airlie , =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= , Tejun Heo , Thierry Reding References: From: SF Markus Elfring Message-ID: <269141d5-6562-3d70-b823-283ecde6e09c@users.sourceforge.net> Date: Thu, 22 Sep 2016 08:20:11 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: X-Provags-ID: V03:K0:6K7Y0JPFK53cLQeF+vjZaAs4e7Krk0w5SCmcCK1oyenNBoZu9pJ phM0VSER913mPvPAFtWVotTKXiprkx7ITx6i2cEHOUVoGPA/ye2EW+wvlZmjisepGbpUCh3 hpyvMrBJmPKFnkkToS016yqgNVLVQw2e/PE1/4oYPgt4WYwqjrLXZwAuZGfDZkg//KcCXdD v5YXX4V4zVrr9fL1OlCGA== X-UI-Out-Filterresults: notjunk:1; V01:K0:KoLwMFL4u+U=:vwjpx/Kh2tMw+6pXFzaGmP dZoHAFi8nsRyuzdN7OjYRAbzIDBH2cSepfQqYQlbP+vvH44GyTPtsG6LgqyQy05D58jgkXzbS erWdQljPSu4bFZF/ejkUh27Q3U+cmKYGT5YPLgC8KOn1KNeYTxhkdRHS8MbT7xOcdGF5YUlmY IgV+3QYlL2q7eSmAnAW3ZBFjwIONFoOt8uK5e+AjVChJ4Fo11sqAnotOmUiULlFBtWUMnMjgH ULnRgjsSwzFgozxEJY4rLDnhth2jN5mi/EGd5mdtypVi0r4y9TGHvKIw6be1pd+sEASaNcCFk WUDsW9GRYRqKRVdYePy3Jp3YSwHnLYkt6pQXQt1PD8AkTHDD0VmtrD1Ln8C5VHawOPBF9D1EW FFyyu4y4+eeqHkmXhHK7agX/qx0kZh84HwDsZoaUie525pGw13uZZTtOkRQU7BhoNkiMEXH3s RAZMg4fSjp/zGv9aTPa/QcSPJdEQdbG90Pcx0fYaFrJSO653IBWvebzTLdnJ5bYDcFAconVGu can2uLUjDJkzIbYp9vTSp3Bv8YdEg4wFpt6Xi06sVbQwipnxcsnu4z3Xwze82hVGtTRnbZt6G v8FtoF/4amMt2UxidG6DQGLHNbn33FpEZlHs9HeFw1dKGnimoi4xRqDjbucAoHm/0F1dF4QfB O0sZZtLSWgIxncrOy8n59POPTBJVPqROaMflWIXsD+KqY+dGiscUZnD09otSt7PnmM6vCSmHC cCMG5taUbBxuhqewBakl5ZF3w4qgebe8Ov8cPYVOXxIOVffKJGcnIhsghvS8ljrKg7PvaG2jK jDDZ5mE Cc: Julia Lawall , kernel-janitors@vger.kernel.org, LKML X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Wed, 21 Sep 2016 22:26:08 +0200 * 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. * Add a bit of exception handling for a detected null pointer. Signed-off-by: Markus Elfring --- drivers/gpu/drm/qxl/qxl_kms.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/qxl/qxl_kms.c b/drivers/gpu/drm/qxl/qxl_kms.c index e642242..76852f1 100644 --- a/drivers/gpu/drm/qxl/qxl_kms.c +++ b/drivers/gpu/drm/qxl/qxl_kms.c @@ -216,10 +216,11 @@ static int qxl_device_init(struct qxl_device *qdev, qdev->slot_id_bits = qdev->rom->slot_id_bits; qdev->va_slot_mask = (~(uint64_t)0) >> (qdev->slot_id_bits + qdev->slot_gen_bits); - - qdev->mem_slots = - kmalloc(qdev->n_mem_slots * sizeof(struct qxl_memslot), - GFP_KERNEL); + qdev->mem_slots = kmalloc_array(qdev->n_mem_slots, + sizeof(*qdev->mem_slots), + GFP_KERNEL); + if (!qdev->mem_slots) + return -ENOMEM; idr_init(&qdev->release_idr); spin_lock_init(&qdev->release_idr_lock);