From patchwork Thu Oct 15 05:56:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 530509 X-Patchwork-Delegate: agust@denx.de Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DDC51401F0 for ; Thu, 15 Oct 2015 16:57:42 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3233B1A09DA for ; Thu, 15 Oct 2015 16:57:42 +1100 (AEDT) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from smtp.smtpout.orange.fr (smtp07.smtpout.orange.fr [80.12.242.129]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 28A6B1A0491 for ; Thu, 15 Oct 2015 16:56:36 +1100 (AEDT) Received: from localhost.localdomain ([92.140.185.80]) by mwinf5d14 with ME id VHwP1r00M1kW4pY03HwPz8; Thu, 15 Oct 2015 07:56:31 +0200 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Thu, 15 Oct 2015 07:56:31 +0200 X-ME-IP: 92.140.185.80 From: Christophe JAILLET To: benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au Subject: [PATCH v2] powerpc/mpc5xxx: Avoid dereferencing potentially freed memory Date: Thu, 15 Oct 2015 07:56:20 +0200 Message-Id: <1444888580-12966-1-git-send-email-christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.1.4 In-Reply-To: <20151014040011.8AB1514110A@ozlabs.org> References: <20151014040011.8AB1514110A@ozlabs.org> X-Antivirus: avast! (VPS 151014-0, 14/10/2015), Outbound message X-Antivirus-Status: Clean X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kernel-janitors@vger.kernel.org, Christophe JAILLET , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Use 'of_property_read_u32()' instead of 'of_get_property()'+pointer dereference in order to avoid access to potentially freed memory. Use 'of_get_next_parent()' to simplify the while() loop and avoid the need of a temp variable. Signed-off-by: Christophe JAILLET --- v2: Use of_property_read_u32 instead of of_get_property+pointer dereference *** Untested *** --- arch/powerpc/sysdev/mpc5xxx_clocks.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/powerpc/sysdev/mpc5xxx_clocks.c b/arch/powerpc/sysdev/mpc5xxx_clocks.c index f4f0301..92fbcf8 100644 --- a/arch/powerpc/sysdev/mpc5xxx_clocks.c +++ b/arch/powerpc/sysdev/mpc5xxx_clocks.c @@ -13,21 +13,17 @@ unsigned long mpc5xxx_get_bus_frequency(struct device_node *node) { - struct device_node *np; - const unsigned int *p_bus_freq = NULL; + u32 bus_freq = 0; of_node_get(node); while (node) { - p_bus_freq = of_get_property(node, "bus-frequency", NULL); - if (p_bus_freq) + if (!of_property_read_u32(node, "bus-frequency", &bus_freq)) break; - np = of_get_parent(node); - of_node_put(node); - node = np; + node = of_get_next_parent(node); } of_node_put(node); - return p_bus_freq ? *p_bus_freq : 0; + return bus_freq; } EXPORT_SYMBOL(mpc5xxx_get_bus_frequency);