Skip to content

Commit 94833ad

Browse files
leitaokuba-moo
authored andcommitted
net: thunderx: Unembed netdev structure
Embedding net_device into structures prohibits the usage of flexible arrays in the net_device structure. For more details, see the discussion at [1]. Un-embed the net_devices from struct lmac by converting them into pointers, and allocating them dynamically. Use the leverage alloc_netdev() to allocate the net_device object at bgx_lmac_enable(). The free of the device occurs at bgx_lmac_disable(). Do not free_netdevice() if bgx_lmac_enable() fails after lmac->netdev is allocated, since bgx_lmac_disable() is called if bgx_lmac_enable() fails, and lmac->netdev will be freed there (similarly to lmac->dmacs). Link: https://lore.kernel.org/all/[email protected]/ [1] Signed-off-by: Breno Leitao <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 2d5f680 commit 94833ad

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct lmac {
5454
bool link_up;
5555
int lmacid; /* ID within BGX */
5656
int lmacid_bd; /* ID on board */
57-
struct net_device netdev;
57+
struct net_device *netdev;
5858
struct phy_device *phydev;
5959
unsigned int last_duplex;
6060
unsigned int last_link;
@@ -590,10 +590,12 @@ static void bgx_sgmii_change_link_state(struct lmac *lmac)
590590

591591
static void bgx_lmac_handler(struct net_device *netdev)
592592
{
593-
struct lmac *lmac = container_of(netdev, struct lmac, netdev);
594593
struct phy_device *phydev;
594+
struct lmac *lmac, **priv;
595595
int link_changed = 0;
596596

597+
priv = netdev_priv(netdev);
598+
lmac = *priv;
597599
phydev = lmac->phydev;
598600

599601
if (!phydev->link && lmac->last_link)
@@ -1052,12 +1054,18 @@ static int phy_interface_mode(u8 lmac_type)
10521054

10531055
static int bgx_lmac_enable(struct bgx *bgx, u8 lmacid)
10541056
{
1055-
struct lmac *lmac;
1057+
struct lmac *lmac, **priv;
10561058
u64 cfg;
10571059

10581060
lmac = &bgx->lmac[lmacid];
10591061
lmac->bgx = bgx;
10601062

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+
10611069
if ((lmac->lmac_type == BGX_MODE_SGMII) ||
10621070
(lmac->lmac_type == BGX_MODE_QSGMII) ||
10631071
(lmac->lmac_type == BGX_MODE_RGMII)) {
@@ -1116,7 +1124,7 @@ static int bgx_lmac_enable(struct bgx *bgx, u8 lmacid)
11161124
}
11171125
lmac->phydev->dev_flags = 0;
11181126

1119-
if (phy_connect_direct(&lmac->netdev, lmac->phydev,
1127+
if (phy_connect_direct(lmac->netdev, lmac->phydev,
11201128
bgx_lmac_handler,
11211129
phy_interface_mode(lmac->lmac_type)))
11221130
return -ENODEV;
@@ -1183,6 +1191,7 @@ static void bgx_lmac_disable(struct bgx *bgx, u8 lmacid)
11831191
(lmac->lmac_type != BGX_MODE_10G_KR) && lmac->phydev)
11841192
phy_disconnect(lmac->phydev);
11851193

1194+
free_netdev(lmac->netdev);
11861195
lmac->phydev = NULL;
11871196
}
11881197

@@ -1414,7 +1423,7 @@ static acpi_status bgx_acpi_register_phy(acpi_handle handle,
14141423

14151424
acpi_get_mac_address(dev, adev, bgx->lmac[bgx->acpi_lmac_idx].mac);
14161425

1417-
SET_NETDEV_DEV(&bgx->lmac[bgx->acpi_lmac_idx].netdev, dev);
1426+
SET_NETDEV_DEV(bgx->lmac[bgx->acpi_lmac_idx].netdev, dev);
14181427

14191428
bgx->lmac[bgx->acpi_lmac_idx].lmacid = bgx->acpi_lmac_idx;
14201429
bgx->acpi_lmac_idx++; /* move to next LMAC */
@@ -1483,7 +1492,7 @@ static int bgx_init_of_phy(struct bgx *bgx)
14831492

14841493
of_get_mac_address(node, bgx->lmac[lmac].mac);
14851494

1486-
SET_NETDEV_DEV(&bgx->lmac[lmac].netdev, &bgx->pdev->dev);
1495+
SET_NETDEV_DEV(bgx->lmac[lmac].netdev, &bgx->pdev->dev);
14871496
bgx->lmac[lmac].lmacid = lmac;
14881497

14891498
phy_np = of_parse_phandle(node, "phy-handle", 0);

0 commit comments

Comments
 (0)