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

pinctrl: st: Use scope based of_node_put() cleanups

Use scope based of_node_put() cleanup to simplify code.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
Link: https://lore.kernel.org/r/20240504-pinctrl-cleanup-v2-8-26c5f2dc1181@nxp.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Peng Fan and committed by
Linus Walleij
b7141b18 2dbcd12d

+11 -26
+11 -26
drivers/pinctrl/pinctrl-st.c
··· 1195 1195 struct property *pp; 1196 1196 struct device *dev = info->dev; 1197 1197 struct st_pinconf *conf; 1198 - struct device_node *pins; 1198 + struct device_node *pins __free(device_node) = NULL; 1199 1199 phandle bank; 1200 1200 unsigned int offset; 1201 - int i = 0, npins = 0, nr_props, ret = 0; 1201 + int i = 0, npins = 0, nr_props; 1202 1202 1203 1203 pins = of_get_child_by_name(np, "st,pins"); 1204 1204 if (!pins) ··· 1213 1213 npins++; 1214 1214 } else { 1215 1215 pr_warn("Invalid st,pins in %pOFn node\n", np); 1216 - ret = -EINVAL; 1217 - goto out_put_node; 1216 + return -EINVAL; 1218 1217 } 1219 1218 } 1220 1219 ··· 1222 1223 grp->pins = devm_kcalloc(dev, npins, sizeof(*grp->pins), GFP_KERNEL); 1223 1224 grp->pin_conf = devm_kcalloc(dev, npins, sizeof(*grp->pin_conf), GFP_KERNEL); 1224 1225 1225 - if (!grp->pins || !grp->pin_conf) { 1226 - ret = -ENOMEM; 1227 - goto out_put_node; 1228 - } 1226 + if (!grp->pins || !grp->pin_conf) 1227 + return -ENOMEM; 1229 1228 1230 1229 /* <bank offset mux direction rt_type rt_delay rt_clk> */ 1231 1230 for_each_property_of_node(pins, pp) { ··· 1257 1260 i++; 1258 1261 } 1259 1262 1260 - out_put_node: 1261 - of_node_put(pins); 1262 - 1263 - return ret; 1263 + return 0; 1264 1264 } 1265 1265 1266 1266 static int st_pctl_parse_functions(struct device_node *np, 1267 1267 struct st_pinctrl *info, u32 index, int *grp_index) 1268 1268 { 1269 1269 struct device *dev = info->dev; 1270 - struct device_node *child; 1271 1270 struct st_pmx_func *func; 1272 1271 struct st_pctl_group *grp; 1273 1272 int ret, i; ··· 1278 1285 return -ENOMEM; 1279 1286 1280 1287 i = 0; 1281 - for_each_child_of_node(np, child) { 1288 + for_each_child_of_node_scoped(np, child) { 1282 1289 func->groups[i] = child->name; 1283 1290 grp = &info->groups[*grp_index]; 1284 1291 *grp_index += 1; 1285 1292 ret = st_pctl_dt_parse_groups(child, grp, info, i++); 1286 - if (ret) { 1287 - of_node_put(child); 1293 + if (ret) 1288 1294 return ret; 1289 - } 1290 1295 } 1291 1296 dev_info(dev, "Function[%d\t name:%s,\tgroups:%d]\n", index, func->name, func->ngroups); 1292 1297 ··· 1592 1601 int i = 0, j = 0, k = 0, bank; 1593 1602 struct pinctrl_pin_desc *pdesc; 1594 1603 struct device_node *np = dev->of_node; 1595 - struct device_node *child; 1596 1604 int grp_index = 0; 1597 1605 int irq = 0; 1598 1606 ··· 1636 1646 pctl_desc->pins = pdesc; 1637 1647 1638 1648 bank = 0; 1639 - for_each_child_of_node(np, child) { 1649 + for_each_child_of_node_scoped(np, child) { 1640 1650 if (of_property_read_bool(child, "gpio-controller")) { 1641 1651 const char *bank_name = NULL; 1642 1652 char **pin_names; 1643 1653 1644 1654 ret = st_gpiolib_register_bank(info, bank, child); 1645 - if (ret) { 1646 - of_node_put(child); 1655 + if (ret) 1647 1656 return ret; 1648 - } 1649 1657 1650 1658 k = info->banks[bank].range.pin_base; 1651 1659 bank_name = info->banks[bank].range.name; 1652 1660 1653 1661 pin_names = devm_kasprintf_strarray(dev, bank_name, ST_GPIO_PINS_PER_BANK); 1654 - if (IS_ERR(pin_names)) { 1655 - of_node_put(child); 1662 + if (IS_ERR(pin_names)) 1656 1663 return PTR_ERR(pin_names); 1657 - } 1658 1664 1659 1665 for (j = 0; j < ST_GPIO_PINS_PER_BANK; j++, k++) { 1660 1666 pdesc->number = k; ··· 1664 1678 i++, &grp_index); 1665 1679 if (ret) { 1666 1680 dev_err(dev, "No functions found.\n"); 1667 - of_node_put(child); 1668 1681 return ret; 1669 1682 } 1670 1683 }