Skip to content

Commit cb3cb99

Browse files
MrVanlinusw
authored andcommitted
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>
1 parent 2677d53 commit cb3cb99

File tree

3 files changed

+16
-39
lines changed

3 files changed

+16
-39
lines changed

drivers/pinctrl/freescale/pinctrl-imx.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,6 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
580580
u32 index)
581581
{
582582
struct pinctrl_dev *pctl = ipctl->pctl;
583-
struct device_node *child;
584583
struct function_desc *func;
585584
struct group_desc *grp;
586585
const char **group_names;
@@ -605,17 +604,15 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
605604
if (!group_names)
606605
return -ENOMEM;
607606
i = 0;
608-
for_each_child_of_node(np, child)
607+
for_each_child_of_node_scoped(np, child)
609608
group_names[i++] = child->name;
610609
func->func.groups = group_names;
611610

612611
i = 0;
613-
for_each_child_of_node(np, child) {
612+
for_each_child_of_node_scoped(np, child) {
614613
grp = devm_kzalloc(ipctl->dev, sizeof(*grp), GFP_KERNEL);
615-
if (!grp) {
616-
of_node_put(child);
614+
if (!grp)
617615
return -ENOMEM;
618-
}
619616

620617
mutex_lock(&ipctl->mutex);
621618
radix_tree_insert(&pctl->pin_group_tree,
@@ -635,21 +632,13 @@ static int imx_pinctrl_parse_functions(struct device_node *np,
635632
*/
636633
static bool imx_pinctrl_dt_is_flat_functions(struct device_node *np)
637634
{
638-
struct device_node *function_np;
639-
struct device_node *pinctrl_np;
640-
641-
for_each_child_of_node(np, function_np) {
642-
if (of_property_read_bool(function_np, "fsl,pins")) {
643-
of_node_put(function_np);
635+
for_each_child_of_node_scoped(np, function_np) {
636+
if (of_property_read_bool(function_np, "fsl,pins"))
644637
return true;
645-
}
646638

647-
for_each_child_of_node(function_np, pinctrl_np) {
648-
if (of_property_read_bool(pinctrl_np, "fsl,pins")) {
649-
of_node_put(pinctrl_np);
650-
of_node_put(function_np);
639+
for_each_child_of_node_scoped(function_np, pinctrl_np) {
640+
if (of_property_read_bool(pinctrl_np, "fsl,pins"))
651641
return false;
652-
}
653642
}
654643
}
655644

drivers/pinctrl/freescale/pinctrl-imx1-core.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,6 @@ static int imx1_pinctrl_parse_functions(struct device_node *np,
508508
struct imx1_pinctrl_soc_info *info,
509509
u32 index)
510510
{
511-
struct device_node *child;
512511
struct imx1_pmx_func *func;
513512
struct imx1_pin_group *grp;
514513
int ret;
@@ -531,14 +530,12 @@ static int imx1_pinctrl_parse_functions(struct device_node *np,
531530
if (!func->groups)
532531
return -ENOMEM;
533532

534-
for_each_child_of_node(np, child) {
533+
for_each_child_of_node_scoped(np, child) {
535534
func->groups[i] = child->name;
536535
grp = &info->groups[grp_index++];
537536
ret = imx1_pinctrl_parse_groups(child, grp, info, i++);
538-
if (ret == -ENOMEM) {
539-
of_node_put(child);
537+
if (ret == -ENOMEM)
540538
return ret;
541-
}
542539
}
543540

544541
return 0;
@@ -548,7 +545,6 @@ static int imx1_pinctrl_parse_dt(struct platform_device *pdev,
548545
struct imx1_pinctrl *pctl, struct imx1_pinctrl_soc_info *info)
549546
{
550547
struct device_node *np = pdev->dev.of_node;
551-
struct device_node *child;
552548
int ret;
553549
u32 nfuncs = 0;
554550
u32 ngroups = 0;
@@ -557,7 +553,7 @@ static int imx1_pinctrl_parse_dt(struct platform_device *pdev,
557553
if (!np)
558554
return -ENODEV;
559555

560-
for_each_child_of_node(np, child) {
556+
for_each_child_of_node_scoped(np, child) {
561557
++nfuncs;
562558
ngroups += of_get_child_count(child);
563559
}
@@ -579,12 +575,10 @@ static int imx1_pinctrl_parse_dt(struct platform_device *pdev,
579575
if (!info->functions || !info->groups)
580576
return -ENOMEM;
581577

582-
for_each_child_of_node(np, child) {
578+
for_each_child_of_node_scoped(np, child) {
583579
ret = imx1_pinctrl_parse_functions(child, info, ifunc++);
584-
if (ret == -ENOMEM) {
585-
of_node_put(child);
580+
if (ret == -ENOMEM)
586581
return -ENOMEM;
587-
}
588582
}
589583

590584
return 0;

drivers/pinctrl/freescale/pinctrl-mxs.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -490,16 +490,14 @@ static int mxs_pinctrl_probe_dt(struct platform_device *pdev,
490490
/* Get groups for each function */
491491
idxf = 0;
492492
fn = fnull;
493-
for_each_child_of_node(np, child) {
493+
for_each_child_of_node_scoped(np, child) {
494494
if (is_mxs_gpio(child))
495495
continue;
496496
if (of_property_read_u32(child, "reg", &val)) {
497497
ret = mxs_pinctrl_parse_group(pdev, child,
498498
idxg++, NULL);
499-
if (ret) {
500-
of_node_put(child);
499+
if (ret)
501500
return ret;
502-
}
503501
continue;
504502
}
505503

@@ -509,19 +507,15 @@ static int mxs_pinctrl_probe_dt(struct platform_device *pdev,
509507
f->ngroups,
510508
sizeof(*f->groups),
511509
GFP_KERNEL);
512-
if (!f->groups) {
513-
of_node_put(child);
510+
if (!f->groups)
514511
return -ENOMEM;
515-
}
516512
fn = child->name;
517513
i = 0;
518514
}
519515
ret = mxs_pinctrl_parse_group(pdev, child, idxg++,
520516
&f->groups[i++]);
521-
if (ret) {
522-
of_node_put(child);
517+
if (ret)
523518
return ret;
524-
}
525519
}
526520

527521
return 0;

0 commit comments

Comments
 (0)