All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pinctrl: nxp: Fix resource leaks in for_each_child_of_node() loops
@ 2023-06-06  7:02 Lu Hongfei
  2023-06-09  7:25 ` Linus Walleij
  2023-06-12 14:01 ` [cocci] " Markus Elfring
  0 siblings, 2 replies; 6+ messages in thread
From: Lu Hongfei @ 2023-06-06  7:02 UTC (permalink / raw)
  To: Chester Lin, NXP S32 Linux Team, Linus Walleij,
	open list:PIN CONTROLLER - NXP S32, open list
  Cc: opensource.kernel, luhongfei

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

Signed-off-by: Lu Hongfei <luhongfei@vivo.com>
---
 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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] pinctrl: nxp: Fix resource leaks in for_each_child_of_node() loops
  2023-06-06  7:02 [PATCH] pinctrl: nxp: Fix resource leaks in for_each_child_of_node() loops Lu Hongfei
@ 2023-06-09  7:25 ` Linus Walleij
  2023-06-12 14:01 ` [cocci] " Markus Elfring
  1 sibling, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2023-06-09  7:25 UTC (permalink / raw)
  To: Lu Hongfei
  Cc: Chester Lin, NXP S32 Linux Team,
	open list:PIN CONTROLLER - NXP S32, open list, opensource.kernel

On Tue, Jun 6, 2023 at 9:02 AM Lu Hongfei <luhongfei@vivo.com> wrote:

> Ensure child node references are decremented properly in the error path.
>
> Signed-off-by: Lu Hongfei <luhongfei@vivo.com>

Patch applied.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [cocci] [PATCH] pinctrl: nxp: Fix resource leaks in for_each_child_of_node() loops
  2023-06-06  7:02 [PATCH] pinctrl: nxp: Fix resource leaks in for_each_child_of_node() loops Lu Hongfei
  2023-06-09  7:25 ` Linus Walleij
@ 2023-06-12 14:01 ` Markus Elfring
  2023-06-13  6:41   ` Chester Lin
  1 sibling, 1 reply; 6+ messages in thread
From: Markus Elfring @ 2023-06-12 14:01 UTC (permalink / raw)
  To: kernel-janitors, s32, linux-gpio, opensource.kernel, Chester Lin,
	Linus Walleij, Lu Hongfei
  Cc: LKML, cocci

> 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?

Regards,
Markus

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pinctrl: nxp: Fix resource leaks in for_each_child_of_node() loops
  2023-06-12 14:01 ` [cocci] " Markus Elfring
@ 2023-06-13  6:41   ` Chester Lin
  2023-06-13  9:15     ` [cocci] [PATCH] pinctrl: nxp: Adjust error predicates for improved exception handling in s32_dt_node_to_map()? Markus Elfring
  0 siblings, 1 reply; 6+ messages in thread
From: Chester Lin @ 2023-06-13  6:41 UTC (permalink / raw)
  To: Markus Elfring
  Cc: kernel-janitors, s32, linux-gpio, opensource.kernel,
	Linus Walleij, Lu Hongfei, LKML, cocci

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [cocci] [PATCH] pinctrl: nxp: Adjust error predicates for improved exception handling in s32_dt_node_to_map()?
  2023-06-13  6:41   ` Chester Lin
@ 2023-06-13  9:15     ` Markus Elfring
  2023-06-13  9:27       ` Chester Lin
  0 siblings, 1 reply; 6+ messages in thread
From: Markus Elfring @ 2023-06-13  9:15 UTC (permalink / raw)
  To: Chester Lin, kernel-janitors, s32, linux-gpio, opensource.kernel
  Cc: Linus Walleij, Lu Hongfei, LKML, cocci

>>> 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.

Are you going to reduce such error predicates so that exception handling
can be improved another bit?

Regards,
Markus

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pinctrl: nxp: Adjust error predicates for improved exception handling in s32_dt_node_to_map()?
  2023-06-13  9:15     ` [cocci] [PATCH] pinctrl: nxp: Adjust error predicates for improved exception handling in s32_dt_node_to_map()? Markus Elfring
@ 2023-06-13  9:27       ` Chester Lin
  0 siblings, 0 replies; 6+ messages in thread
From: Chester Lin @ 2023-06-13  9:27 UTC (permalink / raw)
  To: Markus Elfring
  Cc: kernel-janitors, s32, linux-gpio, opensource.kernel,
	Linus Walleij, Lu Hongfei, LKML, cocci

On Tue, Jun 13, 2023 at 11:15:22AM +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.
> 
> Are you going to reduce such error predicates so that exception handling
> can be improved another bit?
> 
Yes, I am. There will be a patch to improve these error predicates. Thanks for
your suggestion.

Regards,
Chester

> Regards,
> Markus

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-06-13  9:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-06  7:02 [PATCH] pinctrl: nxp: Fix resource leaks in for_each_child_of_node() loops Lu Hongfei
2023-06-09  7:25 ` Linus Walleij
2023-06-12 14:01 ` [cocci] " Markus Elfring
2023-06-13  6:41   ` Chester Lin
2023-06-13  9:15     ` [cocci] [PATCH] pinctrl: nxp: Adjust error predicates for improved exception handling in s32_dt_node_to_map()? Markus Elfring
2023-06-13  9:27       ` Chester Lin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.