* [PATCH v2] md: dm-mpath: use list iterator only inside the loop
@ 2022-04-03 3:41 ` Xiaomeng Tong
0 siblings, 0 replies; 2+ messages in thread
From: Xiaomeng Tong @ 2022-04-03 3:41 UTC (permalink / raw)
To: agk, snitzer, dm-devel; +Cc: linux-kernel, Xiaomeng Tong
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [dm-devel] [PATCH v2] md: dm-mpath: use list iterator only inside the loop
@ 2022-04-03 3:41 ` Xiaomeng Tong
0 siblings, 0 replies; 2+ messages in thread
From: Xiaomeng Tong @ 2022-04-03 3:41 UTC (permalink / raw)
To: agk, snitzer, dm-devel; +Cc: Xiaomeng Tong, linux-kernel
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
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-04-04 6:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-03 3:41 [PATCH v2] md: dm-mpath: use list iterator only inside the loop Xiaomeng Tong
2022-04-03 3:41 ` [dm-devel] " Xiaomeng Tong
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.