@@ -826,26 +826,18 @@ static const struct phylink_mac_ops mtk_phylink_ops = {
static int mtk_mdio_init(struct mtk_eth *eth)
{
unsigned int max_clk = 2500000, divider;
- struct device_node *mii_np;
- int ret;
+ struct device_node *mii_np _free(device_node) =
+ of_get_available_child_by_name(eth->dev->of_node, "mdio-bus");
u32 val;
- mii_np = of_get_child_by_name(eth->dev->of_node, "mdio-bus");
if (!mii_np) {
dev_err(eth->dev, "no %s child node found", "mdio-bus");
return -ENODEV;
}
- if (!of_device_is_available(mii_np)) {
- ret = -ENODEV;
- goto err_put_node;
- }
-
eth->mii_bus = devm_mdiobus_alloc(eth->dev);
- if (!eth->mii_bus) {
- ret = -ENOMEM;
- goto err_put_node;
- }
+ if (!eth->mii_bus)
+ return -ENOMEM;
eth->mii_bus->name = "mdio";
eth->mii_bus->read = mtk_mdio_read_c22;
@@ -860,8 +852,7 @@ static int mtk_mdio_init(struct mtk_eth *eth)
if (!of_property_read_u32(mii_np, "clock-frequency", &val)) {
if (val > MDC_MAX_FREQ || val < MDC_MAX_FREQ / MDC_MAX_DIVIDER) {
dev_err(eth->dev, "MDIO clock frequency out of range");
- ret = -EINVAL;
- goto err_put_node;
+ return -EINVAL;
}
max_clk = val;
}
@@ -879,11 +870,7 @@ static int mtk_mdio_init(struct mtk_eth *eth)
dev_dbg(eth->dev, "MDC is running on %d Hz\n", MDC_MAX_FREQ / divider);
- ret = of_mdiobus_register(eth->mii_bus, mii_np);
-
-err_put_node:
- of_node_put(mii_np);
- return ret;
+ return of_mdiobus_register(eth->mii_bus, mii_np);
}
static void mtk_mdio_cleanup(struct mtk_eth *eth)
Use the helper of_get_available_child_by_name() to simplify mtk_mdio_init(). Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com> --- This patch is only compile tested and depend upon[1] [1] https://lore.kernel.org/all/20250201093126.7322-1-biju.das.jz@bp.renesas.com/ --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 25 +++++---------------- 1 file changed, 6 insertions(+), 19 deletions(-)