Skip to contentSkip to conversation

IB/SA: replace usage of found with dedicated list iterator variable

PATCH Superseded Jakob Koschel 2 participants 2 messages Mar 27, 2022 – Mar 28, 2022 InfiniBand

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 IB/SA: 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.

v1->v2:
- set query correctly (Mark Zhang)

---
 drivers/infiniband/core/sa_query.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/infiniband/core/sa_query.c +8 -8
index 74ecd7456a11..ed26066b706f 100644
@@ -1035,10 +1035,9 @@ int ib_nl_handle_resolve_resp(struct sk_buff *skb,
 			      struct netlink_ext_ack *extack)
 {
 	unsigned long flags;
-	struct ib_sa_query *query;
+	struct ib_sa_query *query = NULL, *iter;
 	struct ib_mad_send_buf *send_buf;
 	struct ib_mad_send_wc mad_send_wc;
-	int found = 0;
 	int ret;
 
 	if ((nlh->nlmsg_flags & NLM_F_REQUEST) ||
@@ -1046,20 +1045,21 @@ int ib_nl_handle_resolve_resp(struct sk_buff *skb,
 		return -EPERM;
 
 	spin_lock_irqsave(&ib_nl_request_lock, flags);
-	list_for_each_entry(query, &ib_nl_request_list, list) {
+	list_for_each_entry(iter, &ib_nl_request_list, list) {
 		/*
 		 * If the query is cancelled, let the timeout routine
 		 * take care of it.
 		 */
-		if (nlh->nlmsg_seq == query->seq) {
-			found = !ib_sa_query_cancelled(query);
-			if (found)
-				list_del(&query->list);
+		if (nlh->nlmsg_seq == iter->seq) {
+			if (!ib_sa_query_cancelled(iter)) {
+				list_del(&iter->list);
+				query = iter;
+			}
 			break;
 		}
 	}
 
-	if (!found) {
+	if (!query) {
 		spin_unlock_irqrestore(&ib_nl_request_lock, flags);
 		goto resp_out;
 	}

base-commit: b47d5a4f6b8d42f8a8fbe891b36215e4fddc53be --
2.25.1

Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 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.

Quoted 6 lines

v1->v2:
- set query correctly (Mark Zhang)

---

Please put changelog and Link after "---" section, as we don't need it in git commit history.

Quoted 2 lines
 drivers/infiniband/core/sa_query.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

The change itself is LGTM.

Thanks,