[PATCH] Add null pointer check to of_find_property
Timur Tabi
timur at freescale.com
Thu May 8 05:19:59 EST 2008
Update function of_find_property() to return NULL if the device_node passed
to it is also NULL. Otherwise, passing NULL will cause a null pointer
dereference.
Signed-off-by: Timur Tabi <timur at freescale.com>
---
This patch allows callers to do this:
np = of_find_compatible_node(...);
prop = of_get_property(np);
if (!prop)
goto error;
Today, we need a np==NULL check between the two of_ calls. Some callers may
not care whether the node is missing or the property is missing.
drivers/of/base.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 9bd7c4a..23ffb7c 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -65,6 +65,9 @@ struct property *of_find_property(const struct device_node *np,
{
struct property *pp;
+ if (!np)
+ return NULL;
+
read_lock(&devtree_lock);
for (pp = np->properties; pp != 0; pp = pp->next) {
if (of_prop_cmp(pp->name, name) == 0) {
--
1.5.5
More information about the Linuxppc-dev
mailing list