Skip to content

Commit 77df35a

Browse files
krzkvinodkoul
authored andcommitted
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: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent d271441 commit 77df35a

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

drivers/phy/mediatek/phy-mtk-xsphy.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,11 @@ static int mtk_xsphy_probe(struct platform_device *pdev)
432432
{
433433
struct device *dev = &pdev->dev;
434434
struct device_node *np = dev->of_node;
435-
struct device_node *child_np;
436435
struct phy_provider *provider;
437436
struct resource *glb_res;
438437
struct mtk_xsphy *xsphy;
439438
struct resource res;
440-
int port, retval;
439+
int port;
441440

442441
xsphy = devm_kzalloc(dev, sizeof(*xsphy), GFP_KERNEL);
443442
if (!xsphy)
@@ -471,37 +470,34 @@ static int mtk_xsphy_probe(struct platform_device *pdev)
471470
device_property_read_u32(dev, "mediatek,src-coef", &xsphy->src_coef);
472471

473472
port = 0;
474-
for_each_child_of_node(np, child_np) {
473+
for_each_child_of_node_scoped(np, child_np) {
475474
struct xsphy_instance *inst;
476475
struct phy *phy;
476+
int retval;
477477

478478
inst = devm_kzalloc(dev, sizeof(*inst), GFP_KERNEL);
479-
if (!inst) {
480-
retval = -ENOMEM;
481-
goto put_child;
482-
}
479+
if (!inst)
480+
return -ENOMEM;
483481

484482
xsphy->phys[port] = inst;
485483

486484
phy = devm_phy_create(dev, child_np, &mtk_xsphy_ops);
487485
if (IS_ERR(phy)) {
488486
dev_err(dev, "failed to create phy\n");
489-
retval = PTR_ERR(phy);
490-
goto put_child;
487+
return PTR_ERR(phy);
491488
}
492489

493490
retval = of_address_to_resource(child_np, 0, &res);
494491
if (retval) {
495492
dev_err(dev, "failed to get address resource(id-%d)\n",
496493
port);
497-
goto put_child;
494+
return retval;
498495
}
499496

500497
inst->port_base = devm_ioremap_resource(&phy->dev, &res);
501498
if (IS_ERR(inst->port_base)) {
502499
dev_err(dev, "failed to remap phy regs\n");
503-
retval = PTR_ERR(inst->port_base);
504-
goto put_child;
500+
return PTR_ERR(inst->port_base);
505501
}
506502

507503
inst->phy = phy;
@@ -512,17 +508,12 @@ static int mtk_xsphy_probe(struct platform_device *pdev)
512508
inst->ref_clk = devm_clk_get(&phy->dev, "ref");
513509
if (IS_ERR(inst->ref_clk)) {
514510
dev_err(dev, "failed to get ref_clk(id-%d)\n", port);
515-
retval = PTR_ERR(inst->ref_clk);
516-
goto put_child;
511+
return PTR_ERR(inst->ref_clk);
517512
}
518513
}
519514

520515
provider = devm_of_phy_provider_register(dev, mtk_phy_xlate);
521516
return PTR_ERR_OR_ZERO(provider);
522-
523-
put_child:
524-
of_node_put(child_np);
525-
return retval;
526517
}
527518

528519
static struct platform_driver mtk_xsphy_driver = {

0 commit comments

Comments
 (0)