linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: rtl8192e: use is_zero_ether_addr() instead of memcmp()
@ 2012-08-23  7:19 Wei Yongjun
  2012-08-23  7:54 ` Eric Dumazet
  0 siblings, 1 reply; 3+ messages in thread
From: Wei Yongjun @ 2012-08-23  7:19 UTC (permalink / raw)
  To: gregkh; +Cc: yongjun_wei, devel, linux-kernel

From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

Using is_zero_ether_addr() instead of directly use
memcmp() to determine if the ethernet address is all
zeros.

spatch with a semantic match is used to found this problem.
(http://coccinelle.lip6.fr/)

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 drivers/staging/rtl8192e/rtllib_softmac_wx.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/rtl8192e/rtllib_softmac_wx.c b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
index 1bb6b52..3cedfd9 100644
--- a/drivers/staging/rtl8192e/rtllib_softmac_wx.c
+++ b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
@@ -14,6 +14,8 @@
  */
 
 
+#include <linux/etherdevice.h>
+
 #include "rtllib.h"
 #include "dot11d.h"
 /* FIXME: add A freqs */
@@ -137,7 +139,6 @@ int rtllib_wx_set_wap(struct rtllib_device *ieee,
 {
 
 	int ret = 0;
-	u8 zero[] = {0, 0, 0, 0, 0, 0};
 	unsigned long flags;
 
 	short ifup = ieee->proto_started;
@@ -157,7 +158,7 @@ int rtllib_wx_set_wap(struct rtllib_device *ieee,
 		goto out;
 	}
 
-	if (memcmp(temp->sa_data, zero, ETH_ALEN) == 0) {
+	if (is_zero_ether_addr(temp->sa_data)) {
 		spin_lock_irqsave(&ieee->lock, flags);
 		memcpy(ieee->current_network.bssid, temp->sa_data, ETH_ALEN);
 		ieee->wap_set = 0;
@@ -177,7 +178,7 @@ int rtllib_wx_set_wap(struct rtllib_device *ieee,
 
 	ieee->cannot_notify = false;
 	memcpy(ieee->current_network.bssid, temp->sa_data, ETH_ALEN);
-	ieee->wap_set = (memcmp(temp->sa_data, zero, ETH_ALEN) != 0);
+	ieee->wap_set = (!is_zero_ether_addr(temp->sa_data));
 
 	spin_unlock_irqrestore(&ieee->lock, flags);
 



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

* Re: [PATCH] staging: rtl8192e: use is_zero_ether_addr() instead of memcmp()
  2012-08-23  7:19 [PATCH] staging: rtl8192e: use is_zero_ether_addr() instead of memcmp() Wei Yongjun
@ 2012-08-23  7:54 ` Eric Dumazet
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Dumazet @ 2012-08-23  7:54 UTC (permalink / raw)
  To: Wei Yongjun; +Cc: gregkh, yongjun_wei, devel, linux-kernel

