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

clk: si5351: add missing of_node_put

for_each_child_of_node performs an of_node_get on each iteration, so
a break out of the loop requires an of_node_put.

A simplified version of the semantic patch that fixes 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;
|
+ of_node_put(child);
? return ...;
)
...
}
// </smpl>

The resulting puts were manually moved to the end of the function for
conciseness.

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

authored by

Julia Lawall and committed by
Stephen Boyd
a1bdfbaf 6bc9d9d6

+10 -7
+10 -7
drivers/clk/clk-si5351.c
··· 1183 1183 if (of_property_read_u32(child, "reg", &num)) { 1184 1184 dev_err(&client->dev, "missing reg property of %s\n", 1185 1185 child->name); 1186 - return -EINVAL; 1186 + goto put_child; 1187 1187 } 1188 1188 1189 1189 if (num >= 8 || 1190 1190 (variant == SI5351_VARIANT_A3 && num >= 3)) { 1191 1191 dev_err(&client->dev, "invalid clkout %d\n", num); 1192 - return -EINVAL; 1192 + goto put_child; 1193 1193 } 1194 1194 1195 1195 if (!of_property_read_u32(child, "silabs,multisynth-source", ··· 1207 1207 dev_err(&client->dev, 1208 1208 "invalid parent %d for multisynth %d\n", 1209 1209 val, num); 1210 - return -EINVAL; 1210 + goto put_child; 1211 1211 } 1212 1212 } 1213 1213 ··· 1230 1230 dev_err(&client->dev, 1231 1231 "invalid parent %d for clkout %d\n", 1232 1232 val, num); 1233 - return -EINVAL; 1233 + goto put_child; 1234 1234 } 1235 1235 pdata->clkout[num].clkout_src = 1236 1236 SI5351_CLKOUT_SRC_CLKIN; ··· 1239 1239 dev_err(&client->dev, 1240 1240 "invalid parent %d for clkout %d\n", 1241 1241 val, num); 1242 - return -EINVAL; 1242 + goto put_child; 1243 1243 } 1244 1244 } 1245 1245 ··· 1256 1256 dev_err(&client->dev, 1257 1257 "invalid drive strength %d for clkout %d\n", 1258 1258 val, num); 1259 - return -EINVAL; 1259 + goto put_child; 1260 1260 } 1261 1261 } 1262 1262 ··· 1283 1283 dev_err(&client->dev, 1284 1284 "invalid disable state %d for clkout %d\n", 1285 1285 val, num); 1286 - return -EINVAL; 1286 + goto put_child; 1287 1287 } 1288 1288 } 1289 1289 ··· 1296 1296 client->dev.platform_data = pdata; 1297 1297 1298 1298 return 0; 1299 + put_child: 1300 + of_node_put(child); 1301 + return -EINVAL; 1299 1302 } 1300 1303 #else 1301 1304 static int si5351_dt_parse(struct i2c_client *client, enum si5351_variant variant)