Skip to content

Commit 2b6ffcd

Browse files
joehattorikuba-moo
authored andcommitted
net: stmmac: restructure the error path of stmmac_probe_config_dt()
Current implementation of stmmac_probe_config_dt() does not release the OF node reference obtained by of_parse_phandle() in some error paths. The problem is that some error paths call stmmac_remove_config_dt() to clean up but others use and unwind ladder. These two types of error handling have not kept in sync and have been a recurring source of bugs. Re-write the error handling in stmmac_probe_config_dt() to use an unwind ladder. Consequently, stmmac_remove_config_dt() is not needed anymore, thus remove it. This bug was found by an experimental verification tool that I am developing. Fixes: 4838a54 ("net: stmmac: Fix wrapper drivers not detecting PHY") Signed-off-by: Joe Hattori <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent a072ffd commit 2b6ffcd

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -405,22 +405,6 @@ static int stmmac_of_get_mac_mode(struct device_node *np)
405405
return -ENODEV;
406406
}
407407

408-
/**
409-
* stmmac_remove_config_dt - undo the effects of stmmac_probe_config_dt()
410-
* @pdev: platform_device structure
411-
* @plat: driver data platform structure
412-
*
413-
* Release resources claimed by stmmac_probe_config_dt().
414-
*/
415-
static void stmmac_remove_config_dt(struct platform_device *pdev,
416-
struct plat_stmmacenet_data *plat)
417-
{
418-
clk_disable_unprepare(plat->stmmac_clk);
419-
clk_disable_unprepare(plat->pclk);
420-
of_node_put(plat->phy_node);
421-
of_node_put(plat->mdio_node);
422-
}
423-
424408
/**
425409
* stmmac_probe_config_dt - parse device-tree driver parameters
426410
* @pdev: platform_device structure
@@ -490,8 +474,10 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
490474
dev_warn(&pdev->dev, "snps,phy-addr property is deprecated\n");
491475

492476
rc = stmmac_mdio_setup(plat, np, &pdev->dev);
493-
if (rc)
494-
return ERR_PTR(rc);
477+
if (rc) {
478+
ret = ERR_PTR(rc);
479+
goto error_put_phy;
480+
}
495481

496482
of_property_read_u32(np, "tx-fifo-depth", &plat->tx_fifo_size);
497483

@@ -581,8 +567,8 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
581567
dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*dma_cfg),
582568
GFP_KERNEL);
583569
if (!dma_cfg) {
584-
stmmac_remove_config_dt(pdev, plat);
585-
return ERR_PTR(-ENOMEM);
570+
ret = ERR_PTR(-ENOMEM);
571+
goto error_put_mdio;
586572
}
587573
plat->dma_cfg = dma_cfg;
588574

@@ -610,8 +596,8 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
610596

611597
rc = stmmac_mtl_setup(pdev, plat);
612598
if (rc) {
613-
stmmac_remove_config_dt(pdev, plat);
614-
return ERR_PTR(rc);
599+
ret = ERR_PTR(rc);
600+
goto error_put_mdio;
615601
}
616602

617603
/* clock setup */
@@ -663,6 +649,10 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
663649
clk_disable_unprepare(plat->pclk);
664650
error_pclk_get:
665651
clk_disable_unprepare(plat->stmmac_clk);
652+
error_put_mdio:
653+
of_node_put(plat->mdio_node);
654+
error_put_phy:
655+
of_node_put(plat->phy_node);
666656

667657
return ret;
668658
}
@@ -671,16 +661,17 @@ static void devm_stmmac_remove_config_dt(void *data)
671661
{
672662
struct plat_stmmacenet_data *plat = data;
673663

674-
/* Platform data argument is unused */
675-
stmmac_remove_config_dt(NULL, plat);
664+
clk_disable_unprepare(plat->stmmac_clk);
665+
clk_disable_unprepare(plat->pclk);
666+
of_node_put(plat->mdio_node);
667+
of_node_put(plat->phy_node);
676668
}
677669

678670
/**
679671
* devm_stmmac_probe_config_dt
680672
* @pdev: platform_device structure
681673
* @mac: MAC address to use
682-
* Description: Devres variant of stmmac_probe_config_dt(). Does not require
683-
* the user to call stmmac_remove_config_dt() at driver detach.
674+
* Description: Devres variant of stmmac_probe_config_dt().
684675
*/
685676
struct plat_stmmacenet_data *
686677
devm_stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)

0 commit comments

Comments
 (0)