From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S938542AbcIUQk7 (ORCPT ); Wed, 21 Sep 2016 12:40:59 -0400 Received: from mout.web.de ([212.227.15.4]:50367 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934263AbcIUQk4 (ORCPT ); Wed, 21 Sep 2016 12:40:56 -0400 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> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall 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> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit 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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- 2.10.0