From 092f239e9f03b35705129082a4962e25f6c0965d Mon Sep 17 00:00:00 2001 From: Sergio Paracuellos Date: Wed, 25 Apr 2018 16:01:46 +0200 Subject: [PATCH] staging: ks7010: refactor ks_wlan_set_pmksa function This commit cleans a bit ks_wlan_set_pmksa function removing nonsense comments as well as make use of ether_addr_* family functions written to not do manually things that were being here. Minor single if brackets has been removed also. Signed-off-by: Sergio Paracuellos Signed-off-by: Greg Kroah-Hartman --- drivers/staging/ks7010/ks_wlan_net.c | 45 +++++++++++++--------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/drivers/staging/ks7010/ks_wlan_net.c b/drivers/staging/ks7010/ks_wlan_net.c index a398b6a2b3e3..f3e83f9aa283 100644 --- a/drivers/staging/ks7010/ks_wlan_net.c +++ b/drivers/staging/ks7010/ks_wlan_net.c @@ -1694,68 +1694,65 @@ static int ks_wlan_set_pmksa(struct net_device *dev, switch (pmksa->cmd) { case IW_PMKSA_ADD: - if (list_empty(&priv->pmklist.head)) { /* new list */ + if (list_empty(&priv->pmklist.head)) { for (i = 0; i < PMK_LIST_MAX; i++) { pmk = &priv->pmklist.pmk[i]; - if (memcmp("\x00\x00\x00\x00\x00\x00", - pmk->bssid, ETH_ALEN) == 0) - break; /* loop */ + if (is_zero_ether_addr(pmk->bssid)) + break; } - memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN); + ether_addr_copy(pmk->bssid, pmksa->bssid.sa_data); memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); list_add(&pmk->list, &priv->pmklist.head); priv->pmklist.size++; - break; /* case */ + break; } /* search cache data */ list_for_each(ptr, &priv->pmklist.head) { pmk = list_entry(ptr, struct pmk, list); - if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) { + if (ether_addr_equal(pmksa->bssid.sa_data, pmk->bssid)) { memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); list_move(&pmk->list, &priv->pmklist.head); - break; /* list_for_each */ + break; } } - if (ptr != &priv->pmklist.head) /* not find address. */ - break; /* case */ - - if (priv->pmklist.size < PMK_LIST_MAX) { /* new cache data */ + /* not find address. */ + if (ptr != &priv->pmklist.head) + break; + /* new cache data */ + if (priv->pmklist.size < PMK_LIST_MAX) { for (i = 0; i < PMK_LIST_MAX; i++) { pmk = &priv->pmklist.pmk[i]; - if (memcmp("\x00\x00\x00\x00\x00\x00", - pmk->bssid, ETH_ALEN) == 0) - break; /* loop */ + if (is_zero_ether_addr(pmk->bssid)) + break; } - memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN); + ether_addr_copy(pmk->bssid, pmksa->bssid.sa_data); memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); list_add(&pmk->list, &priv->pmklist.head); priv->pmklist.size++; - } else { /* overwrite old cache data */ + } else { /* overwrite old cache data */ pmk = list_entry(priv->pmklist.head.prev, struct pmk, list); - memcpy(pmk->bssid, pmksa->bssid.sa_data, ETH_ALEN); + ether_addr_copy(pmk->bssid, pmksa->bssid.sa_data); memcpy(pmk->pmkid, pmksa->pmkid, IW_PMKID_LEN); list_move(&pmk->list, &priv->pmklist.head); } break; case IW_PMKSA_REMOVE: - if (list_empty(&priv->pmklist.head)) { /* list empty */ + if (list_empty(&priv->pmklist.head)) return -EINVAL; - } /* search cache data */ list_for_each(ptr, &priv->pmklist.head) { pmk = list_entry(ptr, struct pmk, list); - if (memcmp(pmksa->bssid.sa_data, pmk->bssid, ETH_ALEN) == 0) { + if (ether_addr_equal(pmksa->bssid.sa_data, pmk->bssid)) { eth_zero_addr(pmk->bssid); memset(pmk->pmkid, 0, IW_PMKID_LEN); list_del_init(&pmk->list); break; } } - if (ptr == &priv->pmklist.head) { /* not find address. */ + /* not find address. */ + if (ptr == &priv->pmklist.head) return 0; - } - break; case IW_PMKSA_FLUSH: memset(&priv->pmklist, 0, sizeof(priv->pmklist)); -- 2.30.2