mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xiaomeng Tong <xiam0nd.tong@gmail.com>
To: agk@redhat.com, snitzer@redhat.com, dm-devel@redhat.com
Cc: linux-kernel@vger.kernel.org, Xiaomeng Tong <xiam0nd.tong@gmail.com>
Subject: [PATCH v2] md: dm-mpath: use list iterator only inside the loop
Date: Sun,  3 Apr 2022 11:41:01 +0800	[thread overview]
Message-ID: <20220403034101.14735-1-xiam0nd.tong@gmail.com> (raw)

To move the declare of list iterator into the list_for_each_entry_*()
macro in the future, it should be avoided to use the list iterator
variable after the loop body [1].

Because the cases (the list is empty or no entry is found) have been
checked prior to iterating m->priority_groups, it is fine to move the
bypass_pg(m, pg, bypassed); inside the loop when entry is found.

[1]: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/

Signed-off-by: Xiaomeng Tong <xiam0nd.tong@gmail.com>
---

changes since v1:
 - it is not a bug, have checked before (Mike Snitzer)
 - tweak code to avoid dead code "return -EINVAL;" (Xiaomeng Tong)

v1: https://lore.kernel.org/lkml/20220327053742.2942-1-xiam0nd.tong@gmail.com/

---
 drivers/md/dm-mpath.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index f4719b65e5e3..13c65eab32a2 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -1496,11 +1496,12 @@ static int bypass_pg_num(struct multipath *m, const char *pgstr, bool bypassed)
 	}
 
 	list_for_each_entry(pg, &m->priority_groups, list) {
-		if (!--pgnum)
+		if (!--pgnum) {
+			bypass_pg(m, pg, bypassed);
 			break;
+		}
 	}
 
-	bypass_pg(m, pg, bypassed);
 	return 0;
 }
 
-- 
2.17.1


                 reply	other threads:[~2022-04-03  3:41 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=20220403034101.14735-1-xiam0nd.tong@gmail.com \
    --to=xiam0nd.tong@gmail.com \
    --cc=agk@redhat.com \
    --cc=dm-devel@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=snitzer@redhat.com \
    /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®