2016-04-07 09:39:54

by Shyam Saini

[permalink] [raw]
Subject: [PATCH 525/525] Staging: Wilc1000: Fixed coding style ether_addr_copy

Fixed following warning detected by checkpatch.pl:
warning: Prefer ether_addr_copy() over memcpy() if the Ethernet addressesare __aligned(2)

Signed-off-by: Shyam Saini <[email protected]>
---
drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 25 +++++++++++------------
1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index b76622d..3a5d04a 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -363,8 +363,8 @@ static void add_network_to_shadow(struct network_info *pstrNetworkInfo,
last_scanned_shadow[ap_index].ssid_len = pstrNetworkInfo->ssid_len;
memcpy(last_scanned_shadow[ap_index].ssid,
pstrNetworkInfo->ssid, pstrNetworkInfo->ssid_len);
- memcpy(last_scanned_shadow[ap_index].bssid,
- pstrNetworkInfo->bssid, ETH_ALEN);
+ ether_addr_copy(last_scanned_shadow[ap_index].bssid,
+ pstrNetworkInfo->bssid);
last_scanned_shadow[ap_index].beacon_period = pstrNetworkInfo->beacon_period;
last_scanned_shadow[ap_index].dtim_period = pstrNetworkInfo->dtim_period;
last_scanned_shadow[ap_index].ch = pstrNetworkInfo->ch;
@@ -521,7 +521,7 @@ static void CfgConnectResult(enum conn_event enuConnDisconnEvent,
bool bNeedScanRefresh = false;
u32 i;

- memcpy(priv->au8AssociatedBss, pstrConnectInfo->bssid, ETH_ALEN);
+ ether_addr_copy(priv->au8AssociatedBss, pstrConnectInfo->bssid);


for (i = 0; i < last_scanned_cnt; i++) {
@@ -1000,7 +1000,7 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
g_add_gtk_key_params.mac_addr = NULL;
} else {
g_add_gtk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
- memcpy(g_add_gtk_key_params.mac_addr, mac_addr, ETH_ALEN);
+ ether_addr_copy(g_add_gtk_key_params.mac_addr, mac_addr);
}
g_key_gtk_params.key_len = params->key_len;
g_key_gtk_params.seq_len = params->seq_len;
@@ -1033,7 +1033,7 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
g_add_ptk_key_params.mac_addr = NULL;
} else {
g_add_ptk_key_params.mac_addr = kmalloc(ETH_ALEN, GFP_KERNEL);
- memcpy(g_add_ptk_key_params.mac_addr, mac_addr, ETH_ALEN);
+ ether_addr_copy(g_add_ptk_key_params.mac_addr, mac_addr);
}
g_key_ptk_params.key_len = params->key_len;
g_key_ptk_params.seq_len = params->seq_len;
@@ -1287,8 +1287,8 @@ static int set_pmksa(struct wiphy *wiphy, struct net_device *netdev,
}
}
if (i < WILC_MAX_NUM_PMKIDS) {
- memcpy(priv->pmkid_list.pmkidlist[i].bssid, pmksa->bssid,
- ETH_ALEN);
+ ether_addr_copy(priv->pmkid_list.pmkidlist[i].bssid,
+ pmksa->bssid);
memcpy(priv->pmkid_list.pmkidlist[i].pmkid, pmksa->pmkid,
PMKID_LEN);
if (!(flag == PMKID_FOUND))
@@ -1322,9 +1322,8 @@ static int del_pmksa(struct wiphy *wiphy, struct net_device *netdev,

if (i < priv->pmkid_list.numpmkid && priv->pmkid_list.numpmkid > 0) {
for (; i < (priv->pmkid_list.numpmkid - 1); i++) {
- memcpy(priv->pmkid_list.pmkidlist[i].bssid,
- priv->pmkid_list.pmkidlist[i + 1].bssid,
- ETH_ALEN);
+ ether_addr_copy(priv->pmkid_list.pmkidlist[i].bssid,
+ priv->pmkid_list.pmkidlist[i + 1].bssid);
memcpy(priv->pmkid_list.pmkidlist[i].pmkid,
priv->pmkid_list.pmkidlist[i].pmkid,
PMKID_LEN);
@@ -1983,8 +1982,8 @@ static int add_station(struct wiphy *wiphy, struct net_device *dev,
vif = netdev_priv(dev);

if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) {
- memcpy(strStaParams.bssid, mac, ETH_ALEN);
- memcpy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac, ETH_ALEN);
+ ether_addr_copy(strStaParams.bssid, mac);
+ ether_addr_copy(priv->assoc_stainfo.au8Sta_AssociatedBss[params->aid], mac);
strStaParams.aid = params->aid;
strStaParams.rates_len = params->supported_rates_len;
strStaParams.rates = params->supported_rates;
@@ -2056,7 +2055,7 @@ static int change_station(struct wiphy *wiphy, struct net_device *dev,
vif = netdev_priv(dev);

if (vif->iftype == AP_MODE || vif->iftype == GO_MODE) {
- memcpy(strStaParams.bssid, mac, ETH_ALEN);
+ ether_addr_copy(strStaParams.bssid, mac);
strStaParams.aid = params->aid;
strStaParams.rates_len = params->supported_rates_len;
strStaParams.rates = params->supported_rates;
--
1.9.1


2016-04-07 11:00:36

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 525/525] Staging: Wilc1000: Fixed coding style ether_addr_copy

On Thu, 2016-04-07 at 15:07 +0530, Shyam Saini wrote:
> Fixed following warning detected by checkpatch.pl:
> warning: Prefer ether_addr_copy() over memcpy() if the Ethernet addressesare __aligned(2)

Please don't just do checkpatch cleanups but strive
to make the code more intelligible for humans.

Also, there's a malloc that may fail that writes through
the returned pointer that could be NULL.

The kmalloc/memcpy could be a kmemdup.

It would make the code shorter and clearer to remove
u32 ap_index and use a temporary pointer for all the
last_scanned_shadow[ap_index]. uses instead.

Something like:
---
?drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 54 +++++++++++------------
?1 file changed, 25 insertions(+), 29 deletions(-)

diff --git a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
index 358632b..35696e2 100644
--- a/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
+++ b/drivers/staging/wilc1000/wilc_wfi_cfgoperations.c
@@ -339,49 +339,45 @@ static void add_network_to_shadow(struct network_info *pstrNetworkInfo,
? ??void *user_void, void *pJoinParams)
?{
? int ap_found = is_network_in_shadow(pstrNetworkInfo, user_void);
- u32 ap_index = 0;
? u8 rssi_index = 0;
+ struct network_info *ni;
?
? if (last_scanned_cnt >= MAX_NUM_SCANNED_NETWORKS_SHADOW)
? return;
?
? if (ap_found == -1) {
- ap_index = last_scanned_cnt;
+ ni = &last_scanned_shadow[last_scanned_cnt];
? last_scanned_cnt++;
? } else {
- ap_index = ap_found;
+ ni = &last_scanned_shadow[ap_found];
? }
- rssi_index = last_scanned_shadow[ap_index].str_rssi.u8Index;
- last_scanned_shadow[ap_index].str_rssi.as8RSSI[rssi_index++] = pstrNetworkInfo->rssi;
+ rssi_index = ni->str_rssi.u8Index;
+ ni->str_rssi.as8RSSI[rssi_index++] = pstrNetworkInfo->rssi;
? if (rssi_index == NUM_RSSI) {
? rssi_index = 0;
- last_scanned_shadow[ap_index].str_rssi.u8Full = 1;
+ ni->str_rssi.u8Full = 1;
? }
- last_scanned_shadow[ap_index].str_rssi.u8Index = rssi_index;
- last_scanned_shadow[ap_index].rssi = pstrNetworkInfo->rssi;
- last_scanned_shadow[ap_index].cap_info = pstrNetworkInfo->cap_info;
- last_scanned_shadow[ap_index].ssid_len = pstrNetworkInfo->ssid_len;
- memcpy(last_scanned_shadow[ap_index].ssid,
- ???????pstrNetworkInfo->ssid, pstrNetworkInfo->ssid_len);
- memcpy(last_scanned_shadow[ap_index].bssid,
- ???????pstrNetworkInfo->bssid, ETH_ALEN);
- last_scanned_shadow[ap_index].beacon_period = pstrNetworkInfo->beacon_period;
- last_scanned_shadow[ap_index].dtim_period = pstrNetworkInfo->dtim_period;
- last_scanned_shadow[ap_index].ch = pstrNetworkInfo->ch;
- last_scanned_shadow[ap_index].ies_len = pstrNetworkInfo->ies_len;
- last_scanned_shadow[ap_index].tsf_hi = pstrNetworkInfo->tsf_hi;
+ ni->str_rssi.u8Index = rssi_index;
+ ni->rssi = pstrNetworkInfo->rssi;
+ ni->cap_info = pstrNetworkInfo->cap_info;
+ ni->ssid_len = pstrNetworkInfo->ssid_len;
+ memcpy(ni->ssid, pstrNetworkInfo->ssid, pstrNetworkInfo->ssid_len);
+ ether_addr_copy(ni->bssid, pstrNetworkInfo->bssid);
+ ni->beacon_period = pstrNetworkInfo->beacon_period;
+ ni->dtim_period = pstrNetworkInfo->dtim_period;
+ ni->ch = pstrNetworkInfo->ch;
+ ni->ies_len = pstrNetworkInfo->ies_len;
+ ni->tsf_hi = pstrNetworkInfo->tsf_hi;
? if (ap_found != -1)
- kfree(last_scanned_shadow[ap_index].ies);
- last_scanned_shadow[ap_index].ies = kmalloc(pstrNetworkInfo->ies_len,
- ????GFP_KERNEL);
- memcpy(last_scanned_shadow[ap_index].ies,
- ???????pstrNetworkInfo->ies, pstrNetworkInfo->ies_len);
- last_scanned_shadow[ap_index].time_scan = jiffies;
- last_scanned_shadow[ap_index].time_scan_cached = jiffies;
- last_scanned_shadow[ap_index].found = 1;
+ kfree(ni->ies);
+ ni->ies = kmemdup(pstrNetworkInfo->ies, pstrNetworkInfo->ies_len,
+ ??GFP_KERNEL);
+ ni->time_scan = jiffies;
+ ni->time_scan_cached = jiffies;
+ ni->found = 1;
? if (ap_found != -1)
- kfree(last_scanned_shadow[ap_index].join_params);
- last_scanned_shadow[ap_index].join_params = pJoinParams;
+ kfree(ni->join_params);
+ ni->join_params = pJoinParams;
?}
?
?static void CfgScanResult(enum scan_event scan_event,

2016-04-07 14:49:41

by Greg Kroah-Hartman

[permalink] [raw]
Subject: Re: [PATCH 525/525] Staging: Wilc1000: Fixed coding style ether_addr_copy

On Thu, Apr 07, 2016 at 03:07:15PM +0530, Shyam Saini wrote:
> Fixed following warning detected by checkpatch.pl:
> warning: Prefer ether_addr_copy() over memcpy() if the Ethernet addressesare __aligned(2)
>
> Signed-off-by: Shyam Saini <[email protected]>
> ---
> drivers/staging/wilc1000/wilc_wfi_cfgoperations.c | 25 +++++++++++------------
> 1 file changed, 12 insertions(+), 13 deletions(-)

Where are the 524 other patches in this series? I don't seem to see
them in my inbox anywhere, so I can't apply this last one either :(

thanks,

greg k-h