From: Gimcuan Hui <gimcuan@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] drivers: base: omit redundant interations
Date: Sat, 11 Nov 2017 05:52:54 +0000 [thread overview]
Message-ID: <20171111055254.2277-1-gimcuan@gmail.com> (raw)
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>
---
drivers/base/bus.c | 2 +-
drivers/base/core.c | 2 +-
drivers/base/driver.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 22a64fd3309b..40b118586434 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -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;
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 12ebd055724c..725ade87cbeb 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -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;
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 4eabfe28d2b3..11832dc88a7a 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -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;
--
2.11.0
reply other threads:[~2017-11-11 5:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171111055254.2277-1-gimcuan@gmail.com \
--to=gimcuan@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®