All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Staging: rtl8188eu: core: Use list_entry instead of container_of
@ 2017-09-30  1:23 Srishti Sharma
  2017-09-30  5:05 ` [Outreachy kernel] " Julia Lawall
  0 siblings, 1 reply; 9+ messages in thread
From: Srishti Sharma @ 2017-09-30  1:23 UTC (permalink / raw)
  To: gregkh; +Cc: devel, linux-kernel, outreachy-kernel, Srishti Sharma

For variables of the type struct list_head* use list_entry to access
the current list element instead of using container_of.
Done using the following semantic patch by coccinelle.

@r@
identifier e;
struct list_head* l;
@@

<... when != l == NULL
l;
...>

(
e =
-container_of
+list_entry
     (
      ...)
)

Signed-off-by: Srishti Sharma <srishtishar@gmail.com>
---
 drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
index 22cf362..f9df4ac 100644
--- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
+++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
@@ -152,8 +152,8 @@ u32	_rtw_free_sta_priv(struct	sta_priv *pstapriv)
 			while (phead != plist) {
 				int i;
 
-				psta = container_of(plist, struct sta_info,
-						    hash_list);
+				psta = list_entry(plist, struct sta_info,
+						  hash_list);
 				plist = plist->next;
 
 				for (i = 0; i < 16; i++) {
@@ -323,7 +323,7 @@ u32	rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta)
 		plist = phead->next;
 
 		while (!list_empty(phead)) {
-			prframe = container_of(plist, struct recv_frame, list);
+			prframe = list_entry(plist, struct recv_frame, list);
 
 			plist = plist->next;
 
@@ -399,7 +399,7 @@ void rtw_free_all_stainfo(struct adapter *padapter)
 		plist = phead->next;
 
 		while (phead != plist) {
-			psta = container_of(plist, struct sta_info, hash_list);
+			psta = list_entry(plist, struct sta_info, hash_list);
 
 			plist = plist->next;
 
@@ -435,7 +435,7 @@ struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
 	plist = phead->next;
 
 	while (phead != plist) {
-		psta = container_of(plist, struct sta_info, hash_list);
+		psta = list_entry(plist, struct sta_info, hash_list);
 
 		if ((!memcmp(psta->hwaddr, addr, ETH_ALEN)) == true) {
 			/*  if found the matched address */
@@ -493,7 +493,7 @@ u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr)
 	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 (!memcmp(paclnode->addr, mac_addr, ETH_ALEN)) {
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [Outreachy kernel] [PATCH] Staging: rtl8188eu: core: Use list_entry instead of container_of
  2017-09-30  1:23 [PATCH] Staging: rtl8188eu: core: Use list_entry instead of container_of Srishti Sharma
@ 2017-09-30  5:05 ` Julia Lawall
  2017-09-30  6:01   ` Srishti Sharma
  0 siblings, 1 reply; 9+ messages in thread
From: Julia Lawall @ 2017-09-30  5:05 UTC (permalink / raw)
  To: Srishti Sharma; +Cc: gregkh, devel, linux-kernel, outreachy-kernel



On Sat, 30 Sep 2017, Srishti Sharma wrote:

> For variables of the type struct list_head* use list_entry to access
> the current list element instead of using container_of.
> Done using the following semantic patch by coccinelle.
>
> @r@
> identifier e;
> struct list_head* l;
> @@
>
> <... when != l == NULL
> l;
> ...>

I don't see what is the goal of the above code.  The list_head variable is
not going to be in a statement by itself.  There is also no need to check
for l being NULL.  If it is NULL, the original code is incorrect too.

> (
> e =
> -container_of
> +list_entry
>      (
>       ...)
> )

Here you don't need the outer ( ).  This makes a disjunction with only
one choice.  Since there is only one choice, you don't need the
disjunction.

julia

> Signed-off-by: Srishti Sharma <srishtishar@gmail.com>
> ---
>  drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> index 22cf362..f9df4ac 100644
> --- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> +++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> @@ -152,8 +152,8 @@ u32	_rtw_free_sta_priv(struct	sta_priv *pstapriv)
>  			while (phead != plist) {
>  				int i;
>
> -				psta = container_of(plist, struct sta_info,
> -						    hash_list);
> +				psta = list_entry(plist, struct sta_info,
> +						  hash_list);
>  				plist = plist->next;
>
>  				for (i = 0; i < 16; i++) {
> @@ -323,7 +323,7 @@ u32	rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta)
>  		plist = phead->next;
>
>  		while (!list_empty(phead)) {
> -			prframe = container_of(plist, struct recv_frame, list);
> +			prframe = list_entry(plist, struct recv_frame, list);
>
>  			plist = plist->next;
>
> @@ -399,7 +399,7 @@ void rtw_free_all_stainfo(struct adapter *padapter)
>  		plist = phead->next;
>
>  		while (phead != plist) {
> -			psta = container_of(plist, struct sta_info, hash_list);
> +			psta = list_entry(plist, struct sta_info, hash_list);
>
>  			plist = plist->next;
>
> @@ -435,7 +435,7 @@ struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
>  	plist = phead->next;
>
>  	while (phead != plist) {
> -		psta = container_of(plist, struct sta_info, hash_list);
> +		psta = list_entry(plist, struct sta_info, hash_list);
>
>  		if ((!memcmp(psta->hwaddr, addr, ETH_ALEN)) == true) {
>  			/*  if found the matched address */
> @@ -493,7 +493,7 @@ u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr)
>  	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 (!memcmp(paclnode->addr, mac_addr, ETH_ALEN)) {
> --
> 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 outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1506734581-10932-1-git-send-email-srishtishar%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Outreachy kernel] [PATCH] Staging: rtl8188eu: core: Use list_entry instead of container_of
  2017-09-30  5:05 ` [Outreachy kernel] " Julia Lawall