On Thu, 2012-08-23 at 15:19 +0800, Wei Yongjun wrote:
> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> 
> Using is_zero_ether_addr() instead of directly use
> memcmp() to determine if the ethernet address is all
> zeros.
> 
> spatch with a semantic match is used to found this problem.
> (http://coccinelle.lip6.fr/)
> 
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> ---
>  drivers/staging/rtl8192e/rtllib_softmac_wx.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/rtl8192e/rtllib_softmac_wx.c b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> index 1bb6b52..3cedfd9 100644
> --- a/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> +++ b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
> @@ -14,6 +14,8 @@
>   */
>  
> 
> +#include <linux/etherdevice.h>
> +
>  #include "rtllib.h"
>  #include "dot11d.h"
>  /* FIXME: add A freqs */
> @@ -137,7 +139,6 @@ int rtllib_wx_set_wap(struct rtllib_device *ieee,
>  {
>  
>  	int ret = 0;
> -	u8 zero[] = {0, 0, 0, 0, 0, 0};
>  	unsigned long flags;
>  
>  	short ifup = ieee->proto_started;
> @@ -157,7 +158,7 @@ int rtllib_wx_set_wap(struct rtllib_device *ieee,
>  		goto out;
>  	}
>  
> -	if (memcmp(temp->sa_data, zero, ETH_ALEN) == 0) {
> +	if (is_zero_ether_addr(temp->sa_data)) {
>  		spin_lock_irqsave(&ieee->lock, flags);
>  		memcpy(ieee->current_network.bssid, temp->sa_data, ETH_ALEN);

BTW this looks suspicious : Why is it using memcpy() if temp->sa_data is
known to be zero ?

>  		ieee->wap_set = 0;
> @@ -177,7 +178,7 @@ int rtllib_wx_set_wap(struct rtllib_device *ieee,
>  
>  	ieee->cannot_notify = false;
>  	memcpy(ieee->current_network.bssid, temp->sa_data, ETH_ALEN);
> -	ieee->wap_set = (memcmp(temp->sa_data, zero, ETH_ALEN) != 0);
> +	ieee->wap_set = (!is_zero_ether_addr(temp->sa_data));
>  
	ieee->wap_set = !is_zero_ether_addr(temp->sa_data);

>  	spin_unlock_irqrestore(&ieee->lock, flags);
>  
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/



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

* Re: [PATCH] staging: rtl8192e: use is_zero_ether_addr() instead of memcmp()
@ 2012-08-23  8:28 Wei Yongjun
  0 siblings, 0 replies; 3+ messages in thread
From: Wei Yongjun @ 2012-08-23  8:28 UTC (permalink / raw)
  To: eric.dumazet; +Cc: gregkh, devel, linux-kernel

On 08/23/2012 03:54 PM, Eric Dumazet wrote:
> On Thu, 2012-08-23 at 15:19 +0800, Wei Yongjun wrote:
>> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>>
>> Using is_zero_ether_addr() instead of directly use
>> memcmp() to determine if the ethernet address is all
>> zeros.
>>
>> spatch with a semantic match is used to found this problem.
>> (http://coccinelle.lip6.fr/)
>>
>> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>> ---
>>  drivers/staging/rtl8192e/rtllib_softmac_wx.c | 7 ++++---
>>  1 file changed, 4 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/staging/rtl8192e/rtllib_softmac_wx.c b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
>> index 1bb6b52..3cedfd9 100644
>> --- a/drivers/staging/rtl8192e/rtllib_softmac_wx.c
>> +++ b/drivers/staging/rtl8192e/rtllib_softmac_wx.c
>> @@ -14,6 +14,8 @@
>>   */
>>  
>>
>> +#include <linux/etherdevice.h>
>> +
>>  #include "rtllib.h"
>>  #include "dot11d.h"
>>  /* FIXME: add A freqs */
>> @@ -137,7 +139,6 @@ int rtllib_wx_set_wap(struct rtllib_device *ieee,
>>  {
>>  
>>  	int ret = 0;
>> -	u8 zero[] = {0, 0, 0, 0, 0, 0};
>>  	unsigned long flags;
>>  
>>  	short ifup = ieee->proto_started;
>> @@ -157,7 +158,7 @@ int rtllib_wx_set_wap(struct rtllib_device *ieee,
>>  		goto out;
>>  	}
>>  
>> -	if (memcmp(temp->sa_data, zero, ETH_ALEN) == 0) {
>> +	if (is_zero_ether_addr(temp->sa_data)) {
>>  		spin_lock_irqsave(&ieee->lock, flags);
>>  		memcpy(ieee->current_network.bssid, temp->sa_data, ETH_ALEN);
> BTW this looks suspicious : Why is it using memcpy() if temp->sa_data is
> known to be zero ?

I see the if (..) is dup of the following memcpy() code, just
used for return -1 for fast path.

rtl8192u does not has this check, and also do memcpy()
temp->sa_data to bssid even if is zero addr.

>
>>  		ieee->wap_set = 0;
>> @@ -177,7 +178,7 @@ int rtllib_wx_set_wap(struct rtllib_device *ieee,
>>  
>>  	ieee->cannot_notify = false;
>>  	memcpy(ieee->current_network.bssid, temp->sa_data, ETH_ALEN);
>> -	ieee->wap_set = (memcmp(temp->sa_data, zero, ETH_ALEN) != 0);
>> +	ieee->wap_set = (!is_zero_ether_addr(temp->sa_data));
>>  
> 	ieee->wap_set = !is_zero_ether_addr(temp->sa_data);

I will fix this and send the new patch.

>
>>  	spin_unlock_irqrestore(&ieee->lock, flags);
>>  
>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/
>
>
>



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

end of thread, other threads:[~2012-08-23  8:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-23  7:19 [PATCH] staging: rtl8192e: use is_zero_ether_addr() instead of memcmp() Wei Yongjun
2012-08-23  7:54 ` Eric Dumazet
2012-08-23  8:28 Wei Yongjun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).