Staging: rtl8188eu: core: Use list_for_each_entry_safe
PATCH 1/1 Staging: rtl8188eu: core: Use list_for_each_entry_safe
Use list_for_each_entry_safe when the list elements may get deleted during traversal. Done using the following semantic patch by coccinelle.
@r@
struct list_head* l;
expression e;
identifier m, list_del_init, f;
type T1;
T1* pos;
iterator name list_for_each_entry_safe;
@@
f(...){
+T1* tmp;
...
-while(...)
+list_for_each_entry_safe(pos,tmp,l,m)
{
...
-pos = container_of(l,T1,m);
...
-l=e;
<+...
list_del_init(&pos->m)
...+>
}
...
}
--- drivers/staging/rtl8188eu/core/rtw_ap.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-)
drivers/staging/rtl8188eu/core/rtw_ap.c +6 -16
@@ -1196,7 +1196,7 @@ int rtw_acl_add_sta(struct adapter *padapter, u8 *addr)int rtw_acl_remove_sta (struct adapter *padapter,u8 *addr) {struct list_head *plist, *phead; -struct rtw_wlan_acl_node *paclnode; +struct rtw_wlan_acl_node *paclnode, *tmp;struct sta_priv *pstapriv = &padapter->stapriv;struct wlan_acl_pool *pacl_list = &pstapriv->acl_list;struct __queue *pacl_node_q = &pacl_list->acl_node_q;
@@ -1208,10 +1208,7 @@ int rtw_acl_remove_sta(struct adapter *padapter, u8 *addr) phead =get_list_head (pacl_node_q); plist = phead->next; -while (phead != plist) { - paclnode = container_of(plist, struct rtw_wlan_acl_node, list); - plist = plist->next; - +list_for_each_entry_safe (paclnode, tmp, plist, list) {if (!memcmp (paclnode->addr, addr,ETH_ALEN )) {if (paclnode->valid) { paclnode->valid = false;
@@ -1711,7 +1708,7 @@ u8 ap_free_sta(struct adapter *padapter, struct sta_info *psta,int rtw_sta_flush (struct adapter *padapter) {struct list_head *phead, *plist; -struct sta_info *psta =NULL ; +struct sta_info *psta =NULL , *tmp;struct sta_priv *pstapriv = &padapter->stapriv;struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
@@ -1727,11 +1724,7 @@ int rtw_sta_flush(struct adapter *padapter) plist = phead->next;/* free sta asoc_queue */ -while (phead != plist) { - psta = container_of(plist, struct sta_info, asoc_list); - - plist = plist->next; - +list_for_each_entry_safe (psta, tmp, plist, asoc_list) {list_del_init (&psta->asoc_list); pstapriv->asoc_list_cnt--;
@@ -1833,7 +1826,7 @@ void start_ap_mode(struct adapter *padapter)void stop_ap_mode (struct adapter *padapter) {struct list_head *phead, *plist; -struct rtw_wlan_acl_node *paclnode; +struct rtw_wlan_acl_node *paclnode, *tmp;struct sta_info *psta =NULL ;struct sta_priv *pstapriv = &padapter->stapriv;struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
@@ -1855,10 +1848,7 @@ void stop_ap_mode(struct adapter *padapter)spin_lock_bh (&pacl_node_q->lock); phead =get_list_head (pacl_node_q); plist = phead->next; -while (phead != plist) { - paclnode = container_of(plist, struct rtw_wlan_acl_node, list); - plist = plist->next; - +list_for_each_entry_safe (paclnode, tmp, plist, list) {if (paclnode->valid) { paclnode->valid = false;
Signature · 1 line
2.7.4
Quoted 2 lines · Srishti Sharma
Use
list_for_each_entry_safewhen the list elements may get deleted during traversal.
This patch is fine as a cleanup but none of these are actually buggy.
regards,
dan carpenter
Quoted 5 lines · Dan Carpenter
Quoted 2 lines · Srishti Sharma
Use
list_for_each_entry_safewhen the list elements may get deleted during traversal.This patch is fine as a cleanup but none of these are actually buggy.
I'm not sure what you are getting at with the comment. The commit doesn't say that they were buggy. Perhaps the commit message could have been more verbose, like "Use list operators on list_head values. List_for_each_entry_safe is needed because the list elements get deleted during the traversal"?
thanks,
julia
Quoted 11 lines
regards,
dan carpenter--
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/20171004112103.cvu5ipkudfpz2adc%40mwanda.
For more options, visit https://groups.google.com/d/optout.
Quoted 8 lines · Julia Lawall
Quoted 4 lines · Dan Carpenter
Quoted 2 lines · Srishti Sharma
Use
list_for_each_entry_safewhen the list elements may get deleted during traversal.
Quoted 6 lines
Quoted 1 line
This patch is fine as a cleanup but none of these are actually buggy.
I'm not sure what you are getting at with the comment. The commit doesn't say that they were buggy. Perhaps the commit message could have been more verbose, like "Use list operators on
list_headvalues.List_for_each_entry_safeis needed because the list elements get deleted
^^^^^^^^^
It is not *needed*, the original code works fine. The problem with the original code, is that it's ugly as sin.
Quoted 1 line
during the traversal"?
The changelog needs to say *why* we're applying the patch. At first I thought it was going to fix a use after free. What I would prefer in the changelog is something like: "This patch is a cleanup and doesn't change runtime behavior. It changes an open coded list traversal to use list_for_each_entry_safe."
regards,
dan carpenter
Quoted 20 lines · Dan Carpenter
Quoted 8 lines · Julia Lawall
Quoted 4 lines · Dan Carpenter
Quoted 2 lines · Srishti Sharma
Use
list_for_each_entry_safewhen the list elements may get deleted during traversal.Quoted 6 lines
Quoted 1 line
This patch is fine as a cleanup but none of these are actually buggy.
I'm not sure what you are getting at with the comment. The commit doesn't say that they were buggy. Perhaps the commit message could have been more verbose, like "Use list operators on
list_headvalues.List_for_each_entry_safeis needed because the list elements get deleted^^^^^^^^^It is not *needed*, the original code works fine. The problem with the original code, is that it's ugly as sin.
Quoted 7 lines
Quoted 1 line
during the traversal"?
The changelog needs to say *why* we're applying the patch. At first I thought it was going to fix a use after free. What I would prefer in the changelog is something like: "This patch is a cleanup and doesn't change runtime behavior. It changes an open coded list traversal to use
list_for_each_entry_safe."
OK, Srishti, you can put that. But change the subject lines too.
julia
Quoted 12 lines
regards,
dan carpenter--
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/20171004144012.jciztelhwjdyzpwg%40mwanda.
For more options, visit https://groups.google.com/d/optout.
Quoted 26 lines · Julia Lawall
Quoted 22 lines · Dan Carpenter
Quoted 8 lines · Julia Lawall
Quoted 4 lines · Dan Carpenter
Quoted 2 lines · Srishti Sharma
Use
list_for_each_entry_safewhen the list elements may get deleted during traversal.Quoted 6 lines
Quoted 1 line
This patch is fine as a cleanup but none of these are actually buggy.
I'm not sure what you are getting at with the comment. The commit doesn't say that they were buggy. Perhaps the commit message could have been more verbose, like "Use list operators on
list_headvalues.List_for_each_entry_safeis needed because the list elements get deleted^^^^^^^^^It is not *needed*, the original code works fine. The problem with the original code, is that it's ugly as sin.
Quoted 1 line
during the traversal"?
Quoted 7 lines
Quoted 5 lines
The changelog needs to say *why* we're applying the patch. At first I thought it was going to fix a use after free. What I would prefer in the changelog is something like: "This patch is a cleanup and doesn't change runtime behavior. It changes an open coded list traversal to use
list_for_each_entry_safe."OK, Srishti, you can put that. But change the subject lines too.
Ok will do ! Thanks again.
Regards,
Srishti
Quoted 15 lines
julia
Quoted 12 lines
regards,
dan carpenter--
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/20171004144012.jciztelhwjdyzpwg%40mwanda.
For more options, visit https://groups.google.com/d/optout.