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

staging: wilc1000: avoid the use of 'wilc_wfi_mon' static variable

Avoid use of static variable for monitor net_device and move it inside
wilc structure.
Signed-off-by: default avatarAjay Singh <ajay.kathat@microchip.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5ae89078
...@@ -18,8 +18,6 @@ struct wilc_wfi_radiotap_cb_hdr { ...@@ -18,8 +18,6 @@ struct wilc_wfi_radiotap_cb_hdr {
u16 tx_flags; u16 tx_flags;
} __packed; } __packed;
static struct net_device *wilc_wfi_mon; /* global monitor netdev */
static u8 srcadd[6]; static u8 srcadd[6];
static u8 bssid[6]; static u8 bssid[6];
...@@ -29,17 +27,17 @@ static u8 bssid[6]; ...@@ -29,17 +27,17 @@ static u8 bssid[6];
#define TX_RADIOTAP_PRESENT ((1 << IEEE80211_RADIOTAP_RATE) | \ #define TX_RADIOTAP_PRESENT ((1 << IEEE80211_RADIOTAP_RATE) | \
(1 << IEEE80211_RADIOTAP_TX_FLAGS)) (1 << IEEE80211_RADIOTAP_TX_FLAGS))
void wilc_wfi_monitor_rx(u8 *buff, u32 size) void wilc_wfi_monitor_rx(struct net_device *mon_dev, u8 *buff, u32 size)
{ {
u32 header, pkt_offset; u32 header, pkt_offset;
struct sk_buff *skb = NULL; struct sk_buff *skb = NULL;
struct wilc_wfi_radiotap_hdr *hdr; struct wilc_wfi_radiotap_hdr *hdr;
struct wilc_wfi_radiotap_cb_hdr *cb_hdr; struct wilc_wfi_radiotap_cb_hdr *cb_hdr;
if (!wilc_wfi_mon) if (!mon_dev)
return; return;
if (!netif_running(wilc_wfi_mon)) if (!netif_running(mon_dev))
return; return;
/* Get WILC header */ /* Get WILC header */
...@@ -94,7 +92,7 @@ void wilc_wfi_monitor_rx(u8 *buff, u32 size) ...@@ -94,7 +92,7 @@ void wilc_wfi_monitor_rx(u8 *buff, u32 size)
hdr->rate = 5; hdr->rate = 5;
} }
skb->dev = wilc_wfi_mon; skb->dev = mon_dev;
skb_reset_mac_header(skb); skb_reset_mac_header(skb);
skb->ip_summed = CHECKSUM_UNNECESSARY; skb->ip_summed = CHECKSUM_UNNECESSARY;
skb->pkt_type = PACKET_OTHERHOST; skb->pkt_type = PACKET_OTHERHOST;
...@@ -156,12 +154,10 @@ static netdev_tx_t wilc_wfi_mon_xmit(struct sk_buff *skb, ...@@ -156,12 +154,10 @@ static netdev_tx_t wilc_wfi_mon_xmit(struct sk_buff *skb,
struct sk_buff *skb2; struct sk_buff *skb2;
struct wilc_wfi_radiotap_cb_hdr *cb_hdr; struct wilc_wfi_radiotap_cb_hdr *cb_hdr;
if (!wilc_wfi_mon) mon_priv = netdev_priv(dev);
return -EFAULT;
mon_priv = netdev_priv(wilc_wfi_mon);
if (!mon_priv) if (!mon_priv)
return -EFAULT; return -EFAULT;
rtap_len = ieee80211_get_radiotap_len(skb->data); rtap_len = ieee80211_get_radiotap_len(skb->data);
if (skb->len < rtap_len) if (skb->len < rtap_len)
return -1; return -1;
...@@ -187,7 +183,7 @@ static netdev_tx_t wilc_wfi_mon_xmit(struct sk_buff *skb, ...@@ -187,7 +183,7 @@ static netdev_tx_t wilc_wfi_mon_xmit(struct sk_buff *skb,
cb_hdr->rate = 5; cb_hdr->rate = 5;
cb_hdr->tx_flags = 0x0004; cb_hdr->tx_flags = 0x0004;
skb2->dev = wilc_wfi_mon; skb2->dev = dev;
skb_reset_mac_header(skb2); skb_reset_mac_header(skb2);
skb2->ip_summed = CHECKSUM_UNNECESSARY; skb2->ip_summed = CHECKSUM_UNNECESSARY;
skb2->pkt_type = PACKET_OTHERHOST; skb2->pkt_type = PACKET_OTHERHOST;
...@@ -223,51 +219,53 @@ static const struct net_device_ops wilc_wfi_netdev_ops = { ...@@ -223,51 +219,53 @@ static const struct net_device_ops wilc_wfi_netdev_ops = {
}; };
struct net_device *wilc_wfi_init_mon_interface(const char *name, struct net_device *wilc_wfi_init_mon_interface(struct wilc *wl,
const char *name,
struct net_device *real_dev) struct net_device *real_dev)
{ {
struct wilc_wfi_mon_priv *priv; struct wilc_wfi_mon_priv *priv;
/*If monitor interface is already initialized, return it*/ /*If monitor interface is already initialized, return it*/
if (wilc_wfi_mon) if (wl->monitor_dev)
return wilc_wfi_mon; return wl->monitor_dev;
wilc_wfi_mon = alloc_etherdev(sizeof(struct wilc_wfi_mon_priv)); wl->monitor_dev = alloc_etherdev(sizeof(struct wilc_wfi_mon_priv));
if (!wilc_wfi_mon) if (!wl->monitor_dev)
return NULL; return NULL;
wilc_wfi_mon->type = ARPHRD_IEEE80211_RADIOTAP;
strncpy(wilc_wfi_mon->name, name, IFNAMSIZ);
wilc_wfi_mon->name[IFNAMSIZ - 1] = 0;
wilc_wfi_mon->netdev_ops = &wilc_wfi_netdev_ops;
if (register_netdevice(wilc_wfi_mon)) { wl->monitor_dev->type = ARPHRD_IEEE80211_RADIOTAP;
strncpy(wl->monitor_dev->name, name, IFNAMSIZ);
wl->monitor_dev->name[IFNAMSIZ - 1] = 0;
wl->monitor_dev->netdev_ops = &wilc_wfi_netdev_ops;
if (register_netdevice(wl->monitor_dev)) {
netdev_err(real_dev, "register_netdevice failed\n"); netdev_err(real_dev, "register_netdevice failed\n");
return NULL; return NULL;
} }
priv = netdev_priv(wilc_wfi_mon); priv = netdev_priv(wl->monitor_dev);
if (!priv) if (!priv)
return NULL; return NULL;
priv->real_ndev = real_dev; priv->real_ndev = real_dev;
return wilc_wfi_mon; return wl->monitor_dev;
} }
void wilc_wfi_deinit_mon_interface(void) void wilc_wfi_deinit_mon_interface(struct wilc *wl)
{ {
bool rollback_lock = false; bool rollback_lock = false;
if (wilc_wfi_mon) { if (wl->monitor_dev) {
if (rtnl_is_locked()) { if (rtnl_is_locked()) {
rtnl_unlock(); rtnl_unlock();
rollback_lock = true; rollback_lock = true;
} }
unregister_netdev(wilc_wfi_mon); unregister_netdev(wl->monitor_dev);
if (rollback_lock) { if (rollback_lock) {
rtnl_lock(); rtnl_lock();
rollback_lock = false; rollback_lock = false;
} }
wilc_wfi_mon = NULL; wl->monitor_dev = NULL;
} }
} }
...@@ -920,7 +920,7 @@ static int wilc_mac_close(struct net_device *ndev) ...@@ -920,7 +920,7 @@ static int wilc_mac_close(struct net_device *ndev)
netdev_dbg(ndev, "Deinitializing wilc1000\n"); netdev_dbg(ndev, "Deinitializing wilc1000\n");
wl->close = 1; wl->close = 1;
wilc_wlan_deinitialize(ndev); wilc_wlan_deinitialize(ndev);
wilc_wfi_deinit_mon_interface(); wilc_wfi_deinit_mon_interface(wl);
} }
vif->mac_opened = 0; vif->mac_opened = 0;
...@@ -976,7 +976,7 @@ void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size) ...@@ -976,7 +976,7 @@ void wilc_wfi_mgmt_rx(struct wilc *wilc, u8 *buff, u32 size)
for (i = 0; i < wilc->vif_num; i++) { for (i = 0; i < wilc->vif_num; i++) {
vif = netdev_priv(wilc->vif[i]->ndev); vif = netdev_priv(wilc->vif[i]->ndev);
if (vif->monitor_flag) { if (vif->monitor_flag) {
wilc_wfi_monitor_rx(buff, size); wilc_wfi_monitor_rx(wilc->monitor_dev, buff, size);
return; return;
} }
} }
......
...@@ -1617,7 +1617,8 @@ static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy, ...@@ -1617,7 +1617,8 @@ static struct wireless_dev *add_virtual_intf(struct wiphy *wiphy,
struct net_device *new_ifc; struct net_device *new_ifc;
if (type == NL80211_IFTYPE_MONITOR) { if (type == NL80211_IFTYPE_MONITOR) {
new_ifc = wilc_wfi_init_mon_interface(name, vif->ndev); new_ifc = wilc_wfi_init_mon_interface(vif->wilc, name,
vif->ndev);
if (new_ifc) { if (new_ifc) {
vif = netdev_priv(priv->wdev->netdev); vif = netdev_priv(priv->wdev->netdev);
vif->monitor_flag = 1; vif->monitor_flag = 1;
......
...@@ -13,9 +13,10 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net, ...@@ -13,9 +13,10 @@ struct wireless_dev *wilc_create_wiphy(struct net_device *net,
void wilc_free_wiphy(struct net_device *net); void wilc_free_wiphy(struct net_device *net);
void wilc_deinit_host_int(struct net_device *net); void wilc_deinit_host_int(struct net_device *net);
int wilc_init_host_int(struct net_device *net); int wilc_init_host_int(struct net_device *net);
void wilc_wfi_monitor_rx(u8 *buff, u32 size); void wilc_wfi_monitor_rx(struct net_device *mon_dev, u8 *buff, u32 size);
void wilc_wfi_deinit_mon_interface(void); void wilc_wfi_deinit_mon_interface(struct wilc *wl);
struct net_device *wilc_wfi_init_mon_interface(const char *name, struct net_device *wilc_wfi_init_mon_interface(struct wilc *wl,
const char *name,
struct net_device *real_dev); struct net_device *real_dev);
void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev, void wilc_mgmt_frame_register(struct wiphy *wiphy, struct wireless_dev *wdev,
u16 frame_type, bool reg); u16 frame_type, bool reg);
......
...@@ -270,6 +270,7 @@ struct wilc { ...@@ -270,6 +270,7 @@ struct wilc {
enum chip_ps_states chip_ps_state; enum chip_ps_states chip_ps_state;
struct wilc_cfg cfg; struct wilc_cfg cfg;
void *bus_data; void *bus_data;
struct net_device *monitor_dev;
}; };
struct wilc_wfi_mon_priv { struct wilc_wfi_mon_priv {
......
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