Re: [PATCH v3 4/9] driver core: Move true expression out of if condition in API driver_find_device()

From: Jonathan Cameron
Date: Mon Dec 16 2024 - 10:19:15 EST


On Thu, 12 Dec 2024 21:38:40 +0800
Zijun Hu <zijun_hu@xxxxxxxxxx> wrote:

> From: Zijun Hu <quic_zijuhu@xxxxxxxxxxx>
>
> For driver_find_device(), get_device() in the if condition always returns
> true, move it to if body to make the API's logic more clearer.
>
> Signed-off-by: Zijun Hu <quic_zijuhu@xxxxxxxxxxx>

Reviewed-by: Jonathan Cameron <Jonathan.Cameron@xxxxxxxxxx>

Though I think it would have been fine to have all these similar patches
as a single patch.

> ---
> drivers/base/driver.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/base/driver.c b/drivers/base/driver.c
> index b4eb5b89c4ee7bc35458fc75730b16a6d1e804d3..6f033a741aa7ce6138d1c61e49e72b2a3eb85e06 100644
> --- a/drivers/base/driver.c
> +++ b/drivers/base/driver.c
> @@ -160,9 +160,12 @@ struct device *driver_find_device(const struct device_driver *drv,
>
> klist_iter_init_node(&drv->p->klist_devices, &i,
> (start ? &start->p->knode_driver : NULL));
> - while ((dev = next_device(&i)))
> - if (match(dev, data) && get_device(dev))
> + while ((dev = next_device(&i))) {
> + if (match(dev, data)) {
> + get_device(dev);
> break;
> + }
> + }
> klist_iter_exit(&i);
> return dev;
> }
>