drivers: base: omit redundant interations
authorGimcuan Hui <gimcuan@gmail.com>
Sat, 11 Nov 2017 05:52:54 +0000 (05:52 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 18 Dec 2017 15:47:27 +0000 (16:47 +0100)
When error happens, these interators return the error, no interation should
be continued, so make the change for getting out of while immediately.

Signed-off-by: Gimcuan Hui <gimcuan@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/bus.c
drivers/base/core.c
drivers/base/driver.c

index 6c63e1abbdcc0f140326bc9911d58c719f42f8bf..ef6183306b4067d3fce4d589d540c6887d82bb78 100644 (file)
@@ -307,7 +307,7 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start,
 
        klist_iter_init_node(&bus->p->klist_devices, &i,
                             (start ? &start->p->knode_bus : NULL));
-       while ((dev = next_device(&i)) && !error)
+       while (!error && (dev = next_device(&i)))
                error = fn(dev, data);
        klist_iter_exit(&i);
        return error;
index bf45587bcb462307d6f087b2e69a9d9639a3f739..61515ef911848e37da9862e9df41c6912c518b00 100644 (file)
@@ -2114,7 +2114,7 @@ int device_for_each_child(struct device *parent, void *data,
                return 0;
 
        klist_iter_init(&parent->p->klist_children, &i);
-       while ((child = next_device(&i)) && !error)
+       while (!error && (child = next_device(&i)))
                error = fn(child, data);
        klist_iter_exit(&i);
        return error;
index 4e20d68edb0d2a47cb9632f10aafbb8f15351b2b..ba912558a5108087f3b169217424a67c0bcaf4f3 100644 (file)
@@ -50,7 +50,7 @@ int driver_for_each_device(struct device_driver *drv, struct device *start,
 
        klist_iter_init_node(&drv->p->klist_devices, &i,
                             start ? &start->p->knode_driver : NULL);
-       while ((dev = next_device(&i)) && !error)
+       while (!error && (dev = next_device(&i)))
                error = fn(dev, data);
        klist_iter_exit(&i);
        return error;