diff mbox series

[2/2] dm: replace usage of found with dedicated list iterator variable

Message ID 20220331220236.884887-2-jakobkoschel@gmail.com (mailing list archive)
State New, archived
Headers show
Series [1/2] dm snapshot: remove usage of list iterator for list_add() after the loop body | expand

Commit Message

Jakob Koschel March 31, 2022, 10:02 p.m. UTC
To move the list iterator variable into the list_for_each_entry_*()
macro in the future it should be avoided to use the list iterator
variable after the loop body.

To *never* use the list iterator variable after the loop it was
concluded to use a separate iterator variable instead of a
found boolean [1].

This removes the need to use a found variable and simply checking if
the variable was set, can determine if the break/goto was hit.

Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1]
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---
 drivers/md/dm-table.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 03541cfc2317..9cf87954c05a 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -424,17 +424,16 @@  static int dm_set_device_limits(struct dm_target *ti, struct dm_dev *dev,
  */
 void dm_put_device(struct dm_target *ti, struct dm_dev *d)
 {
-	int found = 0;
 	struct list_head *devices = &ti->table->devices;
-	struct dm_dev_internal *dd;
+	struct dm_dev_internal *dd = NULL, *iter;
 
-	list_for_each_entry(dd, devices, list) {
-		if (dd->dm_dev == d) {
-			found = 1;
+	list_for_each_entry(iter, devices, list) {
+		if (iter->dm_dev == d) {
+			dd = iter;
 			break;
 		}
 	}
-	if (!found) {
+	if (!dd) {
 		DMWARN("%s: device %s not in table devices list",
 		       dm_device_name(ti->table->md), d->name);
 		return;