@ 2017-09-30  6:01   ` Srishti Sharma
  2017-09-30  6:06     ` Julia Lawall
  0 siblings, 1 reply; 9+ messages in thread
From: Srishti Sharma @ 2017-09-30  6:01 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Greg KH, devel, Linux kernel mailing list, outreachy-kernel

On Sat, Sep 30, 2017 at 10:35 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
>
>
> On Sat, 30 Sep 2017, Srishti Sharma wrote:
>
>> For variables of the type struct list_head* use list_entry to access
>> the current list element instead of using container_of.
>> Done using the following semantic patch by coccinelle.
>>
>> @r@
>> identifier e;
>> struct list_head* l;
>> @@
>>
>> <... when != l == NULL
>> l;
>> ...>
> I don't see what is the goal of the above code.  The list_head variable is
> not going to be in a statement by itself.  There is also no need to check
> for l being NULL.  If it is NULL, the original code is incorrect too.

Since only those container_of are to replaced with list_entry which
have a variable of type list_head*  , I wanted to check if it occurs
anywhere before
container_of , which it only does in it's declaration , because it
can't be in any
statement by itself . I think it will be better to write .

@r@
identifier e;
struct list_head* l;
@@

<...
container_of(l,...);
...>

e =
-container_of
+list_entry
     (
      ....)

>> (
>> e =
>> -container_of
>> +list_entry
>>      (
>>       ...)
>> )
>
> Here you don't need the outer ( ).  This makes a disjunction with only
> one choice.  Since there is only one choice, you don't need the
> disjunction.

Thanks a lot , for pointing out the errors .

