]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: thunder_bgx: decrement cleanup index before use
authorRosen Penev <rosenp@gmail.com>
Mon, 1 Sep 2025 21:33:14 +0000 (14:33 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 9 Sep 2025 16:58:13 +0000 (18:58 +0200)
[ Upstream commit 9e3d71a92e561ccc77025689dab25d201fee7a3e ]

All paths in probe that call goto defer do so before assigning phydev
and thus it makes sense to cleanup the prior index. It also fixes a bug
where index 0 does not get cleaned up.

Fixes: b7d3e3d3d21a ("net: thunderx: Don't leak phy device references on -EPROBE_DEFER condition.")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250901213314.48599-1-rosenp@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/ethernet/cavium/thunder/thunder_bgx.c

index 5afc0735b582733ba9b42ae87794687da8277c39..a360d3dffccd4a8aec077c6043da7e1a542a93b3 100644 (file)
@@ -1519,11 +1519,11 @@ defer:
         * for phy devices we may have already found.
         */
        while (lmac) {
+               lmac--;
                if (bgx->lmac[lmac].phydev) {
                        put_device(&bgx->lmac[lmac].phydev->mdio.dev);
                        bgx->lmac[lmac].phydev = NULL;
                }
-               lmac--;
        }
        of_node_put(node);
        return -EPROBE_DEFER;