]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: ethernet: sunplus: spl2sw: fix phy_node refcount leak in remove
authorShitalkumar Gandhi <shital.gandhi45@gmail.com>
Tue, 23 Jun 2026 06:41:42 +0000 (12:11 +0530)
committerJakub Kicinski <kuba@kernel.org>
Thu, 25 Jun 2026 02:34:56 +0000 (19:34 -0700)
mac->phy_node is acquired via of_parse_phandle() in spl2sw_probe() and
stored in the mac private data, transferring ownership of the
device_node reference to mac. On driver removal, spl2sw_phy_remove()
disconnects the PHY but never drops that reference, so each
probe-then-remove cycle leaks one of_node refcount per port permanently.

Drop the reference after phy_disconnect(). While at it, remove the
redundant inner "if (ndev)" check; comm->ndev[i] was just verified
non-NULL on the line above.

Compile-tested only; no SP7021 hardware available.

Fixes: fd3040b9394c ("net: ethernet: Add driver for Sunplus SP7021")
Signed-off-by: Shitalkumar Gandhi <shitalkumar.gandhi@cambiumnetworks.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/f3bdd4c91f3e2269b4e256075f9dc70808b1b8e9.1782195965.git.shitalkumar.gandhi@cambiumnetworks.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/sunplus/spl2sw_phy.c

index 6f899e48f51dfbea01d7238af3c5c890c73a0590..a4889c52e00e4c7d30e7284de8446384cefdc5c3 100644 (file)
@@ -79,12 +79,14 @@ int spl2sw_phy_connect(struct spl2sw_common *comm)
 void spl2sw_phy_remove(struct spl2sw_common *comm)
 {
        struct net_device *ndev;
+       struct spl2sw_mac *mac;
        int i;
 
        for (i = 0; i < MAX_NETDEV_NUM; i++)
                if (comm->ndev[i]) {
                        ndev = comm->ndev[i];
-                       if (ndev)
-                               phy_disconnect(ndev->phydev);
+                       mac = netdev_priv(ndev);
+                       phy_disconnect(ndev->phydev);
+                       of_node_put(mac->phy_node);
                }
 }