Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 93a76530316a ("net: ethernet: ti: introduce am65x/j721e gigabit eth subsystem driver")
Signed-off-by: Michael Walle <mwalle@kernel.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250414083942.4015060-1-mwalle@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Michael Walle and committed by
Jakub Kicinski
903d2b9f 688abe10

+14 -1
+14 -1
drivers/net/ethernet/ti/am65-cpsw-nuss.c
··· 2666 2666 of_property_read_bool(port_np, "ti,mac-only"); 2667 2667 2668 2668 /* get phy/link info */ 2669 - port->slave.port_np = port_np; 2669 + port->slave.port_np = of_node_get(port_np); 2670 2670 ret = of_get_phy_mode(port_np, &port->slave.phy_if); 2671 2671 if (ret) { 2672 2672 dev_err(dev, "%pOF read phy-mode err %d\n", ··· 2717 2717 port = &common->ports[i]; 2718 2718 if (port->slave.phylink) 2719 2719 phylink_destroy(port->slave.phylink); 2720 + } 2721 + } 2722 + 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); 2720 2731 } 2721 2732 } 2722 2733 ··· 3633 3622 am65_cpsw_nuss_cleanup_ndev(common); 3634 3623 am65_cpsw_nuss_phylink_cleanup(common); 3635 3624 am65_cpts_release(common->cpts); 3625 + am65_cpsw_remove_dt(common); 3636 3626 err_of_clear: 3637 3627 if (common->mdio_dev) 3638 3628 of_platform_device_destroy(common->mdio_dev, NULL); ··· 3673 3661 am65_cpsw_nuss_phylink_cleanup(common); 3674 3662 am65_cpts_release(common->cpts); 3675 3663 am65_cpsw_disable_serdes_phy(common); 3664 + am65_cpsw_remove_dt(common); 3676 3665 3677 3666 if (common->mdio_dev) 3678 3667 of_platform_device_destroy(common->mdio_dev, NULL);