From patchwork Thu Sep 22 08:33:29 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: 9345445 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 94F6960757 for ; Thu, 22 Sep 2016 14:53:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 862952AB4B for ; Thu, 22 Sep 2016 14:53:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A9532AB8E; Thu, 22 Sep 2016 14:53:19 +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 F07442AB4B for ; Thu, 22 Sep 2016 14:53:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3D4126E37E; Thu, 22 Sep 2016 14:53:18 +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 BE5506E37E for ; Thu, 22 Sep 2016 14:53:16 +0000 (UTC) Received: from [192.168.1.2] ([77.182.99.72]) by smtp.web.de (mrweb004) with ESMTPSA (Nemesis) id 0LyOuM-1asHnT3rsc-015n0z; Thu, 22 Sep 2016 10:33:30 +0200 Subject: [PATCH 3/4] GPU-DRM-TILCDC: Less function calls in tilcdc_convert_slave_node() after error detection To: dri-devel@lists.freedesktop.org, David Airlie , Jyri Sarha , Tomi Valkeinen References: <566ABCD9.1060404@users.sourceforge.net> <2f3f7ad7-16a0-1dfb-d073-0d993cd767ee@users.sourceforge.net> From: SF Markus Elfring Message-ID: <0be7fee0-64f7-fa02-0337-51376677343e@users.sourceforge.net> Date: Thu, 22 Sep 2016 10:33:29 +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: <2f3f7ad7-16a0-1dfb-d073-0d993cd767ee@users.sourceforge.net> X-Provags-ID: V03:K0:lRz9v5JdpriNX8nE29V0r9ivFewzZ52ihkrwxD33qRAhboVNxAf jVFATCLYujhEYWGXJDBw4iSBoWMcLCPiyUIr59WhYwTCozlK10nK/jD6yKA+bUcYcB7ueH7 1OS3Is31JMWkrz2IrRo6BEA0yM7OZo1c8tp6RUIKLfnWUkIX0E+dP5jLqol/ssSFFH+sGpR 3tfIAzsXF/2LRXsbpp/fg== X-UI-Out-Filterresults: notjunk:1; V01:K0:rLRE/Bt9qUI=:HVjxR/6yNHikP8mQcXcfku 34QkbBAQCXMIyudJftARFfrK41dQExA9jPgo8B+/zFz6qIDrvigTvGNjTWnb2Jvv6jTBplQjd /LpUcj1UXNbyDcGQN1t+r7KU7zBUUqB6LUpFkv5K/kYQru7cQz6GonATYQVR4jINUIY6aO2KZ gr2tQNKJYMGNnyxxZmH0WGaxevHlU3qbkXsyb989NKJP3PLwIH1HUQNKFfyGyDyex3XRnYY+u EBO9IWxNsyWgxwt2LEn106yP9/x3wZwkgg2GYSWCYKoNB+FRk5v4q3D5gssSsAgplhqWFLWb6 7rJAhHVl16/T3w+Ut+rn72MQbrmxwQs5c4cxIvnViGHyQCqGNpDglyahCbGVwTB16QhF75M+p 24BG/27tjlq8i+cs7kaqhLjCE5AI4SKpUDM6Y7D00A/0Pa+V+KkxlONOBaowm38iRCyBnuKov 47MWBS4RzLardacOp6Pahgrdtg0GschaqJmoPTOK2MHh6lEu5AGl0hEmUkZik54SS3b4U5Uig x86rR6NBdcISEszsJSqjrFNJ/nfTQahI748DO2UoEI6KnhSHPAG08tSvuJFfBJ5JViZjeq8q+ gM6kS8XjMT/g9Zh/rUgp/bhNjHFUpcZy4Qi0IjYtN8BbOj22KELJvSq5AtZezzNlnkHPJq+ue Bk+/VY4H9wYWau2CzeeCd72kOBp0wEbg9AzG71Ui15OCNaj6Tv/mJr97YBD7u6d3bLPebDKvw Qj+qqAxiGB6AgQZQADZM5wkxrrOSgVNMoLtJvOBBUb41qQDow2pl6kEU6YaR4Ke1yYlfLKP38 nFKkR8d 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: Thu, 22 Sep 2016 10:06:50 +0200 The of_node_put() function was called in some cases by the tilcdc_convert_slave_node() 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 resource detection 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 Signed-off-by: Markus Elfring --- drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c b/drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c index 6204405..6ee5865 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_slave_compat.c @@ -209,25 +209,27 @@ void __init tilcdc_convert_slave_node(void) return; lcdc = of_find_matching_node(NULL, tilcdc_of_match); - slave = of_find_matching_node(NULL, tilcdc_slave_of_match); + if (!of_device_is_available(lcdc)) + goto free_table; - if (!slave || !of_device_is_available(lcdc)) - goto out; + slave = of_find_matching_node(NULL, tilcdc_slave_of_match); + if (!slave) + goto put_node_lcdc; i2c = of_parse_phandle(slave, "i2c", 0); if (!i2c) { pr_err("%s: Can't find i2c node trough phandle\n", __func__); - goto out; + goto put_node_slave; } overlay = tilcdc_get_overlay(&kft); if (!overlay) - goto out; + goto put_node_i2c; encoder = of_find_matching_node(overlay, tilcdc_tda998x_of_match); if (!encoder) { pr_err("%s: Failed to find tda998x node\n", __func__); - goto out; + goto put_node_i2c; } tilcdc_copy_props(slave, encoder, tilcdc_slave_props, &kft); @@ -238,10 +240,10 @@ void __init tilcdc_convert_slave_node(void) continue; if (!strncmp("i2c", (char *)prop->value, prop->length)) if (tilcdc_prop_str_update(prop, i2c->full_name, &kft)) - goto out; + goto put_node_fragment; if (!strncmp("lcdc", (char *)prop->value, prop->length)) if (tilcdc_prop_str_update(prop, lcdc->full_name, &kft)) - goto out; + goto put_node_fragment; } tilcdc_node_disable(slave); @@ -252,12 +254,16 @@ void __init tilcdc_convert_slave_node(void) else pr_info("%s: ti,tilcdc,slave node successfully converted\n", __func__); -out: - kfree_table_free(&kft); + put_node_fragment: + of_node_put(fragment); + put_node_i2c: of_node_put(i2c); + put_node_slave: of_node_put(slave); + put_node_lcdc: of_node_put(lcdc); - of_node_put(fragment); + free_table: + kfree_table_free(&kft); } int __init tilcdc_slave_compat_init(void)