Re: [PATCH 1/2] of: property: add of_property_for_each_u64

From: Luca Ceresoli
Date: Wed Jul 03 2024 - 06:57:54 EST


Hello Peng,

On Fri, 28 Jun 2024 16:16:17 +0200
Luca Ceresoli <luca.ceresoli@xxxxxxxxxxx> wrote:

[...]

> > > > > +#define of_property_for_each_u64(np, propname, prop, p, u) \
> > > > > + for (prop = of_find_property(np, propname, NULL), \
> > > > > + p = of_prop_next_u64(prop, NULL, &u); \
> > > > > + p; \
> > > > > + p = of_prop_next_u64(prop, p, &u))
> > > >
> > > > I think we want to define this differently to avoid exposing struct
> > > > property and the property data directly. Like this:
> > > >
> > > > #define of_property_for_each_u64(np, propname, u) \
> > > > for (struct property *_prop = of_find_property(np, propname, NULL),
> > > > const __be32 *_p = of_prop_next_u64(_prop, NULL, &u);
> > > > _p;
> > > > _p = of_prop_next_u64(_prop, _p, &u))
> >
> > This will trigger a compilation error, because C not allow
> > declare two variables with different types as for loop expression 1.
> > Need to think about other methods.
>
> I have a working draft here where I solved it somehow, let me just find
> the proper branch and send it. Perhaps next week, but I'm striving to do
> that by Mon-Tue.

Ok, that slipped to Wednesday, but here it is:
https://lore.kernel.org/all/20240703-of_property_for_each_u32-v1-1-42c1fc0b82aa@xxxxxxxxxxx/

I think you can reuse the technique I used in that patch to write
of_property_for_each_u64(np, propname, u), taking only 3 parameters.

Luca

--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com