[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240129114450.000061f6@Huawei.com>
Date: Mon, 29 Jan 2024 11:44:50 +0000
From: Jonathan Cameron <Jonathan.Cameron@...wei.com>
To: Julia Lawall <julia.lawall@...ia.fr>
CC: David Lechner <dlechner@...libre.com>, Jonathan Cameron
<jic23@...nel.org>, <linux-iio@...r.kernel.org>, Rob Herring
<robh@...nel.org>, Frank Rowand <frowand.list@...il.com>,
<linux-kernel@...r.kernel.org>, Nicolas Palix <nicolas.palix@...g.fr>,
"Sumera Priyadarsini" <sylphrenadin@...il.com>, "Rafael J . Wysocki"
<rafael@...nel.org>, Len Brown <lenb@...nel.org>,
<linux-acpi@...r.kernel.org>, Andy Shevchenko
<andriy.shevchenko@...ux.intel.com>, Greg Kroah-Hartman
<gregkh@...uxfoundation.org>, Nuno Sá <nuno.sa@...log.com>
Subject: Re: [RFC PATCH 2/5] of: Introduce for_each_child_of_node_scoped()
to automate of_node_put() handling
On Mon, 29 Jan 2024 07:54:57 +0100 (CET)
Julia Lawall <julia.lawall@...ia.fr> wrote:
> On Sun, 28 Jan 2024, David Lechner wrote:
>
> > On Sun, Jan 28, 2024 at 10:06 AM Jonathan Cameron <jic23@...nelorg> wrote:
> > >
> > > From: Jonathan Cameron <Jonathan.Cameron@...wei.com>
> > >
> > > To avoid issues with out of order cleanup, or ambiguity about when the
> > > auto freed data is first instantiated, do it within the for loop definition.
> > >
> > > The disadvantage is that the struct device_node *child variable creation
> > > is not immediately obvious where this is used.
> > > However, in many cases, if there is another definition of
> > > struct device_node *child; the compiler / static analysers will notify us
> > > that it is unused, or uninitialized.
> > >
> > > Signed-off-by: Jonathan Cameron <Jonathan.Cameron@...wei.com>
> > > ---
> > > include/linux/of.h | 6 ++++++
> > > 1 file changed, 6 insertions(+)
> > >
> > > diff --git a/include/linux/of.h b/include/linux/of.h
> > > index 50e882ee91da..f822226eac6d 100644
> > > --- a/include/linux/of.h
> > > +++ b/include/linux/of.h
> > > @@ -1434,6 +1434,12 @@ static inline int of_property_read_s32(const struct device_node *np,
> > > for (child = of_get_next_available_child(parent, NULL); child != NULL; \
> > > child = of_get_next_available_child(parent, child))
> > >
> > > +#define for_each_child_of_node_scoped(parent, child) \
> > > + for (struct device_node *child __free(device_node) = \
> > > + of_get_next_child(parent, NULL); \
> > > + child != NULL; \
> > > + child = of_get_next_available_child(parent, child))
> >
> > Doesn't this need to match the initializer (of_get_next_child)?
> > Otherwise it seems like the first node could be a disabled node but no
> > other disabled nodes would be included in the iteration.
> >
> > It seems like we would want two macros, one for each variation,
> > analogous to for_each_child_of_node() and
> > for_each_available_child_of_node().
>
> There are a bunch of iterators, and I guess a scoped version is needed for
> each of them?
Yes. I just didn't want to add too much to the RFC. I'd want to
convert a user of each as part of the patch set introducing the new
loop definitions.
Jonathan
>
> julia
>
>
> >
> >
> > > +
> > > #define for_each_of_cpu_node(cpu) \
> > > for (cpu = of_get_next_cpu_node(NULL); cpu != NULL; \
> > > cpu = of_get_next_cpu_node(cpu))
> > > --
> > > 2.43.0
> > >
> > >
> >
Powered by blists - more mailing lists