Re: [PATCH v2 03/16] ACPI: property: Rework acpi_graph_get_next_endpoint()

Sakari Ailus
2025-09-26T11:49:55Z

Hi Laurent,

Thank you for the review.

On Wed, Sep 24, 2025 at 12:39:34PM +0300, Laurent Pinchart wrote:
> Hi Sakari,
>
> On Wed, Sep 24, 2025 at 10:45:49AM +0300, Sakari Ailus wrote:
> > Rework the code obtaining the next endpoint in
> > acpi_graph_get_next_endpoint(). The resulting code removes unnecessary
> > contitionals and should be easier to follow.
> >
> > Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
> > ---
> > drivers/acpi/property.c | 13 +++++++------
> > 1 file changed, 7 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
> > index 3e85900080ac..5438592dc136 100644
> > --- a/drivers/acpi/property.c
> > +++ b/drivers/acpi/property.c
> > @@ -1399,14 +1399,15 @@ static struct fwnode_handle *acpi_graph_get_next_endpoint(
> > if (!port)
> > return NULL;
> >
> > - endpoint = acpi_get_next_subnode(port, prev);
> > - while (!endpoint) {
> > - port = acpi_get_next_subnode(fwnode, port);
> > - if (!port)
> > + do {
> > + endpoint = acpi_get_next_subnode(port, prev);
> > + if (endpoint)
> > break;
> > +
> > + port = acpi_get_next_subnode(fwnode, port);
> > if (is_acpi_graph_node(port, "port"))
> > - endpoint = acpi_get_next_subnode(port, NULL);
> > - }
> > + prev = NULL;
>
> Isn't there an issue here ? If the next subnode of fwnode is not a port,
> the next iteration of the do loop will attempt to get an endpoint from
> that non-port node. Maybe the acpi_get_next_subnode() that will try to
> get the endpoint from the non-port port will return NULL because prev
> won't be a child of port, but that seems fragile.
>
> I think the following would be easier to understand:
>
> do {
> endpoint = acpi_get_next_subnode(port, prev);
> if (endpoint)
> break;
>
> prev = NULL;
>
> do {
> port = acpi_get_next_subnode(fwnode, port);
> } while (port && !is_acpi_graph_node(port, "port"));
> } while (port);

Yes, this indeed ensures port will be a port node. I'll use this in the
next version.

>
> > + } while (port);
> >
> > /*
> > * The names of the endpoint nodes begin with "endpoint@" followed by
> >
>

--
Regards,

Sakari Ailus