Skip to contentSkip to conversation

Staging: rtl8188eu: use list_entry to access current list element instead of container_of

PATCH NAK Bhanusree Pola 3 participants 3 messages Mar 28, 2019 – Mar 31, 2019 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: rtl8188eu: use list_entry to access current list element instead of container_of

For struct list_head* type variables use list_entry to access the current list elements rather than using container_of.
Issue found using coccinelle.

The following semantic patch is used to implement this:

<smpl>
@rule_list@
struct list_head* l;
@@

-container_of
+list_entry
(l,...)
</smpl>

---
 drivers/staging/rtl8188eu/core/rtw_ap.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/rtl8188eu/core/rtw_ap.c +7 -7
index c360856a86ec..0554792e191f 100644
@@ -179,7 +179,7 @@ void expire_timeout_chk(struct adapter *padapter)
 
 	/* check auth_queue */
 	while (phead != plist) {
-		psta = container_of(plist, struct sta_info, auth_list);
+		psta = list_entry(plist, struct sta_info, auth_list);
 		plist = plist->next;
 
 		if (psta->expire_to > 0) {
@@ -212,7 +212,7 @@ void expire_timeout_chk(struct adapter *padapter)
 
 	/* check asoc_queue */
 	while (phead != plist) {
-		psta = container_of(plist, struct sta_info, asoc_list);
+		psta = list_entry(plist, struct sta_info, asoc_list);
 		plist = plist->next;
 
 		if (chk_sta_is_alive(psta) || !psta->expire_to) {
@@ -1021,7 +1021,7 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
 	plist = phead->next;
 
 	while (phead != plist) {
-		paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
+		paclnode = list_entry(plist, struct rtw_wlan_acl_node, list);
 		plist = plist->next;
 
 		if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
@@ -1081,7 +1081,7 @@ int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
 	plist = phead->next;
 
 	while (phead != plist) {
-		paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
+		paclnode = list_entry(plist, struct rtw_wlan_acl_node, list);
 		plist = plist->next;
 
 		if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
@@ -1328,7 +1328,7 @@ void associated_clients_update(struct adapter *padapter, u8 updated)
 
 		/* check asoc_queue */
 		while (phead != plist) {
-			psta = container_of(plist, struct sta_info, asoc_list);
+			psta = list_entry(plist, struct sta_info, asoc_list);
 
 			plist = plist->next;
 
@@ -1599,7 +1599,7 @@ int rtw_sta_flush(struct adapter *padapter)
 
 	/* free sta asoc_queue */
 	while (phead != plist) {
-		psta = container_of(plist, struct sta_info, asoc_list);
+		psta = list_entry(plist, struct sta_info, asoc_list);
 
 		plist = plist->next;
 
@@ -1726,7 +1726,7 @@ void stop_ap_mode(struct adapter *padapter)
 	phead = get_list_head(pacl_node_q);
 	plist = phead->next;
 	while (phead != plist) {
-		paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
+		paclnode = list_entry(plist, struct rtw_wlan_acl_node, list);
 		plist = plist->next;
 
 		if (paclnode->valid) {
Signature · 1 line
2.17.1
#1 lore raw
Quoted 14 lines · Bhanusree Pola

For struct list_head* type variables use list_entry to access the current list elements rather than using container_of.
Issue found using coccinelle.

The following semantic patch is used to implement this:

<smpl>
@rule_list@
struct list_head* l;
@@

(quoted diff) +1 -1
-container_of
+list_entry
  (l,...)
Quoted 1 line

</smpl>

Can these be implemented with list_for_each?

julia

Quoted 83 lines
---
 drivers/staging/rtl8188eu/core/rtw_ap.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/rtl8188eu/core/rtw_ap.c +7 -8
index c360856a86ec..0554792e191f 100644
@@ -179,7 +179,7 @@ void expire_timeout_chk(struct adapter *padapter)
 
 	/* check auth_queue */
 	while (phead != plist) {
-		psta = container_of(plist, struct sta_info, auth_list);
+		psta = list_entry(plist, struct sta_info, auth_list);
 		plist = plist->next;
 
 		if (psta->expire_to > 0) {
@@ -212,7 +212,7 @@ void expire_timeout_chk(struct adapter *padapter)
 
 	/* check asoc_queue */
 	while (phead != plist) {
-		psta = container_of(plist, struct sta_info, asoc_list);
+		psta = list_entry(plist, struct sta_info, asoc_list);
 		plist = plist->next;
 
 		if (chk_sta_is_alive(psta) || !psta->expire_to) {
@@ -1021,7 +1021,7 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
 	plist = phead->next;
 
 	while (phead != plist) {
-		paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
+		paclnode = list_entry(plist, struct rtw_wlan_acl_node, list);
 		plist = plist->next;
 
 		if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
@@ -1081,7 +1081,7 @@ int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
 	plist = phead->next;
 
 	while (phead != plist) {
-		paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
+		paclnode = list_entry(plist, struct rtw_wlan_acl_node, list);
 		plist = plist->next;
 
 		if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
@@ -1328,7 +1328,7 @@ void associated_clients_update(struct adapter *padapter, u8 updated)
 
 		/* check asoc_queue */
 		while (phead != plist) {
-			psta = container_of(plist, struct sta_info, asoc_list);
+			psta = list_entry(plist, struct sta_info, asoc_list);
 
 			plist = plist->next;
 
@@ -1599,7 +1599,7 @@ int rtw_sta_flush(struct adapter *padapter)
 
 	/* free sta asoc_queue */
 	while (phead != plist) {
-		psta = container_of(plist, struct sta_info, asoc_list);
+		psta = list_entry(plist, struct sta_info, asoc_list);
 
 		plist = plist->next;
 
@@ -1726,7 +1726,7 @@ void stop_ap_mode(struct adapter *padapter)
 	phead = get_list_head(pacl_node_q);
 	plist = phead->next;
 	while (phead != plist) {
-		paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
+		paclnode = list_entry(plist, struct rtw_wlan_acl_node, list);
 		plist = plist->next;
 
 		if (paclnode->valid) {
--

2.17.1

--
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/20190328114741.4367-1-bhanusreemahesh%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

#2 lore raw
In reply to Bhanusree Pola
Quoted 16 lines · Bhanusree Pola

For struct list_head* type variables use list_entry to access the current list elements rather than using container_of.
Issue found using coccinelle.

The following semantic patch is used to implement this:

<smpl>
@rule_list@
struct list_head* l;
@@

(quoted diff) +1 -1
-container_of
+list_entry
   (l,...)

</smpl>

Quoted 1 line

Have you actually tested this patch on real hardware? If not, then you must find a partner before submitting it. It is one thing to do minor semantic changes following the suggestion of some tool for code semantics, but quite another when you are significantly modifying list handling.

Your patch may in fact be correct, but until it has actually been tested and the commit log reflects such testing, then this patch is not acceptable. After all, your reputation would hardly be advanced by submitting a patch that broke a driver!

NACK.

Larry

Quoted 72 lines
---
  drivers/staging/rtl8188eu/core/rtw_ap.c | 14 +++++++-------
  1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/rtl8188eu/core/rtw_ap.c +7 -7
index c360856a86ec..0554792e191f 100644
@@ -179,7 +179,7 @@ void expire_timeout_chk(struct adapter *padapter)
 
  	/* check auth_queue */
  	while (phead != plist) {
-		psta = container_of(plist, struct sta_info, auth_list);
+		psta = list_entry(plist, struct sta_info, auth_list);
  		plist = plist->next;
 
  		if (psta->expire_to > 0) {
@@ -212,7 +212,7 @@ void expire_timeout_chk(struct adapter *padapter)
 
  	/* check asoc_queue */
  	while (phead != plist) {
-		psta = container_of(plist, struct sta_info, asoc_list);
+		psta = list_entry(plist, struct sta_info, asoc_list);
  		plist = plist->next;
 
  		if (chk_sta_is_alive(psta) || !psta->expire_to) {
@@ -1021,7 +1021,7 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)
  	plist = phead->next;
 
  	while (phead != plist) {
-		paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
+		paclnode = list_entry(plist, struct rtw_wlan_acl_node, list);
  		plist = plist->next;
 
  		if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
@@ -1081,7 +1081,7 @@ int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr)
  	plist = phead->next;
 
  	while (phead != plist) {
-		paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
+		paclnode = list_entry(plist, struct rtw_wlan_acl_node, list);
  		plist = plist->next;
 
  		if (!memcmp(paclnode->addr, addr, ETH_ALEN)) {
@@ -1328,7 +1328,7 @@ void associated_clients_update(struct adapter *padapter, u8 updated)
 
  		/* check asoc_queue */
  		while (phead != plist) {
-			psta = container_of(plist, struct sta_info, asoc_list);
+			psta = list_entry(plist, struct sta_info, asoc_list);
 
  			plist = plist->next;
 
@@ -1599,7 +1599,7 @@ int rtw_sta_flush(struct adapter *padapter)
 
  	/* free sta asoc_queue */
  	while (phead != plist) {
-		psta = container_of(plist, struct sta_info, asoc_list);
+		psta = list_entry(plist, struct sta_info, asoc_list);
 
  		plist = plist->next;
 
@@ -1726,7 +1726,7 @@ void stop_ap_mode(struct adapter *padapter)
  	phead = get_list_head(pacl_node_q);
  	plist = phead->next;
  	while (phead != plist) {
-		paclnode = container_of(plist, struct rtw_wlan_acl_node, list);
+		paclnode = list_entry(plist, struct rtw_wlan_acl_node, list);
  		plist = plist->next;
 
  		if (paclnode->valid) {