Commit 54350dac authored by Jonas Dreßler's avatar Jonas Dreßler Committed by Kalle Valo

mwifiex: Use helper function for counting interface types

Use a small helper function to increment and decrement the counter of
the interface types we currently manage. This makes the code that
actually changes and sets up the interface type a bit less messy and
also helps avoiding mistakes in case someone increments/decrements a
counter wrongly.
Signed-off-by: default avatarJonas Dreßler <verdre@v0yd.nl>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210914195909.36035-5-verdre@v0yd.nl
parent c2e9666c
...@@ -1009,6 +1009,32 @@ is_vif_type_change_allowed(struct mwifiex_adapter *adapter, ...@@ -1009,6 +1009,32 @@ is_vif_type_change_allowed(struct mwifiex_adapter *adapter,
return false; return false;
} }
static void
update_vif_type_counter(struct mwifiex_adapter *adapter,
enum nl80211_iftype iftype,
int change)
{
switch (iftype) {
case NL80211_IFTYPE_UNSPECIFIED:
case NL80211_IFTYPE_ADHOC:
case NL80211_IFTYPE_STATION:
adapter->curr_iface_comb.sta_intf += change;
break;
case NL80211_IFTYPE_AP:
adapter->curr_iface_comb.uap_intf += change;
break;
case NL80211_IFTYPE_P2P_CLIENT:
case NL80211_IFTYPE_P2P_GO:
adapter->curr_iface_comb.p2p_intf += change;
break;
default:
mwifiex_dbg(adapter, ERROR,
"%s: Unsupported iftype passed: %d\n",
__func__, iftype);
break;
}
}
static int static int
mwifiex_change_vif_to_p2p(struct net_device *dev, mwifiex_change_vif_to_p2p(struct net_device *dev,
enum nl80211_iftype curr_iftype, enum nl80211_iftype curr_iftype,
...@@ -1056,19 +1082,8 @@ mwifiex_change_vif_to_p2p(struct net_device *dev, ...@@ -1056,19 +1082,8 @@ mwifiex_change_vif_to_p2p(struct net_device *dev,
if (mwifiex_sta_init_cmd(priv, false, false)) if (mwifiex_sta_init_cmd(priv, false, false))
return -1; return -1;
switch (curr_iftype) { update_vif_type_counter(adapter, curr_iftype, -1);
case NL80211_IFTYPE_STATION: update_vif_type_counter(adapter, type, +1);
case NL80211_IFTYPE_ADHOC:
adapter->curr_iface_comb.sta_intf--;
break;
case NL80211_IFTYPE_AP:
adapter->curr_iface_comb.uap_intf--;
break;
default:
break;
}
adapter->curr_iface_comb.p2p_intf++;
dev->ieee80211_ptr->iftype = type; dev->ieee80211_ptr->iftype = type;
return 0; return 0;
...@@ -1107,20 +1122,10 @@ mwifiex_change_vif_to_sta_adhoc(struct net_device *dev, ...@@ -1107,20 +1122,10 @@ mwifiex_change_vif_to_sta_adhoc(struct net_device *dev,
if (mwifiex_sta_init_cmd(priv, false, false)) if (mwifiex_sta_init_cmd(priv, false, false))
return -1; return -1;
switch (curr_iftype) { update_vif_type_counter(adapter, curr_iftype, -1);
case NL80211_IFTYPE_P2P_CLIENT: update_vif_type_counter(adapter, type, +1);
case NL80211_IFTYPE_P2P_GO:
adapter->curr_iface_comb.p2p_intf--;
break;
case NL80211_IFTYPE_AP:
adapter->curr_iface_comb.uap_intf--;
break;
default:
break;
}
adapter->curr_iface_comb.sta_intf++;
dev->ieee80211_ptr->iftype = type; dev->ieee80211_ptr->iftype = type;
return 0; return 0;
} }
...@@ -1153,20 +1158,8 @@ mwifiex_change_vif_to_ap(struct net_device *dev, ...@@ -1153,20 +1158,8 @@ mwifiex_change_vif_to_ap(struct net_device *dev,
if (mwifiex_sta_init_cmd(priv, false, false)) if (mwifiex_sta_init_cmd(priv, false, false))
return -1; return -1;
switch (curr_iftype) { update_vif_type_counter(adapter, curr_iftype, -1);
case NL80211_IFTYPE_P2P_CLIENT: update_vif_type_counter(adapter, type, +1);
case NL80211_IFTYPE_P2P_GO:
adapter->curr_iface_comb.p2p_intf--;
break;
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_ADHOC:
adapter->curr_iface_comb.sta_intf--;
break;
default:
break;
}
adapter->curr_iface_comb.uap_intf++;
dev->ieee80211_ptr->iftype = type; dev->ieee80211_ptr->iftype = type;
return 0; return 0;
} }
...@@ -3128,23 +3121,7 @@ struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy, ...@@ -3128,23 +3121,7 @@ struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
mwifiex_dev_debugfs_init(priv); mwifiex_dev_debugfs_init(priv);
#endif #endif
switch (type) { update_vif_type_counter(adapter, type, +1);
case NL80211_IFTYPE_UNSPECIFIED:
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_ADHOC:
adapter->curr_iface_comb.sta_intf++;
break;
case NL80211_IFTYPE_AP:
adapter->curr_iface_comb.uap_intf++;
break;
case NL80211_IFTYPE_P2P_CLIENT:
adapter->curr_iface_comb.p2p_intf++;
break;
default:
/* This should be dead code; checked above */
mwifiex_dbg(adapter, ERROR, "type not supported\n");
return ERR_PTR(-EINVAL);
}
return &priv->wdev; return &priv->wdev;
...@@ -3210,24 +3187,7 @@ int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev) ...@@ -3210,24 +3187,7 @@ int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev)
/* Clear the priv in adapter */ /* Clear the priv in adapter */
priv->netdev = NULL; priv->netdev = NULL;
switch (priv->bss_mode) { update_vif_type_counter(adapter, priv->bss_mode, -1);
case NL80211_IFTYPE_UNSPECIFIED:
case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_ADHOC:
adapter->curr_iface_comb.sta_intf--;
break;
case NL80211_IFTYPE_AP:
adapter->curr_iface_comb.uap_intf--;
break;
case NL80211_IFTYPE_P2P_CLIENT:
case NL80211_IFTYPE_P2P_GO:
adapter->curr_iface_comb.p2p_intf--;
break;
default:
mwifiex_dbg(adapter, ERROR,
"del_virtual_intf: type not supported\n");
break;
}
priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED; priv->bss_mode = NL80211_IFTYPE_UNSPECIFIED;
......
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