* [PATCH] IB/SA: replace usage of found with dedicated list iterator variable
@ 2022-03-24 7:11 Jakob Koschel
2022-03-24 7:53 ` Mark Zhang
0 siblings, 1 reply; 3+ messages in thread
From: Jakob Koschel @ 2022-03-24 7:11 UTC (permalink / raw)
To: Jason Gunthorpe
Cc: Leon Romanovsky, Håkon Bugge, Mark Bloch, Mark Zhang,
Christophe JAILLET, linux-rdma, linux-kernel, Mike Rapoport,
Brian Johannesmeyer, Cristiano Giuffrida, Bos, H.J.,
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.
Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/
Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
---
drivers/infiniband/core/sa_query.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
index 74ecd7456a11..74cd84045e5b 100644
--- a/drivers/infiniband/core/sa_query.c
+++ b/drivers/infiniband/core/sa_query.c
@@ -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,20 @@ 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: f443e374ae131c168a065ea1748feac6b2e76613
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] IB/SA: replace usage of found with dedicated list iterator variable
2022-03-24 7:11 [PATCH] IB/SA: replace usage of found with dedicated list iterator variable Jakob Koschel
@ 2022-03-24 7:53 ` Mark Zhang
2022-03-24 8:24 ` Jakob Koschel
0 siblings, 1 reply; 3+ messages in thread
From: Mark Zhang @ 2022-03-24 7:53 UTC (permalink / raw)
To: Jakob Koschel, Jason Gunthorpe
Cc: Leon Romanovsky, Håkon Bugge, Mark Bloch,
Christophe JAILLET, linux-rdma, linux-kernel, Mike Rapoport,
Brian Johannesmeyer, Cristiano Giuffrida, Bos, H.J.
On 3/24/2022 3:11 PM, Jakob Koschel wrote:
> External email: Use caution opening links or attachments
>
>
> 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/
> Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
> ---
> drivers/infiniband/core/sa_query.c | 15 +++++++--------
> 1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
> index 74ecd7456a11..74cd84045e5b 100644
> --- a/drivers/infiniband/core/sa_query.c
> +++ b/drivers/infiniband/core/sa_query.c
> @@ -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,20 @@ 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;
Should it be:
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: f443e374ae131c168a065ea1748feac6b2e76613
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] IB/SA: replace usage of found with dedicated list iterator variable
2022-03-24 7:53 ` Mark Zhang
@ 2022-03-24 8:24 ` Jakob Koschel
0 siblings, 0 replies; 3+ messages in thread
From: Jakob Koschel @ 2022-03-24 8:24 UTC (permalink / raw)
To: Mark Zhang
Cc: Jason Gunthorpe, Leon Romanovsky, Håkon Bugge, Mark Bloch,
Christophe JAILLET, linux-rdma, Linux Kernel Mailing List,
Mike Rapoport, Brian Johannesmeyer, Cristiano Giuffrida, Bos,
H.J.
> On 24. Mar 2022, at 08:53, Mark Zhang <markzhang@nvidia.com> wrote:
>
> On 3/24/2022 3:11 PM, Jakob Koschel wrote:
>> External email: Use caution opening links or attachments
>> 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/
>> Signed-off-by: Jakob Koschel <jakobkoschel@gmail.com>
>> ---
>> drivers/infiniband/core/sa_query.c | 15 +++++++--------
>> 1 file changed, 7 insertions(+), 8 deletions(-)
>> diff --git a/drivers/infiniband/core/sa_query.c b/drivers/infiniband/core/sa_query.c
>> index 74ecd7456a11..74cd84045e5b 100644
>> --- a/drivers/infiniband/core/sa_query.c
>> +++ b/drivers/infiniband/core/sa_query.c
>> @@ -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,20 @@ 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;
>
> Should it be:
>
> if (nlh->nlmsg_seq == iter->seq) {
> if (!ib_sa_query_cancelled(iter)) {
> list_del(&iter->list);
> query = iter;
> }
> break;
yes you are right. Sorry about that, I'll send a fixed version with v2.
>
>> }
>> }
>> - if (!found) {
>> + if (!query) {
>> spin_unlock_irqrestore(&ib_nl_request_lock, flags);
>> goto resp_out;
>> }
>> base-commit: f443e374ae131c168a065ea1748feac6b2e76613
>> --
>> 2.25.1
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-24 8:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24 7:11 [PATCH] IB/SA: replace usage of found with dedicated list iterator variable Jakob Koschel
2022-03-24 7:53 ` Mark Zhang
2022-03-24 8:24 ` Jakob Koschel
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.