Skip to content

Commit 903d2b9

Browse files
mwallekuba-moo
authored andcommitted
net: ethernet: ti: am65-cpsw: fix port_np reference counting
A reference to the device tree node is stored in a private struct, thus the reference count has to be incremented. Also, decrement the count on device removal and in the error path. Fixes: 93a7653 ("net: ethernet: ti: introduce am65x/j721e gigabit eth subsystem driver") Signed-off-by: Michael Walle <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 688abe1 commit 903d2b9

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2666,7 +2666,7 @@ static int am65_cpsw_nuss_init_slave_ports(struct am65_cpsw_common *common)
26662666
of_property_read_bool(port_np, "ti,mac-only");
26672667

26682668
/* get phy/link info */
2669-
port->slave.port_np = port_np;
2669+
port->slave.port_np = of_node_get(port_np);
26702670
ret = of_get_phy_mode(port_np, &port->slave.phy_if);
26712671
if (ret) {
26722672
dev_err(dev, "%pOF read phy-mode err %d\n",
@@ -2720,6 +2720,17 @@ static void am65_cpsw_nuss_phylink_cleanup(struct am65_cpsw_common *common)
27202720
}
27212721
}
27222722

2723+
static void am65_cpsw_remove_dt(struct am65_cpsw_common *common)
2724+
{
2725+
struct am65_cpsw_port *port;
2726+
int i;
2727+
2728+
for (i = 0; i < common->port_num; i++) {
2729+
port = &common->ports[i];
2730+
of_node_put(port->slave.port_np);
2731+
}
2732+
}
2733+
27232734
static int
27242735
am65_cpsw_nuss_init_port_ndev(struct am65_cpsw_common *common, u32 port_idx)
27252736
{
@@ -3622,6 +3633,7 @@ static int am65_cpsw_nuss_probe(struct platform_device *pdev)
36223633
am65_cpsw_nuss_cleanup_ndev(common);
36233634
am65_cpsw_nuss_phylink_cleanup(common);
36243635
am65_cpts_release(common->cpts);
3636+
am65_cpsw_remove_dt(common);
36253637
err_of_clear:
36263638
if (common->mdio_dev)
36273639
of_platform_device_destroy(common->mdio_dev, NULL);
@@ -3661,6 +3673,7 @@ static void am65_cpsw_nuss_remove(struct platform_device *pdev)
36613673
am65_cpsw_nuss_phylink_cleanup(common);
36623674
am65_cpts_release(common->cpts);
36633675
am65_cpsw_disable_serdes_phy(common);
3676+
am65_cpsw_remove_dt(common);
36643677

36653678
if (common->mdio_dev)
36663679
of_platform_device_destroy(common->mdio_dev, NULL);

0 commit comments

Comments
 (0)