Skip to content

Commit 3dcc01b

Browse files
MrVanlinusw
authored andcommitted
pinctrl: s32cc: Use scope based of_node_put() cleanups
Use scope based of_node_put() cleanup to simplify code. Signed-off-by: Peng Fan <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent 7c2aabb commit 3dcc01b

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

drivers/pinctrl/nxp/pinctrl-s32cc.c

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -268,28 +268,23 @@ static int s32_dt_node_to_map(struct pinctrl_dev *pctldev,
268268
unsigned int *num_maps)
269269
{
270270
unsigned int reserved_maps;
271-
struct device_node *np;
272-
int ret = 0;
271+
int ret;
273272

274273
reserved_maps = 0;
275274
*map = NULL;
276275
*num_maps = 0;
277276

278-
for_each_available_child_of_node(np_config, np) {
277+
for_each_available_child_of_node_scoped(np_config, np) {
279278
ret = s32_dt_group_node_to_map(pctldev, np, map,
280279
&reserved_maps, num_maps,
281280
np_config->name);
282281
if (ret < 0) {
283-
of_node_put(np);
284-
break;
282+
pinctrl_utils_free_map(pctldev, *map, *num_maps);
283+
return ret;
285284
}
286285
}
287286

288-
if (ret)
289-
pinctrl_utils_free_map(pctldev, *map, *num_maps);
290-
291-
return ret;
292-
287+
return 0;
293288
}
294289

295290
static const struct pinctrl_ops s32_pctrl_ops = {
@@ -786,7 +781,6 @@ static int s32_pinctrl_parse_functions(struct device_node *np,
786781
struct s32_pinctrl_soc_info *info,
787782
u32 index)
788783
{
789-
struct device_node *child;
790784
struct pinfunction *func;
791785
struct s32_pin_group *grp;
792786
const char **groups;
@@ -810,14 +804,12 @@ static int s32_pinctrl_parse_functions(struct device_node *np,
810804
if (!groups)
811805
return -ENOMEM;
812806

813-
for_each_child_of_node(np, child) {
807+
for_each_child_of_node_scoped(np, child) {
814808
groups[i] = child->name;
815809
grp = &info->groups[info->grp_index++];
816810
ret = s32_pinctrl_parse_groups(child, grp, info);
817-
if (ret) {
818-
of_node_put(child);
811+
if (ret)
819812
return ret;
820-
}
821813
i++;
822814
}
823815

@@ -831,7 +823,6 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
831823
{
832824
struct s32_pinctrl_soc_info *info = ipctl->info;
833825
struct device_node *np = pdev->dev.of_node;
834-
struct device_node *child;
835826
struct resource *res;
836827
struct regmap *map;
837828
void __iomem *base;
@@ -889,7 +880,7 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
889880
return -ENOMEM;
890881

891882
info->ngroups = 0;
892-
for_each_child_of_node(np, child)
883+
for_each_child_of_node_scoped(np, child)
893884
info->ngroups += of_get_child_count(child);
894885

895886
info->groups = devm_kcalloc(&pdev->dev, info->ngroups,
@@ -898,12 +889,10 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
898889
return -ENOMEM;
899890

900891
i = 0;
901-
for_each_child_of_node(np, child) {
892+
for_each_child_of_node_scoped(np, child) {
902893
ret = s32_pinctrl_parse_functions(child, info, i++);
903-
if (ret) {
904-
of_node_put(child);
894+
if (ret)
905895
return ret;
906-
}
907896
}
908897

909898
return 0;

0 commit comments

Comments
 (0)