Skip to content

Commit a8c2472

Browse files
JuliaLawallkishon
authored andcommitted
phy: cygnus: pcie: 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]> Signed-off-by: Kishon Vijay Abraham I <[email protected]>
1 parent 39c2b96 commit a8c2472

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

drivers/phy/phy-bcm-cygnus-pcie.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ static int cygnus_pcie_phy_probe(struct platform_device *pdev)
128128
struct phy_provider *provider;
129129
struct resource *res;
130130
unsigned cnt = 0;
131+
int ret;
131132

132133
if (of_get_child_count(node) == 0) {
133134
dev_err(dev, "PHY no child node\n");
@@ -154,24 +155,28 @@ static int cygnus_pcie_phy_probe(struct platform_device *pdev)
154155
if (of_property_read_u32(child, "reg", &id)) {
155156
dev_err(dev, "missing reg property for %s\n",
156157
child->name);
157-
return -EINVAL;
158+
ret = -EINVAL;
159+
goto put_child;
158160
}
159161

160162
if (id >= MAX_NUM_PHYS) {
161163
dev_err(dev, "invalid PHY id: %u\n", id);
162-
return -EINVAL;
164+
ret = -EINVAL;
165+
goto put_child;
163166
}
164167

165168
if (core->phys[id].phy) {
166169
dev_err(dev, "duplicated PHY id: %u\n", id);
167-
return -EINVAL;
170+
ret = -EINVAL;
171+
goto put_child;
168172
}
169173

170174
p = &core->phys[id];
171175
p->phy = devm_phy_create(dev, child, &cygnus_pcie_phy_ops);
172176
if (IS_ERR(p->phy)) {
173177
dev_err(dev, "failed to create PHY\n");
174-
return PTR_ERR(p->phy);
178+
ret = PTR_ERR(p->phy);
179+
goto put_child;
175180
}
176181

177182
p->core = core;
@@ -191,6 +196,9 @@ static int cygnus_pcie_phy_probe(struct platform_device *pdev)
191196
dev_dbg(dev, "registered %u PCIe PHY(s)\n", cnt);
192197

193198
return 0;
199+
put_child:
200+
of_node_put(child);
201+
return ret;
194202
}
195203

196204
static const struct of_device_id cygnus_pcie_phy_match_table[] = {

0 commit comments

Comments
 (0)