[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJZ5v0iLp7R6NC6CkV1hoDADGk9kETb3bO=8vbQCc=J2tDuoeA@mail.gmail.com>
Date: Mon, 10 May 2021 16:53:15 +0200
From: "Rafael J. Wysocki" <rafael@...nel.org>
To: Andy Shevchenko <andy.shevchenko@...il.com>
Cc: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
"Rafael J. Wysocki" <rafael@...nel.org>
Subject: Re: [PATCH v1 2/2] device property: Don't check for NULL twice in the loops
On Mon, May 10, 2021 at 11:57 AM Andy Shevchenko
<andy.shevchenko@...il.com> 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@...il.com>
> ---
> 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
>
Powered by blists - more mailing lists