Skip to contentSkip to conversation

rbd: replace usage of found with dedicated list iterator variable

PATCH Applied Jakob Koschel 2 participants 2 messages Mar 24, 2022 – Mar 25, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rbd: replace usage of found with dedicated list iterator variable

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.

---
 drivers/block/rbd.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/block/rbd.c +6 -7
index b844432bad20..e5f891d058e8 100644
@@ -756,24 +756,23 @@ static struct rbd_client *__rbd_get_client(struct rbd_client *rbdc)
  */
 static struct rbd_client *rbd_client_find(struct ceph_options *ceph_opts)
 {
-	struct rbd_client *client_node;
-	bool found = false;
+	struct rbd_client *client_node = NULL, *iter;
 
 	if (ceph_opts->flags & CEPH_OPT_NOSHARE)
 		return NULL;
 
 	spin_lock(&rbd_client_list_lock);
-	list_for_each_entry(client_node, &rbd_client_list, node) {
-		if (!ceph_compare_options(ceph_opts, client_node->client)) {
-			__rbd_get_client(client_node);
+	list_for_each_entry(iter, &rbd_client_list, node) {
+		if (!ceph_compare_options(ceph_opts, iter->client)) {
+			__rbd_get_client(iter);
 
-			found = true;
+			client_node = iter;
 			break;
 		}
 	}
 	spin_unlock(&rbd_client_list_lock);
 
-	return found ? client_node : NULL;
+	return client_node;
 }
 
 /*

base-commit: f443e374ae131c168a065ea1748feac6b2e76613

Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 54 lines · Jakob Koschel

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.

---
 drivers/block/rbd.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/block/rbd.c +6 -7
index b844432bad20..e5f891d058e8 100644
@@ -756,24 +756,23 @@ static struct rbd_client *__rbd_get_client(struct rbd_client *rbdc)
  */
 static struct rbd_client *rbd_client_find(struct ceph_options *ceph_opts)
 {
-       struct rbd_client *client_node;
-       bool found = false;
+       struct rbd_client *client_node = NULL, *iter;
 
        if (ceph_opts->flags & CEPH_OPT_NOSHARE)
                return NULL;
 
        spin_lock(&rbd_client_list_lock);
-       list_for_each_entry(client_node, &rbd_client_list, node) {
-               if (!ceph_compare_options(ceph_opts, client_node->client)) {
-                       __rbd_get_client(client_node);
+       list_for_each_entry(iter, &rbd_client_list, node) {
+               if (!ceph_compare_options(ceph_opts, iter->client)) {
+                       __rbd_get_client(iter);
 
-                       found = true;
+                       client_node = iter;
                        break;
                }
        }
        spin_unlock(&rbd_client_list_lock);
 
-       return found ? client_node : NULL;
+       return client_node;
 }
 
 /*
Quoted 4 lines

base-commit: f443e374ae131c168a065ea1748feac6b2e76613 --
2.25.1

Applied.

Thanks,

Ilya