Commit 77df35ac authored by Krzysztof Kozlowski's avatar Krzysztof Kozlowski Committed by Vinod Koul

phy: mediatek: xsphy: 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: default avatarKrzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Link: https://lore.kernel.org/r/20240826-phy-of-node-scope-v1-6-5b4d82582644@linaro.orgSigned-off-by: default avatarVinod Koul <vkoul@kernel.org>
parent d2714416
...@@ -432,12 +432,11 @@ static int mtk_xsphy_probe(struct platform_device *pdev) ...@@ -432,12 +432,11 @@ static int mtk_xsphy_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
struct device_node *child_np;
struct phy_provider *provider; struct phy_provider *provider;
struct resource *glb_res; struct resource *glb_res;
struct mtk_xsphy *xsphy; struct mtk_xsphy *xsphy;
struct resource res; struct resource res;
int port, retval; int port;
xsphy = devm_kzalloc(dev, sizeof(*xsphy), GFP_KERNEL); xsphy = devm_kzalloc(dev, sizeof(*xsphy), GFP_KERNEL);
if (!xsphy) if (!xsphy)
...@@ -471,37 +470,34 @@ static int mtk_xsphy_probe(struct platform_device *pdev) ...@@ -471,37 +470,34 @@ static int mtk_xsphy_probe(struct platform_device *pdev)
device_property_read_u32(dev, "mediatek,src-coef", &xsphy->src_coef); device_property_read_u32(dev, "mediatek,src-coef", &xsphy->src_coef);
port = 0; port = 0;
for_each_child_of_node(np, child_np) { for_each_child_of_node_scoped(np, child_np) {
struct xsphy_instance *inst; struct xsphy_instance *inst;
struct phy *phy; struct phy *phy;
int retval;
inst = devm_kzalloc(dev, sizeof(*inst), GFP_KERNEL); inst = devm_kzalloc(dev, sizeof(*inst), GFP_KERNEL);
if (!inst) { if (!inst)
retval = -ENOMEM; return -ENOMEM;
goto put_child;
}
xsphy->phys[port] = inst; xsphy->phys[port] = inst;
phy = devm_phy_create(dev, child_np, &mtk_xsphy_ops); phy = devm_phy_create(dev, child_np, &mtk_xsphy_ops);
if (IS_ERR(phy)) { if (IS_ERR(phy)) {
dev_err(dev, "failed to create phy\n"); dev_err(dev, "failed to create phy\n");
retval = PTR_ERR(phy); return PTR_ERR(phy);
goto put_child;
} }
retval = of_address_to_resource(child_np, 0, &res); retval = of_address_to_resource(child_np, 0, &res);
if (retval) { if (retval) {
dev_err(dev, "failed to get address resource(id-%d)\n", dev_err(dev, "failed to get address resource(id-%d)\n",
port); port);
goto put_child; return retval;
} }
inst->port_base = devm_ioremap_resource(&phy->dev, &res); inst->port_base = devm_ioremap_resource(&phy->dev, &res);
if (IS_ERR(inst->port_base)) { if (IS_ERR(inst->port_base)) {
dev_err(dev, "failed to remap phy regs\n"); dev_err(dev, "failed to remap phy regs\n");
retval = PTR_ERR(inst->port_base); return PTR_ERR(inst->port_base);
goto put_child;
} }
inst->phy = phy; inst->phy = phy;
...@@ -512,17 +508,12 @@ static int mtk_xsphy_probe(struct platform_device *pdev) ...@@ -512,17 +508,12 @@ static int mtk_xsphy_probe(struct platform_device *pdev)
inst->ref_clk = devm_clk_get(&phy->dev, "ref"); inst->ref_clk = devm_clk_get(&phy->dev, "ref");
if (IS_ERR(inst->ref_clk)) { if (IS_ERR(inst->ref_clk)) {
dev_err(dev, "failed to get ref_clk(id-%d)\n", port); dev_err(dev, "failed to get ref_clk(id-%d)\n", port);
retval = PTR_ERR(inst->ref_clk); return PTR_ERR(inst->ref_clk);
goto put_child;
} }
} }
provider = devm_of_phy_provider_register(dev, mtk_phy_xlate); provider = devm_of_phy_provider_register(dev, mtk_phy_xlate);
return PTR_ERR_OR_ZERO(provider); return PTR_ERR_OR_ZERO(provider);
put_child:
of_node_put(child_np);
return retval;
} }
static struct platform_driver mtk_xsphy_driver = { static struct platform_driver mtk_xsphy_driver = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment