[PATCH net] net: bgmac: Fix potential MDIO use-after-free during removal

From: Guangshuo Li

Date: Wed Nov 18 2026 - 09:18:48 EST


The BCMA remove callback destroys its MDIO bus before
bgmac_enet_remove() disconnects the attached PHY. The PHY detach path
still accesses that bus.

Remove the netdev and disconnect the PHY before unregistering the MDIO
bus.

This issue was found by our static analysis tool under development.

Fixes: f6a95a24957a ("net: ethernet: bgmac: Add platform device support")
Signed-off-by: Guangshuo Li <liguangshuo@xxxxxxxxxxxxxxx>
---
drivers/net/ethernet/broadcom/bgmac-bcma.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/broadcom/bgmac-bcma.c b/drivers/net/ethernet/broadcom/bgmac-bcma.c
index 36f9bad28e6a..e9229d86c7d0 100644
--- a/drivers/net/ethernet/broadcom/bgmac-bcma.c
+++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c
@@ -329,8 +329,8 @@ static void bgmac_remove(struct bcma_device *core)
{
struct bgmac *bgmac = bcma_get_drvdata(core);

- bcma_mdio_mii_unregister(bgmac->mii_bus);
bgmac_enet_remove(bgmac);
+ bcma_mdio_mii_unregister(bgmac->mii_bus);
bcma_set_drvdata(core, NULL);
}


base-commit: 2e54b3e187300893688c2c7517894f5d96732e05