net: ravb: Fix error handling in ravb_probe

In ravb_probe(), we were missing a couple of things in the error
handling path:

  * We must unregister the MDIO bus before freeing the corresponding
    struct mii_dev instance to avoid the potential for use-after-free
    bugs.

  * We must free the resources acquired by clk_get_bulk() even if the
    clocks have not yet been enabled.

Fixes: 8ae51b6f32 ("net: ravb: Add Renesas Ethernet RAVB driver")
Signed-off-by: Paul Barker <paul.barker.ct@bp.renesas.com>
Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
This commit is contained in:
Paul Barker
2025-03-04 20:07:09 +00:00
committed by Marek Vasut
parent e2c0605886
commit 667ab63f93

View File

@@ -592,7 +592,7 @@ static int ravb_probe(struct udevice *dev)
ret = clk_get_bulk(dev, &eth->clks);
if (ret < 0)
goto err_mdio_alloc;
goto err_clk_get;
mdiodev = mdio_alloc();
if (!mdiodev) {
@@ -614,23 +614,25 @@ static int ravb_probe(struct udevice *dev)
/* Bring up PHY */
ret = clk_enable_bulk(&eth->clks);
if (ret)
goto err_mdio_register;
goto err_clk_enable;
ret = ravb_reset(dev);
if (ret)
goto err_mdio_reset;
goto err_clk_enable;
ret = ravb_phy_config(dev);
if (ret)
goto err_mdio_reset;
goto err_clk_enable;
return 0;
err_mdio_reset:
clk_release_bulk(&eth->clks);
err_clk_enable:
mdio_unregister(mdiodev);
err_mdio_register:
mdio_free(mdiodev);
err_mdio_alloc:
clk_release_bulk(&eth->clks);
err_clk_get:
unmap_physmem(eth->iobase, MAP_NOCACHE);
return ret;
}