linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Add null pointer check to of_find_property
@ 2008-05-07 19:19 Timur Tabi
  2008-05-07 19:27 ` Grant Likely
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Timur Tabi @ 2008-05-07 19:19 UTC (permalink / raw)
  To: linuxppc-dev, paulus

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@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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add null pointer check to of_find_property
  2008-05-07 19:19 [PATCH] Add null pointer check to of_find_property Timur Tabi
@ 2008-05-07 19:27 ` Grant Likely
  2008-05-07 23:21 ` Michael Ellerman
  2008-05-12 16:46 ` Timur Tabi
  2 siblings, 0 replies; 5+ messages in thread
From: Grant Likely @ 2008-05-07 19:27 UTC (permalink / raw)
  To: Timur Tabi; +Cc: linuxppc-dev, paulus

On Wed, May 7, 2008 at 1:19 PM, Timur Tabi <timur@freescale.com> wrote:
> 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@freescale.com>
Acked-by: Grant Likely <grant.likely@secretlab.ca>

>  ---
>
>  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
>
>  _______________________________________________
>  Linuxppc-dev mailing list
>  Linuxppc-dev@ozlabs.org
>  https://ozlabs.org/mailman/listinfo/linuxppc-dev
>



-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add null pointer check to of_find_property
  2008-05-07 19:19 [PATCH] Add null pointer check to of_find_property Timur Tabi
  2008-05-07 19:27 ` Grant Likely
@ 2008-05-07 23:21 ` Michael Ellerman
  2008-05-09  4:50   ` Paul Mackerras
  2008-05-12 16:46 ` Timur Tabi
  2 siblings, 1 reply; 5+ messages in thread
From: Michael Ellerman @ 2008-05-07 23:21 UTC (permalink / raw)
  To: Timur Tabi; +Cc: linuxppc-dev, paulus

[-- Attachment #1: Type: text/plain, Size: 729 bytes --]

On Wed, 2008-05-07 at 14:19 -0500, Timur Tabi wrote:
> 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@freescale.com>
> ---
> 
> This patch allows callers to do this:

np = of_find_compatible_node(...);
prop = of_get_property(np);
if (!prop)
     goto error;

...

error:
 of_node_put(np)

:)

cheers

-- 
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add null pointer check to of_find_property
  2008-05-07 23:21 ` Michael Ellerman
@ 2008-05-09  4:50   ` Paul Mackerras
  0 siblings, 0 replies; 5+ messages in thread
From: Paul Mackerras @ 2008-05-09  4:50 UTC (permalink / raw)
  To: michael; +Cc: linuxppc-dev, Timur Tabi

Michael Ellerman writes:

> On Wed, 2008-05-07 at 14:19 -0500, Timur Tabi wrote:
> > 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@freescale.com>
> > ---
> > 
> > This patch allows callers to do this:
> 
> np = of_find_compatible_node(...);
> prop = of_get_property(np);
> if (!prop)
>      goto error;
> 
> ...
> 
> error:
>  of_node_put(np)
> 
> :)

And of_node_put looks like this:

void of_node_put(struct device_node *node)
{
        if (node)
                kref_put(&node->kref, of_node_release);
}

so it's OK.

:)

Paul.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Add null pointer check to of_find_property
  2008-05-07 19:19 [PATCH] Add null pointer check to of_find_property Timur Tabi
  2008-05-07 19:27 ` Grant Likely
  2008-05-07 23:21 ` Michael Ellerman
@ 2008-05-12 16:46 ` Timur Tabi
  2 siblings, 0 replies; 5+ messages in thread
From: Timur Tabi @ 2008-05-12 16:46 UTC (permalink / raw)
  To: paulus; +Cc: linuxppc-dev

Timur Tabi wrote:
> 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@freescale.com>

Paul, please pick this up for 2.6.26.  The legacy_serial driver will crash
without it if there's no 'chosen' node in the device tree.  I'm sure there are
other drivers that would crash similarly if given a device tree with missing nodes.

-- 
Timur Tabi
Linux kernel developer at Freescale

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-05-12 16:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-07 19:19 [PATCH] Add null pointer check to of_find_property Timur Tabi
2008-05-07 19:27 ` Grant Likely
2008-05-07 23:21 ` Michael Ellerman
2008-05-09  4:50   ` Paul Mackerras
2008-05-12 16:46 ` Timur Tabi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).