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

pinctrl: st: fix leaked of_node references

The call to of_get_child_by_name returns a node pointer with refcount
incremented thus it must be explicitly decremented after the last
usage.

Detected by coccinelle with the following warnings:
./drivers/pinctrl/pinctrl-st.c:1188:3-9: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 1175, but without a corresponding object release within this function.
./drivers/pinctrl/pinctrl-st.c:1188:3-9: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 1175, but without a corresponding object release within this function.
./drivers/pinctrl/pinctrl-st.c:1199:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 1175, but without a corresponding object release within this function.
./drivers/pinctrl/pinctrl-st.c:1199:2-8: ERROR: missing of_node_put; acquired a node pointer with refcount incremented on line 1175, but without a corresponding object release within this function.

Signed-off-by: Wen Yang <wen.yang99@zte.com.cn>
Cc: Patrice Chotard <patrice.chotard@st.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-gpio@vger.kernel.org
Cc: linux-kernel@vger.kernel.org (open list)
Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Wen Yang and committed by
Linus Walleij
483d70d7 44b9f86c

+10 -5
+10 -5
drivers/pinctrl/pinctrl-st.c
··· 1170 1170 struct property *pp; 1171 1171 struct st_pinconf *conf; 1172 1172 struct device_node *pins; 1173 - int i = 0, npins = 0, nr_props; 1173 + int i = 0, npins = 0, nr_props, ret = 0; 1174 1174 1175 1175 pins = of_get_child_by_name(np, "st,pins"); 1176 1176 if (!pins) ··· 1185 1185 npins++; 1186 1186 } else { 1187 1187 pr_warn("Invalid st,pins in %pOFn node\n", np); 1188 - return -EINVAL; 1188 + ret = -EINVAL; 1189 + goto out_put_node; 1189 1190 } 1190 1191 } 1191 1192 ··· 1196 1195 grp->pin_conf = devm_kcalloc(info->dev, 1197 1196 npins, sizeof(*conf), GFP_KERNEL); 1198 1197 1199 - if (!grp->pins || !grp->pin_conf) 1200 - return -ENOMEM; 1198 + if (!grp->pins || !grp->pin_conf) { 1199 + ret = -ENOMEM; 1200 + goto out_put_node; 1201 + } 1201 1202 1202 1203 /* <bank offset mux direction rt_type rt_delay rt_clk> */ 1203 1204 for_each_property_of_node(pins, pp) { ··· 1232 1229 } 1233 1230 i++; 1234 1231 } 1232 + 1233 + out_put_node: 1235 1234 of_node_put(pins); 1236 1235 1237 - return 0; 1236 + return ret; 1238 1237 } 1239 1238 1240 1239 static int st_pctl_parse_functions(struct device_node *np,