Skip to content

Commit 0b25ff8

Browse files
JuliaLawallkishon
authored andcommitted
phy: brcmstb-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: Brian Norris <[email protected]> Signed-off-by: Kishon Vijay Abraham I <[email protected]>
1 parent 97dc5bf commit 0b25ff8

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

drivers/phy/phy-brcmstb-sata.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static int brcm_sata_phy_probe(struct platform_device *pdev)
140140
struct brcm_sata_phy *priv;
141141
struct resource *res;
142142
struct phy_provider *provider;
143-
int count = 0;
143+
int ret, count = 0;
144144

145145
if (of_get_child_count(dn) == 0)
146146
return -ENODEV;
@@ -163,16 +163,19 @@ static int brcm_sata_phy_probe(struct platform_device *pdev)
163163
if (of_property_read_u32(child, "reg", &id)) {
164164
dev_err(dev, "missing reg property in node %s\n",
165165
child->name);
166-
return -EINVAL;
166+
ret = -EINVAL;
167+
goto put_child;
167168
}
168169

169170
if (id >= MAX_PORTS) {
170171
dev_err(dev, "invalid reg: %u\n", id);
171-
return -EINVAL;
172+
ret = -EINVAL;
173+
goto put_child;
172174
}
173175
if (priv->phys[id].phy) {
174176
dev_err(dev, "already registered port %u\n", id);
175-
return -EINVAL;
177+
ret = -EINVAL;
178+
goto put_child;
176179
}
177180

178181
port = &priv->phys[id];
@@ -182,7 +185,8 @@ static int brcm_sata_phy_probe(struct platform_device *pdev)
182185
port->ssc_en = of_property_read_bool(child, "brcm,enable-ssc");
183186
if (IS_ERR(port->phy)) {
184187
dev_err(dev, "failed to create PHY\n");
185-
return PTR_ERR(port->phy);
188+
ret = PTR_ERR(port->phy);
189+
goto put_child;
186190
}
187191

188192
phy_set_drvdata(port->phy, port);
@@ -198,6 +202,9 @@ static int brcm_sata_phy_probe(struct platform_device *pdev)
198202
dev_info(dev, "registered %d port(s)\n", count);
199203

200204
return 0;
205+
put_child:
206+
of_node_put(child);
207+
return ret;
201208
}
202209

203210
static struct platform_driver brcm_sata_phy_driver = {

0 commit comments

Comments
 (0)