Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

phy: mediatek: tphy: Simplify with scoped for each OF child loop

Use scoped for_each_child_of_node_scoped() when iterating over device
nodes to make code a bit simpler.

Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240826-phy-of-node-scope-v1-5-5b4d82582644@linaro.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>

authored by

Krzysztof Kozlowski and committed by
Vinod Koul
d2714416 93cab07a

+11 -19
+11 -19
drivers/phy/mediatek/phy-mtk-tphy.c
··· 1577 1577 { 1578 1578 struct device *dev = &pdev->dev; 1579 1579 struct device_node *np = dev->of_node; 1580 - struct device_node *child_np; 1581 1580 struct phy_provider *provider; 1582 1581 struct resource *sif_res; 1583 1582 struct mtk_tphy *tphy; 1584 1583 struct resource res; 1585 - int port, retval; 1584 + int port; 1586 1585 1587 1586 tphy = devm_kzalloc(dev, sizeof(*tphy), GFP_KERNEL); 1588 1587 if (!tphy) ··· 1622 1623 } 1623 1624 1624 1625 port = 0; 1625 - for_each_child_of_node(np, child_np) { 1626 + for_each_child_of_node_scoped(np, child_np) { 1626 1627 struct mtk_phy_instance *instance; 1627 1628 struct clk_bulk_data *clks; 1628 1629 struct device *subdev; 1629 1630 struct phy *phy; 1631 + int retval; 1630 1632 1631 1633 instance = devm_kzalloc(dev, sizeof(*instance), GFP_KERNEL); 1632 - if (!instance) { 1633 - retval = -ENOMEM; 1634 - goto put_child; 1635 - } 1634 + if (!instance) 1635 + return -ENOMEM; 1636 1636 1637 1637 tphy->phys[port] = instance; 1638 1638 1639 1639 phy = devm_phy_create(dev, child_np, &mtk_tphy_ops); 1640 1640 if (IS_ERR(phy)) { 1641 1641 dev_err(dev, "failed to create phy\n"); 1642 - retval = PTR_ERR(phy); 1643 - goto put_child; 1642 + return PTR_ERR(phy); 1644 1643 } 1645 1644 1646 1645 subdev = &phy->dev; ··· 1646 1649 if (retval) { 1647 1650 dev_err(subdev, "failed to get address resource(id-%d)\n", 1648 1651 port); 1649 - goto put_child; 1652 + return retval; 1650 1653 } 1651 1654 1652 1655 instance->port_base = devm_ioremap_resource(subdev, &res); 1653 - if (IS_ERR(instance->port_base)) { 1654 - retval = PTR_ERR(instance->port_base); 1655 - goto put_child; 1656 - } 1656 + if (IS_ERR(instance->port_base)) 1657 + return PTR_ERR(instance->port_base); 1657 1658 1658 1659 instance->phy = phy; 1659 1660 instance->index = port; ··· 1663 1668 clks[1].id = "da_ref"; /* analog clock */ 1664 1669 retval = devm_clk_bulk_get_optional(subdev, TPHY_CLKS_CNT, clks); 1665 1670 if (retval) 1666 - goto put_child; 1671 + return retval; 1667 1672 1668 1673 retval = phy_type_syscon_get(instance, child_np); 1669 1674 if (retval) 1670 - goto put_child; 1675 + return retval; 1671 1676 } 1672 1677 1673 1678 provider = devm_of_phy_provider_register(dev, mtk_phy_xlate); 1674 1679 1675 1680 return PTR_ERR_OR_ZERO(provider); 1676 - put_child: 1677 - of_node_put(child_np); 1678 - return retval; 1679 1681 } 1680 1682 1681 1683 static struct platform_driver mtk_tphy_driver = {