Regards,
Srishti
> julia
>
>> Signed-off-by: Srishti Sharma <srishtishar@gmail.com>
>> ---
>>  drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 12 ++++++------
>>  1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
>> index 22cf362..f9df4ac 100644
>> --- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
>> +++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
>> @@ -152,8 +152,8 @@ u32       _rtw_free_sta_priv(struct       sta_priv *pstapriv)
>>                       while (phead != plist) {
>>                               int i;
>>
>> -                             psta = container_of(plist, struct sta_info,
>> -                                                 hash_list);
>> +                             psta = list_entry(plist, struct sta_info,
>> +                                               hash_list);
>>                               plist = plist->next;
>>
>>                               for (i = 0; i < 16; i++) {
>> @@ -323,7 +323,7 @@ u32       rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta)
>>               plist = phead->next;
>>
>>               while (!list_empty(phead)) {
>> -                     prframe = container_of(plist, struct recv_frame, list);
>> +                     prframe = list_entry(plist, struct recv_frame, list);
>>
>>                       plist = plist->next;
>>
>> @@ -399,7 +399,7 @@ void rtw_free_all_stainfo(struct adapter *padapter)
>>               plist = phead->next;
>>
>>               while (phead != plist) {
>> -                     psta = container_of(plist, struct sta_info, hash_list);
>> +                     psta = list_entry(plist, struct sta_info, hash_list);
>>
>>                       plist = plist->next;
>>
>> @@ -435,7 +435,7 @@ struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
>>       plist = phead->next;
>>
>>       while (phead != plist) {
>> -             psta = container_of(plist, struct sta_info, hash_list);
>> +             psta = list_entry(plist, struct sta_info, hash_list);
>>
>>               if ((!memcmp(psta->hwaddr, addr, ETH_ALEN)) == true) {
>>                       /*  if found the matched address */
>> @@ -493,7 +493,7 @@ u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr)
>>       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 (!memcmp(paclnode->addr, mac_addr, ETH_ALEN)) {
>> --
>> 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 outreachy-kernel+unsubscribe@googlegroups.com.
>> To post to this group, send email to outreachy-kernel@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1506734581-10932-1-git-send-email-srishtishar%40gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Outreachy kernel] [PATCH] Staging: rtl8188eu: core: Use list_entry instead of container_of
  2017-09-30  6:01   ` Srishti Sharma
@ 2017-09-30  6:06     ` Julia Lawall
  2017-09-30  6:17       ` Srishti Sharma
  0 siblings, 1 reply; 9+ messages in thread
From: Julia Lawall @ 2017-09-30  6:06 UTC (permalink / raw)
  To: Srishti Sharma
  Cc: Julia Lawall, Greg KH, devel, Linux kernel mailing list,
	outreachy-kernel



On Sat, 30 Sep 2017, Srishti Sharma wrote:

> On Sat, Sep 30, 2017 at 10:35 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
> >
> >
> > On Sat, 30 Sep 2017, Srishti Sharma wrote:
> >
> >> For variables of the type struct list_head* use list_entry to access
> >> the current list element instead of using container_of.
> >> Done using the following semantic patch by coccinelle.
> >>
> >> @r@
> >> identifier e;
> >> struct list_head* l;
> >> @@
> >>
> >> <... when != l == NULL
> >> l;
> >> ...>
> > I don't see what is the goal of the above code.  The list_head variable is
> > not going to be in a statement by itself.  There is also no need to check
> > for l being NULL.  If it is NULL, the original code is incorrect too.
>
> Since only those container_of are to replaced with list_entry which
> have a variable of type list_head*  , I wanted to check if it occurs
> anywhere before
> container_of ,

Why?  If it is a list, then it seems appropriate to access it using
list_head.

> which it only does in it's declaration , because it
> can't be in any
> statement by itself . I think it will be better to write .
>
> @r@
> identifier e;
> struct list_head* l;
> @@
>
> <...
> container_of(l,...);
> ...>

This doesn't ensure that there is a preceding container_of, if that is
what you are trying to do.  The problem is that <... P ...> finds 0 or
more occurrences of pattern P, not 1 or more occurrences.  1 or more
occurrences is <+... P ...+>.  But it would be simpler if you want an
occurrence of container_of before the thing you are transforming to put

container_of(l,...);
...
e = ...

But this doesn't make sense either, partly because the preceding
container_of is just not needed, and also because a container_of would not
be in a statement by itself.  In Coccinelle, when you put a ; after
something is means that the thing is a complete statement, not just the
end half of a statement.

julia

> e =
> -container_of
> +list_entry
>      (
>       ....)
>
> >> (
> >> e =
> >> -container_of
> >> +list_entry
> >>      (
> >>       ...)
> >> )
> >
> > Here you don't need the outer ( ).  This makes a disjunction with only
> > one choice.  Since there is only one choice, you don't need the
> > disjunction.
>
> Thanks a lot , for pointing out the errors .
>
> Regards,
> Srishti
> > julia
> >
> >> Signed-off-by: Srishti Sharma <srishtishar@gmail.com>
> >> ---
> >>  drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 12 ++++++------
> >>  1 file changed, 6 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> >> index 22cf362..f9df4ac 100644
> >> --- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> >> +++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> >> @@ -152,8 +152,8 @@ u32       _rtw_free_sta_priv(struct       sta_priv *pstapriv)
> >>                       while (phead != plist) {
> >>                               int i;
> >>
> >> -                             psta = container_of(plist, struct sta_info,
> >> -                                                 hash_list);
> >> +                             psta = list_entry(plist, struct sta_info,
> >> +                                               hash_list);
> >>                               plist = plist->next;
> >>
> >>                               for (i = 0; i < 16; i++) {
> >> @@ -323,7 +323,7 @@ u32       rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta)
> >>               plist = phead->next;
> >>
> >>               while (!list_empty(phead)) {
> >> -                     prframe = container_of(plist, struct recv_frame, list);
> >> +                     prframe = list_entry(plist, struct recv_frame, list);
> >>
> >>                       plist = plist->next;
> >>
> >> @@ -399,7 +399,7 @@ void rtw_free_all_stainfo(struct adapter *padapter)
> >>               plist = phead->next;
> >>
> >>               while (phead != plist) {
> >> -                     psta = container_of(plist, struct sta_info, hash_list);
> >> +                     psta = list_entry(plist, struct sta_info, hash_list);
> >>
> >>                       plist = plist->next;
> >>
> >> @@ -435,7 +435,7 @@ struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
> >>       plist = phead->next;
> >>
> >>       while (phead != plist) {
> >> -             psta = container_of(plist, struct sta_info, hash_list);
> >> +             psta = list_entry(plist, struct sta_info, hash_list);
> >>
> >>               if ((!memcmp(psta->hwaddr, addr, ETH_ALEN)) == true) {
> >>                       /*  if found the matched address */
> >> @@ -493,7 +493,7 @@ u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr)
> >>       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 (!memcmp(paclnode->addr, mac_addr, ETH_ALEN)) {
> >> --
> >> 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 outreachy-kernel+unsubscribe@googlegroups.com.
> >> To post to this group, send email to outreachy-kernel@googlegroups.com.
> >> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1506734581-10932-1-git-send-email-srishtishar%40gmail.com.
> >> For more options, visit https://groups.google.com/d/optout.
> >>
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Outreachy kernel] [PATCH] Staging: rtl8188eu: core: Use list_entry instead of container_of
  2017-09-30  6:06     ` Julia Lawall
@ 2017-09-30  6:17       ` Srishti Sharma
  2017-09-30  6:21         ` Julia Lawall
  0 siblings, 1 reply; 9+ messages in thread
From: Srishti Sharma @ 2017-09-30  6:17 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Greg KH, devel, Linux kernel mailing list, outreachy-kernel

On Sat, Sep 30, 2017 at 11:36 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
>
>
> On Sat, 30 Sep 2017, Srishti Sharma wrote:
>
>> On Sat, Sep 30, 2017 at 10:35 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
>> >
>> >
>> > On Sat, 30 Sep 2017, Srishti Sharma wrote:
>> >
>> >> For variables of the type struct list_head* use list_entry to access
>> >> the current list element instead of using container_of.
>> >> Done using the following semantic patch by coccinelle.
>> >>
>> >> @r@
>> >> identifier e;
>> >> struct list_head* l;
>> >> @@
>> >>
>> >> <... when != l == NULL
>> >> l;
>> >> ...>
>> > I don't see what is the goal of the above code.  The list_head variable is
>> > not going to be in a statement by itself.  There is also no need to check
>> > for l being NULL.  If it is NULL, the original code is incorrect too.
>>
>> Since only those container_of are to replaced with list_entry which
>> have a variable of type list_head*  , I wanted to check if it occurs
>> anywhere before
>> container_of ,
>
> Why?  If it is a list, then it seems appropriate to access it using
> list_head.
>
>> which it only does in it's declaration , because it
>> can't be in any
>> statement by itself . I think it will be better to write .
>>
>> @r@
>> identifier e;
>> struct list_head* l;
>> @@
>>
>> <...
>> container_of(l,...);
>> ...>
>
> This doesn't ensure that there is a preceding container_of, if that is
> what you are trying to do.  The problem is that <... P ...> finds 0 or
> more occurrences of pattern P, not 1 or more occurrences.  1 or more
> occurrences is <+... P ...+>.  But it would be simpler if you want an
> occurrence of container_of before the thing you are transforming to put
>
> container_of(l,...);
> ...
> e = ...
>
> But this doesn't make sense either, partly because the preceding
> container_of is just not needed, and also because a container_of would not
> be in a statement by itself.  In Coccinelle, when you put a ; after
> something is means that the thing is a complete statement, not just the
> end half of a statement.

So , I guess we can simply write.

e =
-container_of
+list_entry
     (l,...)

Regards,
Srishti

>
> julia
>
>> e =
>> -container_of
>> +list_entry
>>      (
>>       ....)
>>
>> >> (
>> >> e =
>> >> -container_of
>> >> +list_entry
>> >>      (
>> >>       ...)
>> >> )
>> >
>> > Here you don't need the outer ( ).  This makes a disjunction with only
>> > one choice.  Since there is only one choice, you don't need the
>> > disjunction.
>>
>> Thanks a lot , for pointing out the errors .
>>
>> Regards,
>> Srishti
>> > julia
>> >
>> >> Signed-off-by: Srishti Sharma <srishtishar@gmail.com>
>> >> ---
>> >>  drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 12 ++++++------
>> >>  1 file changed, 6 insertions(+), 6 deletions(-)
>> >>
>> >> diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
>> >> index 22cf362..f9df4ac 100644
>> >> --- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
>> >> +++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
>> >> @@ -152,8 +152,8 @@ u32       _rtw_free_sta_priv(struct       sta_priv *pstapriv)
>> >>                       while (phead != plist) {
>> >>                               int i;
>> >>
>> >> -                             psta = container_of(plist, struct sta_info,
>> >> -                                                 hash_list);
>> >> +                             psta = list_entry(plist, struct sta_info,
>> >> +                                               hash_list);
>> >>                               plist = plist->next;
>> >>
>> >>                               for (i = 0; i < 16; i++) {
>> >> @@ -323,7 +323,7 @@ u32       rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta)
>> >>               plist = phead->next;
>> >>
>> >>               while (!list_empty(phead)) {
>> >> -                     prframe = container_of(plist, struct recv_frame, list);
>> >> +                     prframe = list_entry(plist, struct recv_frame, list);
>> >>
>> >>                       plist = plist->next;
>> >>
>> >> @@ -399,7 +399,7 @@ void rtw_free_all_stainfo(struct adapter *padapter)
>> >>               plist = phead->next;
>> >>
>> >>               while (phead != plist) {
>> >> -                     psta = container_of(plist, struct sta_info, hash_list);
>> >> +                     psta = list_entry(plist, struct sta_info, hash_list);
>> >>
>> >>                       plist = plist->next;
>> >>
>> >> @@ -435,7 +435,7 @@ struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
>> >>       plist = phead->next;
>> >>
>> >>       while (phead != plist) {
>> >> -             psta = container_of(plist, struct sta_info, hash_list);
>> >> +             psta = list_entry(plist, struct sta_info, hash_list);
>> >>
>> >>               if ((!memcmp(psta->hwaddr, addr, ETH_ALEN)) == true) {
>> >>                       /*  if found the matched address */
>> >> @@ -493,7 +493,7 @@ u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr)
>> >>       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 (!memcmp(paclnode->addr, mac_addr, ETH_ALEN)) {
>> >> --
>> >> 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 outreachy-kernel+unsubscribe@googlegroups.com.
>> >> To post to this group, send email to outreachy-kernel@googlegroups.com.
>> >> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1506734581-10932-1-git-send-email-srishtishar%40gmail.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >>
>>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Outreachy kernel] [PATCH] Staging: rtl8188eu: core: Use list_entry instead of container_of
  2017-09-30  6:17       ` Srishti Sharma
@ 2017-09-30  6:21         ` Julia Lawall
  2017-09-30  6:24           ` Srishti Sharma
  0 siblings, 1 reply; 9+ messages in thread
From: Julia Lawall @ 2017-09-30  6:21 UTC (permalink / raw)
  To: Srishti Sharma
  Cc: Greg KH, devel, Linux kernel mailing list, outreachy-kernel



On Sat, 30 Sep 2017, Srishti Sharma wrote:

> On Sat, Sep 30, 2017 at 11:36 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
> >
> >
> > On Sat, 30 Sep 2017, Srishti Sharma wrote:
> >
> >> On Sat, Sep 30, 2017 at 10:35 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
> >> >
> >> >
> >> > On Sat, 30 Sep 2017, Srishti Sharma wrote:
> >> >
> >> >> For variables of the type struct list_head* use list_entry to access
> >> >> the current list element instead of using container_of.
> >> >> Done using the following semantic patch by coccinelle.
> >> >>
> >> >> @r@
> >> >> identifier e;
> >> >> struct list_head* l;
> >> >> @@
> >> >>
> >> >> <... when != l == NULL
> >> >> l;
> >> >> ...>
> >> > I don't see what is the goal of the above code.  The list_head variable is
> >> > not going to be in a statement by itself.  There is also no need to check
> >> > for l being NULL.  If it is NULL, the original code is incorrect too.
> >>
> >> Since only those container_of are to replaced with list_entry which
> >> have a variable of type list_head*  , I wanted to check if it occurs
> >> anywhere before
> >> container_of ,
> >
> > Why?  If it is a list, then it seems appropriate to access it using
> > list_head.
> >
> >> which it only does in it's declaration , because it
> >> can't be in any
> >> statement by itself . I think it will be better to write .
> >>
> >> @r@
> >> identifier e;
> >> struct list_head* l;
> >> @@
> >>
> >> <...
> >> container_of(l,...);
> >> ...>
> >
> > This doesn't ensure that there is a preceding container_of, if that is
> > what you are trying to do.  The problem is that <... P ...> finds 0 or
> > more occurrences of pattern P, not 1 or more occurrences.  1 or more
> > occurrences is <+... P ...+>.  But it would be simpler if you want an
> > occurrence of container_of before the thing you are transforming to put
> >
> > container_of(l,...);
> > ...
> > e = ...
> >
> > But this doesn't make sense either, partly because the preceding
> > container_of is just not needed, and also because a container_of would not
> > be in a statement by itself.  In Coccinelle, when you put a ; after
> > something is means that the thing is a complete statement, not just the
> > end half of a statement.
>
> So , I guess we can simply write.
>
> e =
> -container_of
> +list_entry
>      (l,...)

Yes.  You don't even need the e =.  As long as there is a call to
container_of on a list_head * value, you can change it.

julia

>
> Regards,
> Srishti
>
> >
> > julia
> >
> >> e =
> >> -container_of
> >> +list_entry
> >>      (
> >>       ....)
> >>
> >> >> (
> >> >> e =
> >> >> -container_of
> >> >> +list_entry
> >> >>      (
> >> >>       ...)
> >> >> )
> >> >
> >> > Here you don't need the outer ( ).  This makes a disjunction with only
> >> > one choice.  Since there is only one choice, you don't need the
> >> > disjunction.
> >>
> >> Thanks a lot , for pointing out the errors .
> >>
> >> Regards,
> >> Srishti
> >> > julia
> >> >
> >> >> Signed-off-by: Srishti Sharma <srishtishar@gmail.com>
> >> >> ---
> >> >>  drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 12 ++++++------
> >> >>  1 file changed, 6 insertions(+), 6 deletions(-)
> >> >>
> >> >> diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> >> >> index 22cf362..f9df4ac 100644
> >> >> --- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> >> >> +++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
> >> >> @@ -152,8 +152,8 @@ u32       _rtw_free_sta_priv(struct       sta_priv *pstapriv)
> >> >>                       while (phead != plist) {
> >> >>                               int i;
> >> >>
> >> >> -                             psta = container_of(plist, struct sta_info,
> >> >> -                                                 hash_list);
> >> >> +                             psta = list_entry(plist, struct sta_info,
> >> >> +                                               hash_list);
> >> >>                               plist = plist->next;
> >> >>
> >> >>                               for (i = 0; i < 16; i++) {
> >> >> @@ -323,7 +323,7 @@ u32       rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta)
> >> >>               plist = phead->next;
> >> >>
> >> >>               while (!list_empty(phead)) {
> >> >> -                     prframe = container_of(plist, struct recv_frame, list);
> >> >> +                     prframe = list_entry(plist, struct recv_frame, list);
> >> >>
> >> >>                       plist = plist->next;
> >> >>
> >> >> @@ -399,7 +399,7 @@ void rtw_free_all_stainfo(struct adapter *padapter)
> >> >>               plist = phead->next;
> >> >>
> >> >>               while (phead != plist) {
> >> >> -                     psta = container_of(plist, struct sta_info, hash_list);
> >> >> +                     psta = list_entry(plist, struct sta_info, hash_list);
> >> >>
> >> >>                       plist = plist->next;
> >> >>
> >> >> @@ -435,7 +435,7 @@ struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
> >> >>       plist = phead->next;
> >> >>
> >> >>       while (phead != plist) {
> >> >> -             psta = container_of(plist, struct sta_info, hash_list);
> >> >> +             psta = list_entry(plist, struct sta_info, hash_list);
> >> >>
> >> >>               if ((!memcmp(psta->hwaddr, addr, ETH_ALEN)) == true) {
> >> >>                       /*  if found the matched address */
> >> >> @@ -493,7 +493,7 @@ u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr)
> >> >>       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 (!memcmp(paclnode->addr, mac_addr, ETH_ALEN)) {
> >> >> --
> >> >> 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 outreachy-kernel+unsubscribe@googlegroups.com.
> >> >> To post to this group, send email to outreachy-kernel@googlegroups.com.
> >> >> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1506734581-10932-1-git-send-email-srishtishar%40gmail.com.
> >> >> For more options, visit https://groups.google.com/d/optout.
> >> >>
> >>
>
> --
> 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 outreachy-kernel+unsubscribe@googlegroups.com.
> To post to this group, send email to outreachy-kernel@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CAB3L5ox9u0pj04pjkiC8MRgx%3DMZqwh%3Dg%3D2VE0-ZG8NYvrUrDBg%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Outreachy kernel] [PATCH] Staging: rtl8188eu: core: Use list_entry instead of container_of
  2017-09-30  6:21         ` Julia Lawall
@ 2017-09-30  6:24           ` Srishti Sharma
  0 siblings, 0 replies; 9+ messages in thread
From: Srishti Sharma @ 2017-09-30  6:24 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Greg KH, devel, Linux kernel mailing list, outreachy-kernel

On Sat, Sep 30, 2017 at 11:51 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
>
>
> On Sat, 30 Sep 2017, Srishti Sharma wrote:
>
>> On Sat, Sep 30, 2017 at 11:36 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
>> >
>> >
>> > On Sat, 30 Sep 2017, Srishti Sharma wrote:
>> >
>> >> On Sat, Sep 30, 2017 at 10:35 AM, Julia Lawall <julia.lawall@lip6.fr> wrote:
>> >> >
>> >> >
>> >> > On Sat, 30 Sep 2017, Srishti Sharma wrote:
>> >> >
>> >> >> For variables of the type struct list_head* use list_entry to access
>> >> >> the current list element instead of using container_of.
>> >> >> Done using the following semantic patch by coccinelle.
>> >> >>
>> >> >> @r@
>> >> >> identifier e;
>> >> >> struct list_head* l;
>> >> >> @@
>> >> >>
>> >> >> <... when != l == NULL
>> >> >> l;
>> >> >> ...>
>> >> > I don't see what is the goal of the above code.  The list_head variable is
>> >> > not going to be in a statement by itself.  There is also no need to check
>> >> > for l being NULL.  If it is NULL, the original code is incorrect too.
>> >>
>> >> Since only those container_of are to replaced with list_entry which
>> >> have a variable of type list_head*  , I wanted to check if it occurs
>> >> anywhere before
>> >> container_of ,
>> >
>> > Why?  If it is a list, then it seems appropriate to access it using
>> > list_head.
>> >
>> >> which it only does in it's declaration , because it
>> >> can't be in any
>> >> statement by itself . I think it will be better to write .
>> >>
>> >> @r@
>> >> identifier e;
>> >> struct list_head* l;
>> >> @@
>> >>
>> >> <...
>> >> container_of(l,...);
>> >> ...>
>> >
>> > This doesn't ensure that there is a preceding container_of, if that is
>> > what you are trying to do.  The problem is that <... P ...> finds 0 or
>> > more occurrences of pattern P, not 1 or more occurrences.  1 or more
>> > occurrences is <+... P ...+>.  But it would be simpler if you want an
>> > occurrence of container_of before the thing you are transforming to put
>> >
>> > container_of(l,...);
>> > ...
>> > e = ...
>> >
>> > But this doesn't make sense either, partly because the preceding
>> > container_of is just not needed, and also because a container_of would not
>> > be in a statement by itself.  In Coccinelle, when you put a ; after
>> > something is means that the thing is a complete statement, not just the
>> > end half of a statement.
>>
>> So , I guess we can simply write.
>>
>> e =
>> -container_of
>> +list_entry
>>      (l,...)
>
> Yes.  You don't even need the e =.  As long as there is a call to
> container_of on a list_head * value, you can change it.

Okay, Thanks again :) , I'll make the changes and resend .

Regards,
Srishti
>
> julia
>
>>
>> Regards,
>> Srishti
>>
>> >
>> > julia
>> >
>> >> e =
>> >> -container_of
>> >> +list_entry
>> >>      (
>> >>       ....)
>> >>
>> >> >> (
>> >> >> e =
>> >> >> -container_of
>> >> >> +list_entry
>> >> >>      (
>> >> >>       ...)
>> >> >> )
>> >> >
>> >> > Here you don't need the outer ( ).  This makes a disjunction with only
>> >> > one choice.  Since there is only one choice, you don't need the
>> >> > disjunction.
>> >>
>> >> Thanks a lot , for pointing out the errors .
>> >>
>> >> Regards,
>> >> Srishti
>> >> > julia
>> >> >
>> >> >> Signed-off-by: Srishti Sharma <srishtishar@gmail.com>
>> >> >> ---
>> >> >>  drivers/staging/rtl8188eu/core/rtw_sta_mgt.c | 12 ++++++------
>> >> >>  1 file changed, 6 insertions(+), 6 deletions(-)
>> >> >>
>> >> >> diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
>> >> >> index 22cf362..f9df4ac 100644
>> >> >> --- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
>> >> >> +++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
>> >> >> @@ -152,8 +152,8 @@ u32       _rtw_free_sta_priv(struct       sta_priv *pstapriv)
>> >> >>                       while (phead != plist) {
>> >> >>                               int i;
>> >> >>
>> >> >> -                             psta = container_of(plist, struct sta_info,
>> >> >> -                                                 hash_list);
>> >> >> +                             psta = list_entry(plist, struct sta_info,
>> >> >> +                                               hash_list);
>> >> >>                               plist = plist->next;
>> >> >>
>> >> >>                               for (i = 0; i < 16; i++) {
>> >> >> @@ -323,7 +323,7 @@ u32       rtw_free_stainfo(struct adapter *padapter, struct sta_info *psta)
>> >> >>               plist = phead->next;
>> >> >>
>> >> >>               while (!list_empty(phead)) {
>> >> >> -                     prframe = container_of(plist, struct recv_frame, list);
>> >> >> +                     prframe = list_entry(plist, struct recv_frame, list);
>> >> >>
>> >> >>                       plist = plist->next;
>> >> >>
>> >> >> @@ -399,7 +399,7 @@ void rtw_free_all_stainfo(struct adapter *padapter)
>> >> >>               plist = phead->next;
>> >> >>
>> >> >>               while (phead != plist) {
>> >> >> -                     psta = container_of(plist, struct sta_info, hash_list);
>> >> >> +                     psta = list_entry(plist, struct sta_info, hash_list);
>> >> >>
>> >> >>                       plist = plist->next;
>> >> >>
>> >> >> @@ -435,7 +435,7 @@ struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
>> >> >>       plist = phead->next;
>> >> >>
>> >> >>       while (phead != plist) {
>> >> >> -             psta = container_of(plist, struct sta_info, hash_list);
>> >> >> +             psta = list_entry(plist, struct sta_info, hash_list);
>> >> >>
>> >> >>               if ((!memcmp(psta->hwaddr, addr, ETH_ALEN)) == true) {
>> >> >>                       /*  if found the matched address */
>> >> >> @@ -493,7 +493,7 @@ u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr)
>> >> >>       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 (!memcmp(paclnode->addr, mac_addr, ETH_ALEN)) {
>> >> >> --
>> >> >> 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 outreachy-kernel+unsubscribe@googlegroups.com.
>> >> >> To post to this group, send email to outreachy-kernel@googlegroups.com.
>> >> >> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/1506734581-10932-1-git-send-email-srishtishar%40gmail.com.
>> >> >> For more options, visit https://groups.google.com/d/optout.
>> >> >>
>> >>
>>
>> --
>> 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 outreachy-kernel+unsubscribe@googlegroups.com.
>> To post to this group, send email to outreachy-kernel@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/CAB3L5ox9u0pj04pjkiC8MRgx%3DMZqwh%3Dg%3D2VE0-ZG8NYvrUrDBg%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] Staging: rtl8188eu: core: Use list_entry instead of container_of
@ 2017-10-04 13:09 Srishti Sharma
  0 siblings, 0 replies; 9+ messages in thread
From: Srishti Sharma @ 2017-10-04 13:09 UTC (permalink / raw)
  To: gregkh; +Cc: devel, linux-kernel, outreachy-kernel, Srishti Sharma

For variables of the struct list_head* use list_entry to access
current list element instead of using container_of.
Done using the following semantic patch by coccinelle.

@r@
struct list_head* l;
@@

-container_of
+list_entry
   (l,...)

Signed-off-by: Srishti Sharma <srishtishar@gmail.com>
---
 drivers/staging/rtl8188eu/core/rtw_ap.c       | 4 ++--
 drivers/staging/rtl8188eu/core/rtw_mlme.c     | 8 ++++----
 drivers/staging/rtl8188eu/core/rtw_mlme_ext.c | 2 +-
 drivers/staging/rtl8188eu/core/rtw_sta_mgt.c  | 8 ++++----
 drivers/staging/rtl8188eu/core/rtw_xmit.c     | 8 ++++----
 5 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_ap.c b/drivers/staging/rtl8188eu/core/rtw_ap.c
index 551af9e..c968472 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ap.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ap.c
@@ -1143,7 +1143,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)) {
@@ -1447,7 +1447,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;
 
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme.c b/drivers/staging/rtl8188eu/core/rtw_mlme.c
index b15cf17..82f25b6 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme.c
@@ -198,7 +198,7 @@ struct wlan_network *rtw_find_network(struct __queue *scanned_queue, u8 *addr)
 	plist = phead->next;
 
 	while (plist != phead) {
-		pnetwork = container_of(plist, struct wlan_network, list);
+		pnetwork = list_entry(plist, struct wlan_network, list);
 		if (!memcmp(addr, pnetwork->network.MacAddress, ETH_ALEN))
 			break;
 		plist = plist->next;
@@ -223,7 +223,7 @@ void rtw_free_network_queue(struct adapter *padapter, u8 isfreeall)
 	plist = phead->next;
 
 	while (phead != plist) {
-		pnetwork = container_of(plist, struct wlan_network, list);
+		pnetwork = list_entry(plist, struct wlan_network, list);
 
 		plist = plist->next;
 
@@ -342,7 +342,7 @@ struct	wlan_network	*rtw_get_oldest_wlan_network(struct __queue *scanned_queue)
 	phead = get_list_head(scanned_queue);
 
 	for (plist = phead->next; plist != phead; plist = plist->next) {
-		pwlan = container_of(plist, struct wlan_network, list);
+		pwlan = list_entry(plist, struct wlan_network, list);
 
 		if (!pwlan->fixed) {
 			if (!oldest || time_after(oldest->last_scanned, pwlan->last_scanned))
@@ -421,7 +421,7 @@ void rtw_update_scanned_network(struct adapter *adapter, struct wlan_bssid_ex *t
 	plist = phead->next;
 
 	while (phead != plist) {
-		pnetwork	= container_of(plist, struct wlan_network, list);
+		pnetwork	= list_entry(plist, struct wlan_network, list);
 
 		if (is_same_network(&(pnetwork->network), target))
 			break;
diff --git a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
index 4e1d06c..6ecc871 100644
--- a/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
+++ b/drivers/staging/rtl8188eu/core/rtw_mlme_ext.c
@@ -1790,7 +1790,7 @@ static void issue_action_BSSCoexistPacket(struct adapter *padapter)
 			u8 *p;
 			struct wlan_bssid_ex *pbss_network;
 
-			pnetwork = container_of(plist, struct wlan_network, list);
+			pnetwork = list_entry(plist, struct wlan_network, list);
 
 			plist = plist->next;
 
diff --git a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
index 2fd2a9e..21c4d38 100644
--- a/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
+++ b/drivers/staging/rtl8188eu/core/rtw_sta_mgt.c
@@ -152,8 +152,8 @@ u32	_rtw_free_sta_priv(struct	sta_priv *pstapriv)
 			while (phead != plist) {
 				int i;
 
-				psta = container_of(plist, struct sta_info,
-						    hash_list);
+				psta = list_entry(plist, struct sta_info,
+						  hash_list);
 				plist = plist->next;
 
 				for (i = 0; i < 16; i++) {
@@ -435,7 +435,7 @@ struct sta_info *rtw_get_stainfo(struct sta_priv *pstapriv, u8 *hwaddr)
 	plist = phead->next;
 
 	while (phead != plist) {
-		psta = container_of(plist, struct sta_info, hash_list);
+		psta = list_entry(plist, struct sta_info, hash_list);
 
 		if ((!memcmp(psta->hwaddr, addr, ETH_ALEN)) == true) {
 			/*  if found the matched address */
@@ -493,7 +493,7 @@ u8 rtw_access_ctrl(struct adapter *padapter, u8 *mac_addr)
 	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 (!memcmp(paclnode->addr, mac_addr, ETH_ALEN)) {
diff --git a/drivers/staging/rtl8188eu/core/rtw_xmit.c b/drivers/staging/rtl8188eu/core/rtw_xmit.c
index 6d8820b..3f4e55c 100644
--- a/drivers/staging/rtl8188eu/core/rtw_xmit.c
+++ b/drivers/staging/rtl8188eu/core/rtw_xmit.c
@@ -1401,7 +1401,7 @@ void rtw_free_xmitframe_queue(struct xmit_priv *pxmitpriv, struct __queue *pfram
 	plist = phead->next;
 
 	while (phead != plist) {
-		pxmitframe = container_of(plist, struct xmit_frame, list);
+		pxmitframe = list_entry(plist, struct xmit_frame, list);
 
 		plist = plist->next;
 
@@ -1432,7 +1432,7 @@ static struct xmit_frame *dequeue_one_xmitframe(struct xmit_priv *pxmitpriv, str
 	xmitframe_plist = xmitframe_phead->next;
 
 	if (xmitframe_phead != xmitframe_plist) {
-		pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
+		pxmitframe = list_entry(xmitframe_plist, struct xmit_frame, list);
 
 		xmitframe_plist = xmitframe_plist->next;
 
@@ -1473,7 +1473,7 @@ struct xmit_frame *rtw_dequeue_xframe(struct xmit_priv *pxmitpriv, struct hw_xmi
 		sta_plist = sta_phead->next;
 
 		while (sta_phead != sta_plist) {
-			ptxservq = container_of(sta_plist, struct tx_servq, tx_pending);
+			ptxservq = list_entry(sta_plist, struct tx_servq, tx_pending);
 
 			pframe_queue = &ptxservq->sta_pending;
 
@@ -1811,7 +1811,7 @@ static void dequeue_xmitframes_to_sleeping_queue(struct adapter *padapter, struc
 	plist = phead->next;
 
 	while (phead != plist) {
-		pxmitframe = container_of(plist, struct xmit_frame, list);
+		pxmitframe = list_entry(plist, struct xmit_frame, list);
 
 		plist = plist->next;
 
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH] Staging: rtl8188eu: core: Use list_entry instead of container_of
@ 2017-09-30  0:56 Srishti Sharma
  0 siblings, 0 replies; 9+ messages in thread
From: Srishti Sharma @ 2017-09-30  0:56 UTC (permalink / raw)
  To: gregkh; +Cc: devel, linux-kernel, outreachy-kernel, Srishti Sharma

For variables that have type struct list_head* use list_entry to
access current list element instead of using container_of.
Done using the following semantic patch by coccinelle.

@r@
identifier e;
struct list_head* l;
@@

<... when != l == NULL
l;
...>

(
e=
-container_of
+list_entry
    (
     ...)
)

Signed-off-by: Srishti Sharma <srishtishar@gmail.com>
---
 drivers/staging/rtl8188eu/core/rtw_recv.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_recv.c b/drivers/staging/rtl8188eu/core/rtw_recv.c
index 3fd5f41..af59c16 100644
--- a/drivers/staging/rtl8188eu/core/rtw_recv.c
+++ b/drivers/staging/rtl8188eu/core/rtw_recv.c
@@ -193,7 +193,7 @@ void rtw_free_recvframe_queue(struct __queue *pframequeue,  struct __queue *pfre
 	plist = phead->next;
 
 	while (phead != plist) {
-		hdr = container_of(plist, struct recv_frame, list);
+		hdr = list_entry(plist, struct recv_frame, list);
 
 		plist = plist->next;
 
@@ -943,7 +943,7 @@ static int validate_recv_ctrl_frame(struct adapter *padapter,
 			xmitframe_plist = xmitframe_phead->next;
 
 			if (xmitframe_phead != xmitframe_plist) {
-				pxmitframe = container_of(xmitframe_plist, struct xmit_frame, list);
+				pxmitframe = list_entry(xmitframe_plist, struct xmit_frame, list);
 
 				xmitframe_plist = xmitframe_plist->next;
 
@@ -1347,7 +1347,7 @@ static struct recv_frame *recvframe_defrag(struct adapter *adapter,
 
 	phead = get_list_head(defrag_q);
 	plist = phead->next;
-	pfhdr = container_of(plist, struct recv_frame, list);
+	pfhdr = list_entry(plist, struct recv_frame, list);
 	prframe = pfhdr;
 	list_del_init(&(prframe->list));
 
@@ -1367,7 +1367,7 @@ static struct recv_frame *recvframe_defrag(struct adapter *adapter,
 	plist = plist->next;
 
 	while (phead != plist) {
-		pnfhdr = container_of(plist, struct recv_frame, list);
+		pnfhdr = list_entry(plist, struct recv_frame, list);
 		pnextrframe = pnfhdr;
 
 		/* check the fragment sequence  (2nd ~n fragment frame) */
@@ -1655,7 +1655,7 @@ static int enqueue_reorder_recvframe(struct recv_reorder_ctrl *preorder_ctrl,
 	plist = phead->next;
 
 	while (phead != plist) {
-		hdr = container_of(plist, struct recv_frame, list);
+		hdr = list_entry(plist, struct recv_frame, list);
 		pnextattrib = &hdr->attrib;
 
 		if (SN_LESS(pnextattrib->seq_num, pattrib->seq_num))
@@ -1690,7 +1690,7 @@ static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reor
 		if (list_empty(phead))
 			return true;
 
-		prhdr = container_of(plist, struct recv_frame, list);
+		prhdr = list_entry(plist, struct recv_frame, list);
 		pattrib = &prhdr->attrib;
 		preorder_ctrl->indicate_seq = pattrib->seq_num;
 	}
@@ -1698,7 +1698,7 @@ static int recv_indicatepkts_in_order(struct adapter *padapter, struct recv_reor
 	/*  Prepare indication list and indication. */
 	/*  Check if there is any packet need indicate. */
 	while (!list_empty(phead)) {
-		prhdr = container_of(plist, struct recv_frame, list);
+		prhdr = list_entry(plist, struct recv_frame, list);
 		prframe = prhdr;
 		pattrib = &prframe->attrib;
 
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2017-10-04 13:09 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-30  1:23 [PATCH] Staging: rtl8188eu: core: Use list_entry instead of container_of Srishti Sharma
2017-09-30  5:05 ` [Outreachy kernel] " Julia Lawall
2017-09-30  6:01   ` Srishti Sharma
2017-09-30  6:06     ` Julia Lawall
2017-09-30  6:17       ` Srishti Sharma
2017-09-30  6:21         ` Julia Lawall
2017-09-30  6:24           ` Srishti Sharma
  -- strict thread matches above, loose matches on Subject: below --
2017-10-04 13:09 Srishti Sharma
2017-09-30  0:56 Srishti Sharma

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.