Skip to content

Commit

Permalink
brcmfmac: use struct net_device::destructor to remove interfaces
Browse files Browse the repository at this point in the history
Upon deleting a P2P_CLIENT/GO interface the vif and consequently
the wdev is freed before the net_device is actually being unregistered
but cfg80211 still needs to access the wdev. Using destructor field
to free the net_device and vif.

Reviewed-by: Hante Meuleman <[email protected]>
Signed-off-by: Arend van Spriel <[email protected]>
Signed-off-by: John W. Linville <[email protected]>
  • Loading branch information
Arend van Spriel authored and linvjw committed May 28, 2013
1 parent 9390ace commit cbb371d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
6 changes: 3 additions & 3 deletions drivers/net/wireless/brcm80211/brcmfmac/dhd_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ int brcmf_net_attach(struct brcmf_if *ifp, bool rtnl_locked)

brcmf_dbg(INFO, "%s: Broadcom Dongle Host Driver\n", ndev->name);

ndev->destructor = free_netdev;
return 0;

fail:
Expand Down Expand Up @@ -793,6 +794,7 @@ void brcmf_del_if(struct brcmf_pub *drvr, s32 bssidx)
struct brcmf_if *ifp;

ifp = drvr->iflist[bssidx];
drvr->iflist[bssidx] = NULL;
if (!ifp) {
brcmf_err("Null interface, idx=%d\n", bssidx);
return;
Expand All @@ -813,15 +815,13 @@ void brcmf_del_if(struct brcmf_pub *drvr, s32 bssidx)
cancel_work_sync(&ifp->setmacaddr_work);
cancel_work_sync(&ifp->multicast_work);
}

/* unregister will take care of freeing it */
unregister_netdev(ifp->ndev);
if (bssidx == 0)
brcmf_cfg80211_detach(drvr->config);
free_netdev(ifp->ndev);
} else {
kfree(ifp);
}
drvr->iflist[bssidx] = NULL;
}

int brcmf_attach(uint bus_hdrlen, struct device *dev)
Expand Down
23 changes: 22 additions & 1 deletion drivers/net/wireless/brcm80211/brcmfmac/p2p.c
Original file line number Diff line number Diff line change
Expand Up @@ -2239,6 +2239,25 @@ static void brcmf_p2p_delete_p2pdev(struct brcmf_cfg80211_info *cfg,
brcmf_free_vif(cfg, vif);
}

/**
* brcmf_p2p_free_p2p_if() - free up net device related data.
*
* @ndev: net device that needs to be freed.
*/
static void brcmf_p2p_free_p2p_if(struct net_device *ndev)
{
struct brcmf_cfg80211_info *cfg;
struct brcmf_cfg80211_vif *vif;
struct brcmf_if *ifp;

ifp = netdev_priv(ndev);
cfg = ifp->drvr->config;
vif = ifp->vif;

brcmf_free_vif(cfg, vif);
free_netdev(ifp->ndev);
}

/**
* brcmf_p2p_add_vif() - create a new P2P virtual interface.
*
Expand Down Expand Up @@ -2316,6 +2335,9 @@ struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name,
brcmf_err("Registering netdevice failed\n");
goto fail;
}
/* override destructor */
ifp->ndev->destructor = brcmf_p2p_free_p2p_if;

cfg->p2p.bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = vif;
/* Disable firmware roaming for P2P interface */
brcmf_fil_iovar_int_set(ifp, "roam_off", 1);
Expand Down Expand Up @@ -2391,7 +2413,6 @@ int brcmf_p2p_del_vif(struct wiphy *wiphy, struct wireless_dev *wdev)
err = 0;
}
brcmf_cfg80211_arm_vif_event(cfg, NULL);
brcmf_free_vif(cfg, vif);
p2p->bss_idx[P2PAPI_BSSCFG_CONNECTION].vif = NULL;

return err;
Expand Down
1 change: 0 additions & 1 deletion drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -4678,7 +4678,6 @@ static s32 brcmf_notify_vif_event(struct brcmf_if *ifp,
return 0;

case BRCMF_E_IF_DEL:
ifp->vif = NULL;
mutex_unlock(&event->vif_event_lock);
/* event may not be upon user request */
if (brcmf_cfg80211_vif_event_armed(cfg))
Expand Down

0 comments on commit cbb371d

Please sign in to comment.