Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

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/r/20220331091634.644840-1-jakobkoschel@gmail.com
Reviewed-by: Leon Romanovsky <leonro@nvidia.com>
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Jakob Koschel and committed by
Jason Gunthorpe
4302005f e945c653

+8 -8
+8 -8
drivers/infiniband/core/sa_query.c
··· 1034 1034 struct netlink_ext_ack *extack) 1035 1035 { 1036 1036 unsigned long flags; 1037 - struct ib_sa_query *query; 1037 + struct ib_sa_query *query = NULL, *iter; 1038 1038 struct ib_mad_send_buf *send_buf; 1039 1039 struct ib_mad_send_wc mad_send_wc; 1040 - int found = 0; 1041 1040 int ret; 1042 1041 1043 1042 if ((nlh->nlmsg_flags & NLM_F_REQUEST) || ··· 1044 1045 return -EPERM; 1045 1046 1046 1047 spin_lock_irqsave(&ib_nl_request_lock, flags); 1047 - list_for_each_entry(query, &ib_nl_request_list, list) { 1048 + list_for_each_entry(iter, &ib_nl_request_list, list) { 1048 1049 /* 1049 1050 * If the query is cancelled, let the timeout routine 1050 1051 * take care of it. 1051 1052 */ 1052 - if (nlh->nlmsg_seq == query->seq) { 1053 - found = !ib_sa_query_cancelled(query); 1054 - if (found) 1055 - list_del(&query->list); 1053 + if (nlh->nlmsg_seq == iter->seq) { 1054 + if (!ib_sa_query_cancelled(iter)) { 1055 + list_del(&iter->list); 1056 + query = iter; 1057 + } 1056 1058 break; 1057 1059 } 1058 1060 } 1059 1061 1060 - if (!found) { 1062 + if (!query) { 1061 1063 spin_unlock_irqrestore(&ib_nl_request_lock, flags); 1062 1064 goto resp_out; 1063 1065 }