Skip to contentSkip to conversation

staging: rdma: hfi1: Use list_for_each_entry_safe()

PATCH In review Janani Ravichandran 1 participant 2 messages Feb 28, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rdma: hfi1: Use list_for_each_entry_safe()

Use list_for_each_entry_safe() rather than a combination of list_for_each_safe() and list_entry()

Semantic patch used:

@a@
expression pos, n, head;
expression mem;
type t;
identifier var;
iterator name list_for_each_entry_safe, list_for_each_safe; @@

- list_for_each_safe(pos, n, head)
+ list_for_each_entry_safe(var, n, head, mem) {
... when != var
- var = \(list_entry \| container_of\)(pos, t, mem); ... when any
}

---
 drivers/staging/rdma/hfi1/diag.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/rdma/hfi1/diag.c +1 -2
index e41159f..411cdee 100644
@@ -304,8 +304,7 @@ static void drain_snoop_list(struct list_head *queue)
 	struct list_head *pos, *q;
 	struct snoop_packet *packet;
 
-	list_for_each_safe(pos, q, queue) {
-		packet = list_entry(pos, struct snoop_packet, list);
+	list_for_each_entry_safe(packet, q, queue, list) {
 		list_del(pos);
 		kfree(packet);
 	}
Signature · 1 line
2.5.0
#1 lore raw
Quoted 44 lines · Janani Ravichandran

Use list_for_each_entry_safe() rather than a combination of list_for_each_safe() and list_entry()

Semantic patch used:

@a@
expression pos, n, head;
expression mem;
type t;
identifier var;
iterator name list_for_each_entry_safe, list_for_each_safe; @@

- list_for_each_safe(pos, n, head)
+ list_for_each_entry_safe(var, n, head, mem)

  {
   ... when != var

- var = \(list_entry \| container_of\)(pos, t, mem); ... when any
}

---
 drivers/staging/rdma/hfi1/diag.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/rdma/hfi1/diag.c +1 -3
index e41159f..411cdee 100644
@@ -304,8 +304,7 @@ static void drain_snoop_list(struct list_head *queue)
        struct list_head *pos, *q;
        struct snoop_packet *packet;
 
-       list_for_each_safe(pos, q, queue) {
-               packet = list_entry(pos, struct snoop_packet, list);
+       list_for_each_entry_safe(packet, q, queue, list) {
                list_del(pos);
                kfree(packet);
        }
--

2.5.0

Quoted 1 line

This is a mistake here. Please ignore this. Sorry.

Janani.