]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
net: ti: icssg_prueth: Fix NULL pointer dereference in prueth_probe()
authorRomain Gantois <romain.gantois@bootlin.com>
Tue, 21 May 2024 12:44:11 +0000 (14:44 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 23 May 2024 10:11:09 +0000 (12:11 +0200)
In the prueth_probe() function, if one of the calls to emac_phy_connect()
fails due to of_phy_connect() returning NULL, then the subsequent call to
phy_attached_info() will dereference a NULL pointer.

Check the return code of emac_phy_connect and fail cleanly if there is an
error.

Fixes: 128d5874c082 ("net: ti: icssg-prueth: Add ICSSG ethernet driver")
Cc: stable@vger.kernel.org
Signed-off-by: Romain Gantois <romain.gantois@bootlin.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Reviewed-by: MD Danish Anwar <danishanwar@ti.com>
Link: https://lore.kernel.org/r/20240521-icssg-prueth-fix-v1-1-b4b17b1433e9@bootlin.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
drivers/net/ethernet/ti/icssg/icssg_prueth.c

index 7c9e9518f555a0481ea02baf22c16bb82979a442..1ea3fbd5e954ebb0d216381fb762c989b07f457b 100644 (file)
@@ -1039,7 +1039,12 @@ static int prueth_probe(struct platform_device *pdev)
 
                prueth->registered_netdevs[PRUETH_MAC0] = prueth->emac[PRUETH_MAC0]->ndev;
 
-               emac_phy_connect(prueth->emac[PRUETH_MAC0]);
+               ret = emac_phy_connect(prueth->emac[PRUETH_MAC0]);
+               if (ret) {
+                       dev_err(dev,
+                               "can't connect to MII0 PHY, error -%d", ret);
+                       goto netdev_unregister;
+               }
                phy_attached_info(prueth->emac[PRUETH_MAC0]->ndev->phydev);
        }
 
@@ -1051,7 +1056,12 @@ static int prueth_probe(struct platform_device *pdev)
                }
 
                prueth->registered_netdevs[PRUETH_MAC1] = prueth->emac[PRUETH_MAC1]->ndev;
-               emac_phy_connect(prueth->emac[PRUETH_MAC1]);
+               ret = emac_phy_connect(prueth->emac[PRUETH_MAC1]);
+               if (ret) {
+                       dev_err(dev,
+                               "can't connect to MII1 PHY, error %d", ret);
+                       goto netdev_unregister;
+               }
                phy_attached_info(prueth->emac[PRUETH_MAC1]->ndev->phydev);
        }