2023-06-06 07:38:30

by Lu Hongfei

[permalink] [raw]
Subject: [PATCH] pinctrl: nxp: Fix resource leaks in for_each_child_of_node() loops

Ensure child node references are decremented properly in the error path.

Signed-off-by: Lu Hongfei <[email protected]>
---
drivers/pinctrl/nxp/pinctrl-s32cc.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/pinctrl/nxp/pinctrl-s32cc.c b/drivers/pinctrl/nxp/pinctrl-s32cc.c
index 41e024160f36..3ae043b27463
--- a/drivers/pinctrl/nxp/pinctrl-s32cc.c
+++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c
@@ -279,8 +279,10 @@ static int s32_dt_node_to_map(struct pinctrl_dev *pctldev,
ret = s32_dt_group_node_to_map(pctldev, np, map,
&reserved_maps, num_maps,
np_config->name);
- if (ret < 0)
+ if (ret < 0) {
+ of_node_put(np);
break;
+ }
}

if (ret)
@@ -812,8 +814,10 @@ static int s32_pinctrl_parse_functions(struct device_node *np,
groups[i] = child->name;
grp = &info->groups[info->grp_index++];
ret = s32_pinctrl_parse_groups(child, grp, info);
- if (ret)
+ if (ret) {
+ of_node_put(child);
return ret;
+ }
i++;
}

@@ -896,8 +900,10 @@ static int s32_pinctrl_probe_dt(struct platform_device *pdev,
i = 0;
for_each_child_of_node(np, child) {
ret = s32_pinctrl_parse_functions(child, info, i++);
- if (ret)
+ if (ret) {
+ of_node_put(child);
return ret;
+ }
}

return 0;
--
2.39.0



2023-06-09 07:31:09

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: nxp: Fix resource leaks in for_each_child_of_node() loops

On Tue, Jun 6, 2023 at 9:02 AM Lu Hongfei <[email protected]> wrote:

> Ensure child node references are decremented properly in the error path.
>
> Signed-off-by: Lu Hongfei <[email protected]>

Patch applied.

Yours,
Linus Walleij

2023-06-13 07:09:49

by Chester Lin

[permalink] [raw]
Subject: Re: [PATCH] pinctrl: nxp: Fix resource leaks in for_each_child_of_node() loops

On Mon, Jun 12, 2023 at 04:01:00PM +0200, Markus Elfring wrote:
> > Ensure child node references are decremented properly in the error path.
> …
> > +++ b/drivers/pinctrl/nxp/pinctrl-s32cc.c
> > @@ -279,8 +279,10 @@ static int s32_dt_node_to_map(struct pinctrl_dev *pctldev,
> > ret = s32_dt_group_node_to_map(pctldev, np, map,
> > &reserved_maps, num_maps,
> > np_config->name);
> > - if (ret < 0)
> > + if (ret < 0) {
> > + of_node_put(np);
> > break;
> > + }
> > }
> >
> > if (ret)
>
> May the same error predicate be applied at two places here?
>

I think these two error predicates can be combined together in another patch.

Regards,
Chester

> Regards,
> Markus