Skip to content

Commit d0ca576

Browse files
JuliaLawallkishon
authored andcommitted
phy: berlin-sata: add missing of_node_put
for_each_available_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_available_child_of_node(root, child) { ... when != of_node_put(child) when != e = child ( return child; | * return ...; ) ... } // </smpl> Signed-off-by: Julia Lawall <[email protected]> Acked-by: Sebastian Hesselbarth <[email protected]> Signed-off-by: Kishon Vijay Abraham I <[email protected]>
1 parent 2bb80cc commit d0ca576

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

drivers/phy/phy-berlin-sata.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static int phy_berlin_sata_probe(struct platform_device *pdev)
195195
struct phy_provider *phy_provider;
196196
struct phy_berlin_priv *priv;
197197
struct resource *res;
198-
int i = 0;
198+
int ret, i = 0;
199199
u32 phy_id;
200200

201201
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
@@ -237,22 +237,27 @@ static int phy_berlin_sata_probe(struct platform_device *pdev)
237237
if (of_property_read_u32(child, "reg", &phy_id)) {
238238
dev_err(dev, "missing reg property in node %s\n",
239239
child->name);
240-
return -EINVAL;
240+
ret = -EINVAL;
241+
goto put_child;
241242
}
242243

243244
if (phy_id >= ARRAY_SIZE(phy_berlin_power_down_bits)) {
244245
dev_err(dev, "invalid reg in node %s\n", child->name);
245-
return -EINVAL;
246+
ret = -EINVAL;
247+
goto put_child;
246248
}
247249

248250
phy_desc = devm_kzalloc(dev, sizeof(*phy_desc), GFP_KERNEL);
249-
if (!phy_desc)
250-
return -ENOMEM;
251+
if (!phy_desc) {
252+
ret = -ENOMEM;
253+
goto put_child;
254+
}
251255

252256
phy = devm_phy_create(dev, NULL, &phy_berlin_sata_ops);
253257
if (IS_ERR(phy)) {
254258
dev_err(dev, "failed to create PHY %d\n", phy_id);
255-
return PTR_ERR(phy);
259+
ret = PTR_ERR(phy);
260+
goto put_child;
256261
}
257262

258263
phy_desc->phy = phy;
@@ -269,6 +274,9 @@ static int phy_berlin_sata_probe(struct platform_device *pdev)
269274
phy_provider =
270275
devm_of_phy_provider_register(dev, phy_berlin_sata_phy_xlate);
271276
return PTR_ERR_OR_ZERO(phy_provider);
277+
put_child:
278+
of_node_put(child);
279+
return ret;
272280
}
273281

274282
static const struct of_device_id phy_berlin_sata_of_match[] = {

0 commit comments

Comments
 (0)