[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220331224501.904039-1-jakobkoschel@gmail.com>
Date: Fri, 1 Apr 2022 00:45:01 +0200
From: Jakob Koschel <jakobkoschel@...il.com>
To: Mike Marciniszyn <mike.marciniszyn@...nelisnetworks.com>
Cc: Dennis Dalessandro <dennis.dalessandro@...nelisnetworks.com>,
Jason Gunthorpe <jgg@...pe.ca>, linux-rdma@...r.kernel.org,
linux-kernel@...r.kernel.org, Mike Rapoport <rppt@...nel.org>,
"Brian Johannesmeyer" <bjohannesmeyer@...il.com>,
Cristiano Giuffrida <c.giuffrida@...nl>,
"Bos, H.J." <h.j.bos@...nl>, Jakob Koschel <jakobkoschel@...il.com>
Subject: [PATCH] IB/hfi1: remove check of list iterator against head past the loop body
When list_for_each_entry() completes the iteration over the whole list
without breaking the loop, the iterator value will be a bogus pointer
computed based on the head element.
While it is safe to use the pointer to determine if it was computed
based on the head element, either with list_entry_is_head() or
&pos->member == head, using the iterator variable after the loop should
be avoided.
In preparation to limit the scope of a list iterator to the list
traversal loop, use a dedicated pointer to point to the found element [1].
Link: https://lore.kernel.org/all/CAHk-=wgRr_D8CB-D9Kg-c=EHreAsk5SqXPwr9Y7k9sA6cWXJ6w@mail.gmail.com/ [1]
Signed-off-by: Jakob Koschel <jakobkoschel@...il.com>
---
drivers/infiniband/hw/hfi1/tid_rdma.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/infiniband/hw/hfi1/tid_rdma.c b/drivers/infiniband/hw/hfi1/tid_rdma.c
index 2a7abf7a1f7f..b12abf83a91c 100644
--- a/drivers/infiniband/hw/hfi1/tid_rdma.c
+++ b/drivers/infiniband/hw/hfi1/tid_rdma.c
@@ -1239,7 +1239,7 @@ static int kern_alloc_tids(struct tid_rdma_flow *flow)
struct hfi1_ctxtdata *rcd = flow->req->rcd;
struct hfi1_devdata *dd = rcd->dd;
u32 ngroups, pageidx = 0;
- struct tid_group *group = NULL, *used;
+ struct tid_group *group = NULL, *used, *iter;
u8 use;
flow->tnode_cnt = 0;
@@ -1248,13 +1248,15 @@ static int kern_alloc_tids(struct tid_rdma_flow *flow)
goto used_list;
/* First look at complete groups */
- list_for_each_entry(group, &rcd->tid_group_list.list, list) {
- kern_add_tid_node(flow, rcd, "complete groups", group,
- group->size);
+ list_for_each_entry(iter, &rcd->tid_group_list.list, list) {
+ kern_add_tid_node(flow, rcd, "complete groups", iter,
+ iter->size);
- pageidx += group->size;
- if (!--ngroups)
+ pageidx += iter->size;
+ if (!--ngroups) {
+ group = iter;
break;
+ }
}
if (pageidx >= flow->npagesets)
@@ -1277,7 +1279,7 @@ static int kern_alloc_tids(struct tid_rdma_flow *flow)
* However, if we are at the head, we have reached the end of the
* complete groups list from the first loop above
*/
- if (group && &group->list == &rcd->tid_group_list.list)
+ if (!group)
goto bail_eagain;
group = list_prepare_entry(group, &rcd->tid_group_list.list,
list);
base-commit: f82da161ea75dc4db21b2499e4b1facd36dab275
--
2.25.1
Powered by blists - more mailing lists