[PATCH] Add null pointer check to of_find_property

Grant Likely grant.likely at secretlab.ca
Thu May 8 05:27:28 EST 2008


On Wed, May 7, 2008 at 1:19 PM, Timur Tabi <timur at 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 at freescale.com>
Acked-by: Grant Likely <grant.likely at 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 at ozlabs.org
>  https://ozlabs.org/mailman/listinfo/linuxppc-dev
>



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



More information about the Linuxppc-dev mailing list