Skip to contentSkip to conversation

staging: rtl8712: avoid a useless call to memset().

PATCH Superseded Cyril Roelandt 4 participants 6 messages Dec 5, 2012 – Dec 10, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rtl8712: avoid a useless call to memset().

In r8711_wx_get_wap(), make sure we do not call memcpy() on a memory area that has just been zeroed by a call to memset().

---
 drivers/staging/rtl8712/rtl871x_ioctl_linux.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rtl8712/rtl871x_ioctl_linux.c +2 -1
index 3a64790..2c73319 100644
@@ -1131,10 +1131,11 @@ static int r8711_wx_get_wap(struct net_device *dev,
 	struct ndis_wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
 
 	wrqu->ap_addr.sa_family = ARPHRD_ETHER;
-	memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
 	if (check_fwstate(pmlmepriv, _FW_LINKED |
 	    WIFI_ADHOC_MASTER_STATE|WIFI_AP_STATE)) {
 		memcpy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress, ETH_ALEN);
+	} else {
+		memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
 	}
 	return 0;
 }
Signature · 1 line
1.7.10.4
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Cyril Roelandt

In r8711_wx_get_wap(), make sure we do not call memcpy() on a memory area that has just been zeroed by a call to memset().

---
  drivers/staging/rtl8712/rtl871x_ioctl_linux.c |    3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

Thanks,

Larry

Quoted 19 lines
drivers/staging/rtl8712/rtl871x_ioctl_linux.c +2 -1
index 3a64790..2c73319 100644
@@ -1131,10 +1131,11 @@ static int r8711_wx_get_wap(struct net_device *dev,
  	struct ndis_wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
 
  	wrqu->ap_addr.sa_family = ARPHRD_ETHER;
-	memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
  	if (check_fwstate(pmlmepriv, _FW_LINKED |
  	    WIFI_ADHOC_MASTER_STATE|WIFI_AP_STATE)) {
  		memcpy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress, ETH_ALEN);
+	} else {
+		memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
  	}
  	return 0;
  }
#2 lore raw
In reply to Cyril Roelandt
Quoted 3 lines · Cyril Roelandt

In r8711_wx_get_wap(), make sure we do not call memcpy() on a memory area that has just been zeroed by a call to memset().

I look at it like the original code is fine. Your version is also fine but is it worth the churn? Also the curly braces are not needed.

regards,
dan carpenter

#3 lore raw
Quoted 9 lines · Dan Carpenter
Quoted 3 lines · Cyril Roelandt

In r8711_wx_get_wap(), make sure we do not call memcpy() on a memory area that has just been zeroed by a call to memset().

I look at it like the original code is fine. Your version is also fine but is it worth the churn? Also the curly braces are not needed.

Sorry about the braces.

I just thought the code would be easier to understand this way, but it's probably OK to leave it as it currently is too.

WBR,
Cyril Roelandt.

#4 lore raw
Quoted 11 lines · Cyril Roelandt
Quoted 9 lines · Dan Carpenter
Quoted 3 lines · Cyril Roelandt

In r8711_wx_get_wap(), make sure we do not call memcpy() on a memory area that has just been zeroed by a call to memset().

I look at it like the original code is fine. Your version is also fine but is it worth the churn? Also the curly braces are not needed.

Quoted 5 lines

Sorry about the braces.

I just thought the code would be easier to understand this way, but it's probably OK to leave it as it currently is too.

Ah. I'd buy that. I like readability fixes. The indenting is also messed up and confusing. It should be:

	if (check_fwstate(pmlmepriv, _FW_LINKED | WIFI_ADHOC_MASTER_STATE |
				     WIFI_AP_STATE))
		memcpy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress, ETH_ALEN);
	else
		memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);

regards,
dan carpenter

#5 lore raw
In reply to Cyril Roelandt

Hi Cyril,
you patch is correct ..but being an advocate of defensive programming i would say the original version especially since the number of bytes is small.

re,
wh

Am 05.12.2012 02:22, schrieb Cyril Roelandt:

Quoted 25 lines

In r8711_wx_get_wap(), make sure we do not call memcpy() on a memory area that has just been zeroed by a call to memset().

---
 drivers/staging/rtl8712/rtl871x_ioctl_linux.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/staging/rtl8712/rtl871x_ioctl_linux.c +2 -1
index 3a64790..2c73319 100644
@@ -1131,10 +1131,11 @@ static int r8711_wx_get_wap(struct net_device *dev,
 	struct ndis_wlan_bssid_ex *pcur_bss = &pmlmepriv->cur_network.network;
 
 	wrqu->ap_addr.sa_family = ARPHRD_ETHER;
-	memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
 	if (check_fwstate(pmlmepriv, _FW_LINKED |
 	    WIFI_ADHOC_MASTER_STATE|WIFI_AP_STATE)) {
 		memcpy(wrqu->ap_addr.sa_data, pcur_bss->MacAddress, ETH_ALEN);
+	} else {
+		memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
 	}
 	return 0;
 }