Skip to content

Commit 03c96bc

Browse files
Nicolas PitrePaolo Abeni
authored andcommitted
net: ethernet: ti: am65-cpsw: avoid devm_alloc_etherdev, fix module removal
Usage of devm_alloc_etherdev_mqs() conflicts with am65_cpsw_nuss_cleanup_ndev() as the same struct net_device instances get unregistered twice. Switch to alloc_etherdev_mqs() and make sure am65_cpsw_nuss_cleanup_ndev() unregisters and frees those net_device instances properly. With this, it is finally possible to rmmod the driver without oopsing the kernel. Fixes: 93a7653 ("net: ethernet: ti: introduce am65x/j721e gigabit eth subsystem driver") Signed-off-by: Nicolas Pitre <[email protected]> Reviewed-by: Roger Quadros <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 47f9605 commit 03c96bc

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/net/ethernet/ti/am65-cpsw-nuss.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,10 +2744,9 @@ am65_cpsw_nuss_init_port_ndev(struct am65_cpsw_common *common, u32 port_idx)
27442744
return 0;
27452745

27462746
/* alloc netdev */
2747-
port->ndev = devm_alloc_etherdev_mqs(common->dev,
2748-
sizeof(struct am65_cpsw_ndev_priv),
2749-
AM65_CPSW_MAX_QUEUES,
2750-
AM65_CPSW_MAX_QUEUES);
2747+
port->ndev = alloc_etherdev_mqs(sizeof(struct am65_cpsw_ndev_priv),
2748+
AM65_CPSW_MAX_QUEUES,
2749+
AM65_CPSW_MAX_QUEUES);
27512750
if (!port->ndev) {
27522751
dev_err(dev, "error allocating slave net_device %u\n",
27532752
port->port_id);
@@ -2868,8 +2867,12 @@ static void am65_cpsw_nuss_cleanup_ndev(struct am65_cpsw_common *common)
28682867

28692868
for (i = 0; i < common->port_num; i++) {
28702869
port = &common->ports[i];
2871-
if (port->ndev && port->ndev->reg_state == NETREG_REGISTERED)
2870+
if (!port->ndev)
2871+
continue;
2872+
if (port->ndev->reg_state == NETREG_REGISTERED)
28722873
unregister_netdev(port->ndev);
2874+
free_netdev(port->ndev);
2875+
port->ndev = NULL;
28732876
}
28742877
}
28752878

@@ -3613,16 +3616,17 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev)
36133616

36143617
ret = am65_cpsw_nuss_init_ndevs(common);
36153618
if (ret)
3616-
goto err_free_phylink;
3619+
goto err_ndevs_clear;
36173620

36183621
ret = am65_cpsw_nuss_register_ndevs(common);
36193622
if (ret)
3620-
goto err_free_phylink;
3623+
goto err_ndevs_clear;
36213624

36223625
pm_runtime_put(dev);
36233626
return 0;
36243627

3625-
err_free_phylink:
3628+
err_ndevs_clear:
3629+
am65_cpsw_nuss_cleanup_ndev(common);
36263630
am65_cpsw_nuss_phylink_cleanup(common);
36273631
am65_cpts_release(common->cpts);
36283632
err_of_clear:

0 commit comments

Comments
 (0)