Re: [PATCH v1 2/2] device property: Don't check for NULL twice in the loops

From: Rafael J. Wysocki
Date: Mon May 10 2021 - 10:55:12 EST


On Mon, May 10, 2021 at 11:57 AM Andy Shevchenko
<andy.shevchenko@xxxxxxxxx> wrote:
>
> In fwnode_get_next_available_child_node() we check next_child for NULL
> twice. All the same in fwnode_get_next_parent_dev() we may avoid checking
> fwnode for NULL twice.
>
> Signed-off-by: Andy Shevchenko <andy.shevchenko@xxxxxxxxx>
> ---
> drivers/base/property.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/base/property.c b/drivers/base/property.c
> index dd98759d688b..62285f1b79e3 100644
> --- a/drivers/base/property.c
> +++ b/drivers/base/property.c
> @@ -632,9 +632,10 @@ struct device *fwnode_get_next_parent_dev(struct fwnode_handle *fwnode)
> fwnode_handle_get(fwnode);
> do {
> fwnode = fwnode_get_next_parent(fwnode);
> - if (fwnode)
> - dev = get_dev_from_fwnode(fwnode);
> - } while (fwnode && !dev);
> + if (!fwnode)
> + break;

I would return NULL from here right away.

> + dev = get_dev_from_fwnode(fwnode);
> + } while (!dev);
> fwnode_handle_put(fwnode);
> return dev;
> }
> @@ -742,10 +743,9 @@ fwnode_get_next_available_child_node(const struct fwnode_handle *fwnode,
>
> do {
> next_child = fwnode_get_next_child_node(fwnode, next_child);
> -
> - if (!next_child || fwnode_device_is_available(next_child))
> + if (!next_child)
> break;

And from here too.

> - } while (next_child);
> + } while (!fwnode_device_is_available(next_child));
>
> return next_child;
> }
> --
> 2.31.1
>