[PATCH Resend V2] dt: add helper function to read u8 & u16 variables & arrays

Viresh Kumar viresh.kumar at linaro.org
Wed Nov 7 01:39:04 EST 2012


On 6 November 2012 19:48, Rob Herring <robherring2 at gmail.com> wrote:

> > diff --git a/drivers/of/base.c b/drivers/of/base.c
>


> > +#define of_property_read_array(_np, _pname, _out, _sz)
>       \
> > +     struct property *_prop = of_find_property(_np, _pname, NULL);   \
> > +     const __be32 *_val;                                             \
> > +                                                                     \
> > +     if (!_prop)                                                     \
> > +             return -EINVAL;                                         \
> > +     if (!_prop->value)                                              \
> > +             return -ENODATA;                                        \
> > +     if ((_sz * sizeof(*_out)) > _prop->length)                      \
> > +             return -EOVERFLOW;                                      \
> > +                                                                     \
> > +     _val = _prop->value;                                            \
> > +     while (_sz--)                                                   \
> > +             *_out++ = (typeof(*_out))be32_to_cpup(_val++);          \
>
> This will not work. You are incrementing _out by 1, 2, or 4 bytes, but
> _val is always incremented by 4 bytes.
>
> According to the dtc commit adding this feature, the values are packed:
>
> With this patch the following property assignment:
>
>     property = /bits/ 16 <0x1234 0x5678 0x0 0xffff>;
>
> is equivalent to:
>
>     property = <0x12345678 0x0000ffff>;
>

Something which i haven't expected :(
I will fix and test it well for all types before sending it now.


> > +/**
> > + * of_property_read_u8_array - Find and read an array of u8 from a
> property.
> > + *
> > + * @np:              device node from which the property value is to be
> read.
> > + * @propname:        name of the property to be searched.
> > + * @out_value:       pointer to return value, modified only if return
> value is 0.
> > + *
>
> Missing sz
>

Yes for both misses.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/devicetree-discuss/attachments/20121106/bf5bb48e/attachment-0001.html>


More information about the devicetree-discuss mailing list