Skip to contentSkip to conversation

drivers: base: omit redundant interations

PATCH New Gimcuan Hui 1 participant 1 message Nov 11, 2017 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drivers: base: omit redundant interations

When error happens, these interators return the error, no interation should be continued, so make the change for getting out of while immediately.

---
 drivers/base/bus.c    | 2 +-
 drivers/base/core.c   | 2 +-
 drivers/base/driver.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/base/bus.c +1 -1
index 22a64fd3309b..40b118586434 100644
@@ -309,7 +309,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;
drivers/base/core.c +1 -1
index 12ebd055724c..725ade87cbeb 100644
@@ -2116,7 +2116,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;
drivers/base/driver.c +1 -1
index 4eabfe28d2b3..11832dc88a7a 100644
@@ -52,7 +52,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;
Signature · 1 line
2.11.0