Skip to content

Commit 1f1b194

Browse files
Marc ZyngierPaolo Abeni
authored andcommitted
net: thunder_bgx: Fix netdev structure allocation
Commit 94833ad ("net: thunderx: Unembed netdev structure") had a go at dynamically allocating the netdev structures for the thunderx_bgx driver. This change results in my ThunderX box catching fire (to be fair, it is what it does best). The issues with this change are that: - bgx_lmac_enable() is called *after* bgx_acpi_register_phy() and bgx_init_of_phy(), both expecting netdev to be a valid pointer. - bgx_init_of_phy() populates the MAC addresses for *all* LMACs attached to a given BGX instance, and thus needs netdev for each of them to have been allocated. There is a few things to be said about how the driver mixes LMAC and BGX states which leads to this sorry state, but that's beside the point. To address this, go back to a situation where all netdev structures are allocated before the driver starts relying on them, and move the freeing of these structures to driver removal. Someone brave enough can always go and restructure the driver if they want. Fixes: 94833ad ("net: thunderx: Unembed netdev structure") Signed-off-by: Marc Zyngier <[email protected]> Cc: Breno Leitao <[email protected]> Cc: Sunil Goutham <[email protected]> Cc: "David S. Miller" <[email protected]> Cc: Eric Dumazet <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: Paolo Abeni <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Breno Leitao <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent fde25c2 commit 1f1b194

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

drivers/net/ethernet/cavium/thunder/thunder_bgx.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,18 +1054,12 @@ static int phy_interface_mode(u8 lmac_type)
10541054

10551055
static int bgx_lmac_enable(struct bgx *bgx, u8 lmacid)
10561056
{
1057-
struct lmac *lmac, **priv;
1057+
struct lmac *lmac;
10581058
u64 cfg;
10591059

10601060
lmac = &bgx->lmac[lmacid];
10611061
lmac->bgx = bgx;
10621062

1063-
lmac->netdev = alloc_netdev_dummy(sizeof(struct lmac *));
1064-
if (!lmac->netdev)
1065-
return -ENOMEM;
1066-
priv = netdev_priv(lmac->netdev);
1067-
*priv = lmac;
1068-
10691063
if ((lmac->lmac_type == BGX_MODE_SGMII) ||
10701064
(lmac->lmac_type == BGX_MODE_QSGMII) ||
10711065
(lmac->lmac_type == BGX_MODE_RGMII)) {
@@ -1191,7 +1185,6 @@ static void bgx_lmac_disable(struct bgx *bgx, u8 lmacid)
11911185
(lmac->lmac_type != BGX_MODE_10G_KR) && lmac->phydev)
11921186
phy_disconnect(lmac->phydev);
11931187

1194-
free_netdev(lmac->netdev);
11951188
lmac->phydev = NULL;
11961189
}
11971190

@@ -1653,6 +1646,23 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
16531646

16541647
bgx_get_qlm_mode(bgx);
16551648

1649+
for (lmac = 0; lmac < bgx->lmac_count; lmac++) {
1650+
struct lmac *lmacp, **priv;
1651+
1652+
lmacp = &bgx->lmac[lmac];
1653+
lmacp->netdev = alloc_netdev_dummy(sizeof(struct lmac *));
1654+
1655+
if (!lmacp->netdev) {
1656+
for (int i = 0; i < lmac; i++)
1657+
free_netdev(bgx->lmac[i].netdev);
1658+
err = -ENOMEM;
1659+
goto err_enable;
1660+
}
1661+
1662+
priv = netdev_priv(lmacp->netdev);
1663+
*priv = lmacp;
1664+
}
1665+
16561666
err = bgx_init_phy(bgx);
16571667
if (err)
16581668
goto err_enable;
@@ -1692,8 +1702,10 @@ static void bgx_remove(struct pci_dev *pdev)
16921702
u8 lmac;
16931703

16941704
/* Disable all LMACs */
1695-
for (lmac = 0; lmac < bgx->lmac_count; lmac++)
1705+
for (lmac = 0; lmac < bgx->lmac_count; lmac++) {
16961706
bgx_lmac_disable(bgx, lmac);
1707+
free_netdev(bgx->lmac[lmac].netdev);
1708+
}
16971709

16981710
pci_free_irq(pdev, GMPX_GMI_TX_INT, bgx);
16991711

0 commit comments

Comments
 (0)