From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr> Subject: [PATCH v2] powerpc/mpc5xxx: Avoid dereferencing potentially freed memory Date: Thu, 15 Oct 2015 07:56:20 +0200 [thread overview] Message-ID: <1444888580-12966-1-git-send-email-christophe.jaillet@wanadoo.fr> (raw) In-Reply-To: <20151014040011.8AB1514110A@ozlabs.org> 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 <christophe.jaillet@wanadoo.fr> --- 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); -- 2.1.4
WARNING: multiple messages have this Message-ID (diff)
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr> To: benh@kernel.crashing.org, paulus@samba.org, mpe@ellerman.id.au Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET <christophe.jaillet@wanadoo.fr> Subject: [PATCH v2] powerpc/mpc5xxx: Avoid dereferencing potentially freed memory Date: Thu, 15 Oct 2015 05:56:20 +0000 [thread overview] Message-ID: <1444888580-12966-1-git-send-email-christophe.jaillet@wanadoo.fr> (raw) In-Reply-To: <20151014040011.8AB1514110A@ozlabs.org> 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 <christophe.jaillet@wanadoo.fr> --- 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); -- 2.1.4
next prev parent reply other threads:[~2015-10-15 5:56 UTC|newest] Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-10-11 20:27 [PATCH] powerpc/mpc5xxx: Use of_get_next_parent to simplify code Christophe JAILLET 2015-10-11 20:27 ` Christophe JAILLET 2015-10-11 20:44 ` Julia Lawall 2015-10-11 20:44 ` Julia Lawall 2015-10-12 5:05 ` Christophe JAILLET 2015-10-12 5:05 ` Christophe JAILLET 2015-10-14 4:00 ` Michael Ellerman 2015-10-14 4:00 ` Michael Ellerman 2015-10-15 5:56 ` Christophe JAILLET [this message] 2015-10-15 5:56 ` [PATCH v2] powerpc/mpc5xxx: Avoid dereferencing potentially freed memory Christophe JAILLET 2015-10-15 6:36 ` Michael Ellerman 2015-10-15 6:36 ` Michael Ellerman 2015-10-15 6:36 ` Michael Ellerman 2015-10-16 6:20 ` Christophe JAILLET 2015-10-16 6:20 ` Christophe JAILLET 2015-10-16 7:15 ` Gabriel Paubert 2015-10-16 7:15 ` Gabriel Paubert 2015-10-16 9:49 ` Michael Ellerman 2015-10-16 9:49 ` Michael Ellerman 2015-10-16 9:49 ` Michael Ellerman 2015-10-16 20:05 ` Christophe JAILLET 2015-10-16 20:05 ` Christophe JAILLET 2015-10-19 4:38 ` Michael Ellerman 2015-10-19 4:38 ` Michael Ellerman 2015-10-19 4:38 ` Michael Ellerman 2015-10-15 11:11 ` powerpc/mpc5xxx: Use of_get_next_parent to simplify code Michael Ellerman 2015-10-15 11:11 ` Michael Ellerman
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1444888580-12966-1-git-send-email-christophe.jaillet@wanadoo.fr \ --to=christophe.jaillet@wanadoo.fr \ --cc=benh@kernel.crashing.org \ --cc=kernel-janitors@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linuxppc-dev@lists.ozlabs.org \ --cc=mpe@ellerman.id.au \ --cc=paulus@samba.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.