Skip to contentSkip to conversation

staging: rtl8192u: Prefer list_for_each_entry()

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8192u: Prefer list_for_each_entry()

Use list_for_each_entry rather than a combination of list_for_each and list_entry().

Semantic patch used:

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

(
- list_for_each(pos, head)
+ list_for_each_entry(var, head, mem)
{
... when != var
- var = \(list_entry \| container_of\)(pos, t, mem); ... when any
}
|
- 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/rtl8192u/ieee80211/ieee80211_rx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +1 -2
index 9dfde07..7d1edb3 100644
@@ -452,8 +452,7 @@ static int is_duplicate_packet(struct ieee80211_device *ieee,
 		u8 *mac = header->addr2;
 		int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
 
-		list_for_each(p, &ieee->ibss_mac_hash[index]) {
-			entry = list_entry(p, struct ieee_ibss_seq, list);
+		list_for_each_entry(entry, &ieee->ibss_mac_hash[index], list) {
 			if (!memcmp(entry->mac, mac, ETH_ALEN))
 				break;
 		}
Signature · 1 line
2.5.0
#1 lore raw
Quoted 54 lines · Janani Ravichandran

Use list_for_each_entry rather than a combination of list_for_each and list_entry().

Semantic patch used:

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

(
- list_for_each(pos, head)
+ list_for_each_entry(var, head, mem)

  {
   ... when != var

- var = \(list_entry \| container_of\)(pos, t, mem); ... when any
}
|
- 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/rtl8192u/ieee80211/ieee80211_rx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +1 -2
index 9dfde07..7d1edb3 100644
@@ -452,8 +452,7 @@ static int is_duplicate_packet(struct ieee80211_device
 *ieee,
                u8 *mac = header->addr2;
                int index = mac[5] % IEEE_IBSS_MAC_HASH_SIZE;
 
-               list_for_each(p, &ieee->ibss_mac_hash[index]) {
-                       entry = list_entry(p, struct ieee_ibss_seq, list);
+               list_for_each_entry(entry, &ieee->ibss_mac_hash[index],
 list) {
                        if (!memcmp(entry->mac, mac, ETH_ALEN))
                                break;
                }
Quoted 3 lines

--
2.5.0

There is an error in this patch. Please ignore this. Sorry.

Janani.