Commit 7cec84fd authored by Ajay Singh's avatar Ajay Singh Committed by Greg Kroah-Hartman

staging: wilc1000: split add_key() to avoid line over 80 chars

Cleanup changes to fix 'line over 80 chars' issue found by checkpatch.pl
script by spliting the function. Also make use of kzalloc() instead
kmalloc().
Signed-off-by: default avatarAjay Singh <ajay.kathat@microchip.com>
Reviewed-by: default avatarClaudiu Beznea <claudiu.beznea@microchip.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent e1f769c5
......@@ -859,6 +859,58 @@ static int disconnect(struct wiphy *wiphy, struct net_device *dev,
return ret;
}
static inline void wilc_wfi_cfg_copy_wep_info(struct wilc_priv *priv,
u8 key_index,
struct key_params *params)
{
priv->wep_key_len[key_index] = params->key_len;
memcpy(priv->wep_key[key_index], params->key, params->key_len);
}
static int wilc_wfi_cfg_allocate_wpa_entry(struct wilc_priv *priv, u8 idx)
{
if (!priv->wilc_gtk[idx]) {
priv->wilc_gtk[idx] = kzalloc(sizeof(struct wilc_wfi_key),
GFP_KERNEL);
if (!priv->wilc_gtk[idx])
return -ENOMEM;
}
if (!priv->wilc_ptk[idx]) {
priv->wilc_ptk[idx] = kzalloc(sizeof(struct wilc_wfi_key),
GFP_KERNEL);
if (!priv->wilc_ptk[idx])
return -ENOMEM;
}
return 0;
}
static int wilc_wfi_cfg_copy_wpa_info(struct wilc_wfi_key *key_info,
struct key_params *params)
{
kfree(key_info->key);
key_info->key = kmemdup(params->key, params->key_len, GFP_KERNEL);
if (!key_info->key)
return -ENOMEM;
kfree(key_info->seq);
if (params->seq_len > 0) {
key_info->seq = kmemdup(params->seq, params->seq_len,
GFP_KERNEL);
if (!key_info->seq)
return -ENOMEM;
}
key_info->cipher = params->cipher;
key_info->key_len = params->key_len;
key_info->seq_len = params->seq_len;
return 0;
}
static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
bool pairwise,
const u8 *mac_addr, struct key_params *params)
......@@ -883,8 +935,7 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
case WLAN_CIPHER_SUITE_WEP40:
case WLAN_CIPHER_SUITE_WEP104:
if (priv->wdev->iftype == NL80211_IFTYPE_AP) {
priv->wep_key_len[key_index] = params->key_len;
memcpy(priv->wep_key[key_index], params->key, params->key_len);
wilc_wfi_cfg_copy_wep_info(priv, key_index, params);
auth_type = OPEN_SYSTEM;
......@@ -898,9 +949,9 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
mode, auth_type);
break;
}
if (memcmp(params->key, priv->wep_key[key_index], params->key_len)) {
priv->wep_key_len[key_index] = params->key_len;
memcpy(priv->wep_key[key_index], params->key, params->key_len);
if (memcmp(params->key, priv->wep_key[key_index],
params->key_len)) {
wilc_wfi_cfg_copy_wep_info(priv, key_index, params);
wilc_add_wep_key_bss_sta(vif, params->key,
params->key_len, key_index);
......@@ -910,17 +961,9 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
case WLAN_CIPHER_SUITE_TKIP:
case WLAN_CIPHER_SUITE_CCMP:
if (priv->wdev->iftype == NL80211_IFTYPE_AP || priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
if (!priv->wilc_gtk[key_index]) {
priv->wilc_gtk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
priv->wilc_gtk[key_index]->key = NULL;
priv->wilc_gtk[key_index]->seq = NULL;
}
if (!priv->wilc_ptk[key_index]) {
priv->wilc_ptk[key_index] = kmalloc(sizeof(struct wilc_wfi_key), GFP_KERNEL);
priv->wilc_ptk[key_index]->key = NULL;
priv->wilc_ptk[key_index]->seq = NULL;
}
if (priv->wdev->iftype == NL80211_IFTYPE_AP ||
priv->wdev->iftype == NL80211_IFTYPE_P2P_GO) {
wilc_wfi_cfg_allocate_wpa_entry(priv, key_index);
if (!pairwise) {
if (params->cipher == WLAN_CIPHER_SUITE_TKIP)
......@@ -935,20 +978,8 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
rx_mic = params->key + 16;
keylen = params->key_len - 16;
}
kfree(priv->wilc_gtk[key_index]->key);
priv->wilc_gtk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
memcpy(priv->wilc_gtk[key_index]->key, params->key, params->key_len);
kfree(priv->wilc_gtk[key_index]->seq);
if (params->seq_len > 0) {
priv->wilc_gtk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
memcpy(priv->wilc_gtk[key_index]->seq, params->seq, params->seq_len);
}
priv->wilc_gtk[key_index]->cipher = params->cipher;
priv->wilc_gtk[key_index]->key_len = params->key_len;
priv->wilc_gtk[key_index]->seq_len = params->seq_len;
wilc_wfi_cfg_copy_wpa_info(priv->wilc_gtk[key_index],
params);
wilc_add_rx_gtk(vif, params->key, keylen,
key_index, params->seq_len,
......@@ -967,19 +998,8 @@ static int add_key(struct wiphy *wiphy, struct net_device *netdev, u8 key_index,
keylen = params->key_len - 16;
}
kfree(priv->wilc_ptk[key_index]->key);
priv->wilc_ptk[key_index]->key = kmalloc(params->key_len, GFP_KERNEL);
memcpy(priv->wilc_ptk[key_index]->key, params->key, params->key_len);
kfree(priv->wilc_ptk[key_index]->seq);
if (params->seq_len > 0) {
priv->wilc_ptk[key_index]->seq = kmalloc(params->seq_len, GFP_KERNEL);
memcpy(priv->wilc_ptk[key_index]->seq, params->seq, params->seq_len);
}
priv->wilc_ptk[key_index]->cipher = params->cipher;
priv->wilc_ptk[key_index]->key_len = params->key_len;
priv->wilc_ptk[key_index]->seq_len = params->seq_len;
wilc_wfi_cfg_copy_wpa_info(priv->wilc_ptk[key_index],
params);
wilc_add_ptk(vif, params->key, keylen,
mac_addr, rx_mic, tx_mic,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment