Skip to content

Commit 2bb80cc

Browse files
JuliaLawallkishon
authored andcommitted
phy: mt65xx-usb3: 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 0b25ff8 commit 2bb80cc

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

drivers/phy/phy-mt65xx-usb3.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static int mt65xx_u3phy_probe(struct platform_device *pdev)
415415
struct resource *sif_res;
416416
struct mt65xx_u3phy *u3phy;
417417
struct resource res;
418-
int port;
418+
int port, retval;
419419

420420
u3phy = devm_kzalloc(dev, sizeof(*u3phy), GFP_KERNEL);
421421
if (!u3phy)
@@ -447,31 +447,34 @@ static int mt65xx_u3phy_probe(struct platform_device *pdev)
447447
for_each_child_of_node(np, child_np) {
448448
struct mt65xx_phy_instance *instance;
449449
struct phy *phy;
450-
int retval;
451450

452451
instance = devm_kzalloc(dev, sizeof(*instance), GFP_KERNEL);
453-
if (!instance)
454-
return -ENOMEM;
452+
if (!instance) {
453+
retval = -ENOMEM;
454+
goto put_child;
455+
}
455456

456457
u3phy->phys[port] = instance;
457458

458459
phy = devm_phy_create(dev, child_np, &mt65xx_u3phy_ops);
459460
if (IS_ERR(phy)) {
460461
dev_err(dev, "failed to create phy\n");
461-
return PTR_ERR(phy);
462+
retval = PTR_ERR(phy);
463+
goto put_child;
462464
}
463465

464466
retval = of_address_to_resource(child_np, 0, &res);
465467
if (retval) {
466468
dev_err(dev, "failed to get address resource(id-%d)\n",
467469
port);
468-
return retval;
470+
goto put_child;
469471
}
470472

471473
instance->port_base = devm_ioremap_resource(&phy->dev, &res);
472474
if (IS_ERR(instance->port_base)) {
473475
dev_err(dev, "failed to remap phy regs\n");
474-
return PTR_ERR(instance->port_base);
476+
retval = PTR_ERR(instance->port_base);
477+
goto put_child;
475478
}
476479

477480
instance->phy = phy;
@@ -483,6 +486,9 @@ static int mt65xx_u3phy_probe(struct platform_device *pdev)
483486
provider = devm_of_phy_provider_register(dev, mt65xx_phy_xlate);
484487

485488
return PTR_ERR_OR_ZERO(provider);
489+
put_child:
490+
of_node_put(child_np);
491+
return retval;
486492
}
487493

488494
static const struct of_device_id mt65xx_u3phy_id_table[] = {

0 commit comments

Comments
 (0)