From patchwork Wed Sep 21 16:40:46 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: 9343879 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 130486077A for ; Wed, 21 Sep 2016 16:40:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E8B52A76A for ; Wed, 21 Sep 2016 16:40:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F2AE22A7F0; Wed, 21 Sep 2016 16:40:55 +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 870FF2A76A for ; Wed, 21 Sep 2016 16:40:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BD9D6892F3; Wed, 21 Sep 2016 16:40:54 +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.15.4]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9CDAA892F3 for ; Wed, 21 Sep 2016 16:40:53 +0000 (UTC) Received: from [192.168.1.2] ([77.182.212.253]) by smtp.web.de (mrweb004) with ESMTPSA (Nemesis) id 0MXSg2-1bRKFl1yli-00WSCM; Wed, 21 Sep 2016 18:40:47 +0200 Subject: [PATCH 03/14] GPU-DRM-OMAP: Less function calls in tiler_map_show() after error detection To: dri-devel@lists.freedesktop.org, David Airlie , Laurent Pinchart , Tomi Valkeinen References: <566ABCD9.1060404@users.sourceforge.net> <0ea38611-3d93-0ade-a1fb-f8cc2e0b8d61@users.sourceforge.net> From: SF Markus Elfring Message-ID: <0818f5f2-2acc-cadd-2a60-44f424cd6149@users.sourceforge.net> Date: Wed, 21 Sep 2016 18:40:46 +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: <0ea38611-3d93-0ade-a1fb-f8cc2e0b8d61@users.sourceforge.net> X-Provags-ID: V03:K0:y81x0YGD+DSe2hcByA709SbGKZd67hDAVK+h4x+qFBLlQVIm9RE Eq9XIf/8w6vcRfSIqAFRb9zlqmc4Zym4ausNwPKAE13QTDA0HRxqlB3+9tUFgKrD9+y9DeW MSwYEtdTgXWGc8Lo+O5cV8zsr4Ttjc4CRWw+GGnaBwHKwbsaakWB1T1OlJMjF7WQcKk+LaA R7dpjDIzeonXbLGSE255A== X-UI-Out-Filterresults: notjunk:1; V01:K0:bhtOYzP8D+Y=:hINJa82meeT+pe8ohZixYI fOvOdryQ4SpjJE9GGsM6vXE/wZOxCDpMhDRmAHKbEAZovqzP9aGRW2Gtrs0hG5OaWd+XJDLeA vBK4PpOO+d1G1N0yIA3JKGY5sPPHEuwfCa/tDrhwEm+Uw75C9JL7/RGesjsNre9LAq0rQYjmk h2zf+wohhDIircMqDNHEsjGxBzGbP3sw4wEQwH2SYSMglmZqlhw2nTBk6lvu1X+vlymtkRQYI ztIuvBJvSMizkB/XAc6qaPBEnr0UM9VnLA30ESX5pp3TRjDS6MLnMaJwYv4gVfABXelt7os22 K+WcWhMGenTtZIpcnhrKkR+LVcFbJuZgYtgvvh3FdjTyMSyQEJr7t8kgMHB3Ft9Mf8/m0SlJJ sNdh9HaPETen6HtflcJKMKvwKkClJ3tgzthMUxOlT+7jrA2gnE54M4F8krkliMQ1snEE6k85c PISdrbaodFcYUpHEnT0HJzPLEG4JjLz6bsfCtp6SeKti4lTzrNoXxds8wuNX33/Tv+YVxav6b dAzN7kgk7UQA8HlQCXuy3+pTGeE3lyJj8J9qoMfVMkJcVyUe9et+3ihu7A/vMDWwvKHIjsGAL r7FKwv6svd1wIMv7UKBWO1TJEcE1DU6zMBD+vgvr3VD2xPKWP1pnIuNVDJ1L3kH4c6qC8mGAu KfMFTFfFoj1AZwI9T6B9ImkEv9P4zUVdKJvhcwGJR5C2oxThmSmht94gpXqPyaWW3pUeMvVP9 YsAcGIy4mU2OFxECDdHbJAW/gUI2wm+HiYm7gcgTbHoUHnZBfYxT0N8KhKazlmx/3T9RvWM77 bvk0Xm3 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 13:16:20 +0200 The kfree() function was called in up to two cases by the tiler_map_show() function during error handling even if the passed variable contained a null pointer. * Adjust jump targets according to the Linux coding style convention. * Split a condition check for memory allocation failures so that each pointer from these function calls will be checked immediately. See also background information: Topic "CWE-754: Improper check for unusual or exceptional conditions" Link: https://cwe.mitre.org/data/definitions/754.html * Return directly after a call of the function "kmalloc_array" failed at the beginning. * Move an assignment for the local variable "w_adj" behind the first memory allocation. Signed-off-by: Markus Elfring --- drivers/gpu/drm/omapdrm/omap_dmm_tiler.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c index 3a4f91b..60beeb9 100644 --- a/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c +++ b/drivers/gpu/drm/omapdrm/omap_dmm_tiler.c @@ -916,11 +916,14 @@ int tiler_map_show(struct seq_file *s, void *arg) } h_adj = omap_dmm->container_height / ydiv; - w_adj = omap_dmm->container_width / xdiv; map = kmalloc_array(h_adj, sizeof(*map), GFP_KERNEL); + if (!map) + return 0; + + w_adj = omap_dmm->container_width / xdiv; global_map = kmalloc_array(h_adj, w_adj + 1, GFP_KERNEL); - if (!map || !global_map) - goto error; + if (!global_map) + goto free_map; for (lut_idx = 0; lut_idx < omap_dmm->num_lut; lut_idx++) { memset(map, 0, h_adj * sizeof(*map)); @@ -982,10 +985,9 @@ int tiler_map_show(struct seq_file *s, void *arg) } } -error: - kfree(map); kfree(global_map); - + free_map: + kfree(map); return 0; } #endif