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

pinctrl: freescale: 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: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/20240627131721.678727-4-peng.fan@oss.nxp.com
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Peng Fan and committed by
Linus Walleij
cb3cb99a 2677d53d

+16 -39
+7 -18
drivers/pinctrl/freescale/pinctrl-imx.c
··· 580 580 u32 index) 581 581 { 582 582 struct pinctrl_dev *pctl = ipctl->pctl; 583 - struct device_node *child; 584 583 struct function_desc *func; 585 584 struct group_desc *grp; 586 585 const char **group_names; ··· 604 605 if (!group_names) 605 606 return -ENOMEM; 606 607 i = 0; 607 - for_each_child_of_node(np, child) 608 + for_each_child_of_node_scoped(np, child) 608 609 group_names[i++] = child->name; 609 610 func->func.groups = group_names; 610 611 611 612 i = 0; 612 - for_each_child_of_node(np, child) { 613 + for_each_child_of_node_scoped(np, child) { 613 614 grp = devm_kzalloc(ipctl->dev, sizeof(*grp), GFP_KERNEL); 614 - if (!grp) { 615 - of_node_put(child); 615 + if (!grp) 616 616 return -ENOMEM; 617 - } 618 617 619 618 mutex_lock(&ipctl->mutex); 620 619 radix_tree_insert(&pctl->pin_group_tree, ··· 632 635 */ 633 636 static bool imx_pinctrl_dt_is_flat_functions(struct device_node *np) 634 637 { 635 - struct device_node *function_np; 636 - struct device_node *pinctrl_np; 637 - 638 - for_each_child_of_node(np, function_np) { 639 - if (of_property_read_bool(function_np, "fsl,pins")) { 640 - of_node_put(function_np); 638 + for_each_child_of_node_scoped(np, function_np) { 639 + if (of_property_read_bool(function_np, "fsl,pins")) 641 640 return true; 642 - } 643 641 644 - for_each_child_of_node(function_np, pinctrl_np) { 645 - if (of_property_read_bool(pinctrl_np, "fsl,pins")) { 646 - of_node_put(pinctrl_np); 647 - of_node_put(function_np); 642 + for_each_child_of_node_scoped(function_np, pinctrl_np) { 643 + if (of_property_read_bool(pinctrl_np, "fsl,pins")) 648 644 return false; 649 - } 650 645 } 651 646 } 652 647
+5 -11
drivers/pinctrl/freescale/pinctrl-imx1-core.c
··· 508 508 struct imx1_pinctrl_soc_info *info, 509 509 u32 index) 510 510 { 511 - struct device_node *child; 512 511 struct imx1_pmx_func *func; 513 512 struct imx1_pin_group *grp; 514 513 int ret; ··· 530 531 if (!func->groups) 531 532 return -ENOMEM; 532 533 533 - for_each_child_of_node(np, child) { 534 + for_each_child_of_node_scoped(np, child) { 534 535 func->groups[i] = child->name; 535 536 grp = &info->groups[grp_index++]; 536 537 ret = imx1_pinctrl_parse_groups(child, grp, info, i++); 537 - if (ret == -ENOMEM) { 538 - of_node_put(child); 538 + if (ret == -ENOMEM) 539 539 return ret; 540 - } 541 540 } 542 541 543 542 return 0; ··· 545 548 struct imx1_pinctrl *pctl, struct imx1_pinctrl_soc_info *info) 546 549 { 547 550 struct device_node *np = pdev->dev.of_node; 548 - struct device_node *child; 549 551 int ret; 550 552 u32 nfuncs = 0; 551 553 u32 ngroups = 0; ··· 553 557 if (!np) 554 558 return -ENODEV; 555 559 556 - for_each_child_of_node(np, child) { 560 + for_each_child_of_node_scoped(np, child) { 557 561 ++nfuncs; 558 562 ngroups += of_get_child_count(child); 559 563 } ··· 575 579 if (!info->functions || !info->groups) 576 580 return -ENOMEM; 577 581 578 - for_each_child_of_node(np, child) { 582 + for_each_child_of_node_scoped(np, child) { 579 583 ret = imx1_pinctrl_parse_functions(child, info, ifunc++); 580 - if (ret == -ENOMEM) { 581 - of_node_put(child); 584 + if (ret == -ENOMEM) 582 585 return -ENOMEM; 583 - } 584 586 } 585 587 586 588 return 0;
+4 -10
drivers/pinctrl/freescale/pinctrl-mxs.c
··· 490 490 /* Get groups for each function */ 491 491 idxf = 0; 492 492 fn = fnull; 493 - for_each_child_of_node(np, child) { 493 + for_each_child_of_node_scoped(np, child) { 494 494 if (is_mxs_gpio(child)) 495 495 continue; 496 496 if (of_property_read_u32(child, "reg", &val)) { 497 497 ret = mxs_pinctrl_parse_group(pdev, child, 498 498 idxg++, NULL); 499 - if (ret) { 500 - of_node_put(child); 499 + if (ret) 501 500 return ret; 502 - } 503 501 continue; 504 502 } 505 503 ··· 507 509 f->ngroups, 508 510 sizeof(*f->groups), 509 511 GFP_KERNEL); 510 - if (!f->groups) { 511 - of_node_put(child); 512 + if (!f->groups) 512 513 return -ENOMEM; 513 - } 514 514 fn = child->name; 515 515 i = 0; 516 516 } 517 517 ret = mxs_pinctrl_parse_group(pdev, child, idxg++, 518 518 &f->groups[i++]); 519 - if (ret) { 520 - of_node_put(child); 519 + if (ret) 521 520 return ret; 522 - } 523 521 } 524 522 525 523 return 0;