Skip to contentSkip to conversation

staging: rtl8192u: ieee80211: Replace list_for_each with list_for_each_entry

PATCH In review Aastha Gupta 2 participants 2 messages Oct 7, 2017 Staging

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 staging: rtl8192u: ieee80211: Replace list_for_each with list_for_each_entry

list_for_each is a macro that iterates over the elements of a list. list_entry is a function that takes as argument a list pointer and returns the structure that is pointed to. list_for_each_entry is a macro that iterates over the structures in the list, rather than exposing the list spine.

Here the list is only used for its entries, and thus list_for_each_entry can be used instead of the composition of list_for_each and list_entry.

This patch is with the help of following Coccinelle script:

@@
expression l, list;
type t1, t2;
identifier p, v;
iterator name list_for_each_entry, list_for_each;
@@

- t1 *p;
...
- list_for_each(p, l)
+ list_for_each_entry(v, l, list)
{
... when != p
- v = list_entry(p, t2, list);
... when != p
}

---
Changes in v2:
- removed braces around list_for_each_entry

 drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +1 -4
index cbf8eb4..1781f11 100644
@@ -447,16 +447,13 @@ static int is_duplicate_packet(struct ieee80211_device *ieee,
 	switch (ieee->iw_mode) {
 	case IW_MODE_ADHOC:
 	{
-		struct list_head *p;
 		struct ieee_ibss_seq *entry = NULL;
 		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;
-		}
 	//	if (memcmp(entry->mac, mac, ETH_ALEN)){
 		if (p == &ieee->ibss_mac_hash[index]) {
 			entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 19 lines · Aastha Gupta

list_for_each is a macro that iterates over the elements of a list. list_entry is a function that takes as argument a list pointer and returns the structure that is pointed to. list_for_each_entry is a macro that iterates over the structures in the list, rather than exposing the list spine.

Here the list is only used for its entries, and thus list_for_each_entry can be used instead of the composition of list_for_each and list_entry.

This patch is with the help of following Coccinelle script:

@@
expression l, list;
type t1, t2;
identifier p, v;
iterator name list_for_each_entry, list_for_each;
@@

Quoted 9 lines

- t1 *p;
...
- list_for_each(p, l)
+ list_for_each_entry(v, l, list)
{
... when != p
- v = list_entry(p, t2, list);
... when != p
}

Oops, the when != p's in this rule are not good enough. p has to appear nowhere in its scope, not just nowhere in the list_for_each_loop. If you look a few lines below your change you see that there is another use of p.

This suggests also that you didn't compile the code.

julia

Quoted 41 lines

---
Changes in v2:
- removed braces around list_for_each_entry

 drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/staging/rtl8192u/ieee80211/ieee80211_rx.c +1 -5
index cbf8eb4..1781f11 100644
@@ -447,16 +447,13 @@ static int is_duplicate_packet(struct ieee80211_device *ieee,
 	switch (ieee->iw_mode) {
 	case IW_MODE_ADHOC:
 	{
-		struct list_head *p;
 		struct ieee_ibss_seq *entry = NULL;
 		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;
-		}
 	//	if (memcmp(entry->mac, mac, ETH_ALEN)){
 		if (p == &ieee->ibss_mac_hash[index]) {
 			entry = kmalloc(sizeof(struct ieee_ibss_seq), GFP_ATOMIC);
--

2.7.4

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1507406358-2502-1-git-send-email-aastha.gupta4104%40gmail.com.
For more options, visit https://groups.google.com/d/optout.