Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <Julia.Lawall@lip6.fr>
Acked-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>

authored by

Julia Lawall and committed by
Kishon Vijay Abraham I
d0ca576a 2bb80ccd

+14 -6
+14 -6
drivers/phy/phy-berlin-sata.c
··· 195 195 struct phy_provider *phy_provider; 196 196 struct phy_berlin_priv *priv; 197 197 struct resource *res; 198 - int i = 0; 198 + int ret, i = 0; 199 199 u32 phy_id; 200 200 201 201 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); ··· 237 237 if (of_property_read_u32(child, "reg", &phy_id)) { 238 238 dev_err(dev, "missing reg property in node %s\n", 239 239 child->name); 240 - return -EINVAL; 240 + ret = -EINVAL; 241 + goto put_child; 241 242 } 242 243 243 244 if (phy_id >= ARRAY_SIZE(phy_berlin_power_down_bits)) { 244 245 dev_err(dev, "invalid reg in node %s\n", child->name); 245 - return -EINVAL; 246 + ret = -EINVAL; 247 + goto put_child; 246 248 } 247 249 248 250 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 + } 251 255 252 256 phy = devm_phy_create(dev, NULL, &phy_berlin_sata_ops); 253 257 if (IS_ERR(phy)) { 254 258 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; 256 261 } 257 262 258 263 phy_desc->phy = phy; ··· 274 269 phy_provider = 275 270 devm_of_phy_provider_register(dev, phy_berlin_sata_phy_xlate); 276 271 return PTR_ERR_OR_ZERO(phy_provider); 272 + put_child: 273 + of_node_put(child); 274 + return ret; 277 275 } 278 276 279 277 static const struct of_device_id phy_berlin_sata_of_match[] = {