Skip to content

Commit 39c2b96

Browse files
JuliaLawallkishon
authored andcommitted
phy: miphy365x: add missing of_node_put
for_each_child_of_node performs an of_node_get on each iteration, so a return from the middle of the loop requires an of_node_put. A simplified version of the semantic patch that finds this problem is as follows (http://coccinelle.lip6.fr): // <smpl> @@ expression root,e; local idexpression child; @@ for_each_child_of_node(root, child) { ... when != of_node_put(child) when != e = child ( return child; | * return ...; ) ... } // </smpl> Signed-off-by: Julia Lawall <[email protected]> Signed-off-by: Kishon Vijay Abraham I <[email protected]>
1 parent 7fd7fa4 commit 39c2b96

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

drivers/phy/phy-miphy365x.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -566,22 +566,25 @@ static int miphy365x_probe(struct platform_device *pdev)
566566

567567
miphy_phy = devm_kzalloc(&pdev->dev, sizeof(*miphy_phy),
568568
GFP_KERNEL);
569-
if (!miphy_phy)
570-
return -ENOMEM;
569+
if (!miphy_phy) {
570+
ret = -ENOMEM;
571+
goto put_child;
572+
}
571573

572574
miphy_dev->phys[port] = miphy_phy;
573575

574576
phy = devm_phy_create(&pdev->dev, child, &miphy365x_ops);
575577
if (IS_ERR(phy)) {
576578
dev_err(&pdev->dev, "failed to create PHY\n");
577-
return PTR_ERR(phy);
579+
ret = PTR_ERR(phy);
580+
goto put_child;
578581
}
579582

580583
miphy_dev->phys[port]->phy = phy;
581584

582585
ret = miphy365x_of_probe(child, miphy_phy);
583586
if (ret)
584-
return ret;
587+
goto put_child;
585588

586589
phy_set_drvdata(phy, miphy_dev->phys[port]);
587590

@@ -591,12 +594,15 @@ static int miphy365x_probe(struct platform_device *pdev)
591594
&miphy_phy->ctrlreg);
592595
if (ret) {
593596
dev_err(&pdev->dev, "No sysconfig offset found\n");
594-
return ret;
597+
goto put_child;
595598
}
596599
}
597600

598601
provider = devm_of_phy_provider_register(&pdev->dev, miphy365x_xlate);
599602
return PTR_ERR_OR_ZERO(provider);
603+
put_child:
604+
of_node_put(child);
605+
return ret;
600606
}
601607

602608
static const struct of_device_id miphy365x_of_match[] = {

0 commit comments

Comments
 (0)