[lkml]   [2022]   [Apr]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH v2] md: dm-mpath: use list iterator only inside the loop
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.


Signed-off-by: Xiaomeng Tong <>

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


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);
+ }

- bypass_pg(m, pg, bypassed);
return 0;

 \ /
  Last update: 2022-04-03 05:41    [W:0.035 / U:1.384 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site