linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 linux-next] leds: powernv: replace of_node_put to __free
@ 2024-06-01  3:17 MarileneGarcia
  2024-06-07 11:25 ` Marilene Andrade Garcia
  2024-06-13 17:34 ` (subset) " Lee Jones
  0 siblings, 2 replies; 4+ messages in thread
From: MarileneGarcia @ 2024-06-01  3:17 UTC (permalink / raw)
  To: Pavel Machek, Lee Jones, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy, Naveen N. Rao, Julia Lawall
  Cc: MarileneGarcia, Shuah Khan, Javier Carrasco, linux-leds,
	linuxppc-dev, linux-kernel

Use __free for device_node values, and thus drop calls to
of_node_put.

The variable attribute __free adds a scope based cleanup to
the device node. The goal is to reduce memory management issues
in the kernel code.

The of_node_put calls were removed, and the
for_each_available_child_of_node was replaced to the equivalent
for_each_available_child_of_node_scoped which use the __free.

Suggested-by: Julia Lawall <julia.lawall@inria.fr>
Signed-off-by: MarileneGarcia <marilene.agarcia@gmail.com>
---
Hello, 
Thank you for the feedback.

The line-break strategy was fixed, and now it is according to
the top one suggested.

The __free is a wrapper to __attribute__((__cleanup__())) so 
the variavel definition is needed. And according to Julia, it 
is preferred to combine the declaration and the allocation to 
ensure that there is no return that can occur after the declaration, 
but before the allocation (or more precisely the initialization).  
If there is no other option for the initialization of the variable, 
then it should be NULL.

 drivers/leds/leds-powernv.c | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/drivers/leds/leds-powernv.c b/drivers/leds/leds-powernv.c
index 4f01acb75727..49ab8c9a3f29 100644
--- a/drivers/leds/leds-powernv.c
+++ b/drivers/leds/leds-powernv.c
@@ -246,29 +246,25 @@ static int powernv_led_classdev(struct platform_device *pdev,
 	const char *cur = NULL;
 	int rc = -1;
 	struct property *p;
-	struct device_node *np;
 	struct powernv_led_data *powernv_led;
 	struct device *dev = &pdev->dev;
 
-	for_each_available_child_of_node(led_node, np) {
+	for_each_available_child_of_node_scoped(led_node, np) {
 		p = of_find_property(np, "led-types", NULL);
 
 		while ((cur = of_prop_next_string(p, cur)) != NULL) {
 			powernv_led = devm_kzalloc(dev, sizeof(*powernv_led),
 						   GFP_KERNEL);
-			if (!powernv_led) {
-				of_node_put(np);
+			if (!powernv_led)
 				return -ENOMEM;
-			}
 
 			powernv_led->common = powernv_led_common;
 			powernv_led->loc_code = (char *)np->name;
 
 			rc = powernv_led_create(dev, powernv_led, cur);
-			if (rc) {
-				of_node_put(np);
+			if (rc)
 				return rc;
-			}
+
 		} /* while end */
 	}
 
@@ -278,12 +274,11 @@ static int powernv_led_classdev(struct platform_device *pdev,
 /* Platform driver probe */
 static int powernv_led_probe(struct platform_device *pdev)
 {
-	struct device_node *led_node;
 	struct powernv_led_common *powernv_led_common;
 	struct device *dev = &pdev->dev;
-	int rc;
+	struct device_node *led_node
+		__free(device_node) = of_find_node_by_path("/ibm,opal/leds");
 
-	led_node = of_find_node_by_path("/ibm,opal/leds");
 	if (!led_node) {
 		dev_err(dev, "%s: LED parent device node not found\n",
 			__func__);
@@ -292,20 +287,15 @@ static int powernv_led_probe(struct platform_device *pdev)
 
 	powernv_led_common = devm_kzalloc(dev, sizeof(*powernv_led_common),
 					  GFP_KERNEL);
-	if (!powernv_led_common) {
-		rc = -ENOMEM;
-		goto out;
-	}
+	if (!powernv_led_common)
+		return -ENOMEM;
 
 	mutex_init(&powernv_led_common->lock);
 	powernv_led_common->max_led_type = cpu_to_be64(OPAL_SLOT_LED_TYPE_MAX);
 
 	platform_set_drvdata(pdev, powernv_led_common);
 
-	rc = powernv_led_classdev(pdev, led_node, powernv_led_common);
-out:
-	of_node_put(led_node);
-	return rc;
+	return powernv_led_classdev(pdev, led_node, powernv_led_common);
 }
 
 /* Platform driver remove */
-- 
2.34.1


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

* Re: [PATCH v3 linux-next] leds: powernv: replace of_node_put to __free
  2024-06-01  3:17 [PATCH v3 linux-next] leds: powernv: replace of_node_put to __free MarileneGarcia
@ 2024-06-07 11:25 ` Marilene Andrade Garcia
  2024-06-13 16:52   ` Lee Jones
  2024-06-13 17:34 ` (subset) " Lee Jones
  1 sibling, 1 reply; 4+ messages in thread
From: Marilene Andrade Garcia @ 2024-06-07 11:25 UTC (permalink / raw)
  To: Pavel Machek, Lee Jones, Michael Ellerman, Nicholas Piggin,
	Christophe Leroy, Naveen N. Rao, Julia Lawall
  Cc: Shuah Khan, Javier Carrasco, linux-leds, linuxppc-dev,
	linux-kernel

On 01/06/2024 00:17, MarileneGarcia wrote:
> Use __free for device_node values, and thus drop calls to
> of_node_put.
> 
> The variable attribute __free adds a scope based cleanup to
> the device node. The goal is to reduce memory management issues
> in the kernel code.
> 
> The of_node_put calls were removed, and the
> for_each_available_child_of_node was replaced to the equivalent
> for_each_available_child_of_node_scoped which use the __free.
> 
> Suggested-by: Julia Lawall <julia.lawall@inria.fr>
> Signed-off-by: MarileneGarcia <marilene.agarcia@gmail.com>
> ---
> Hello,
> Thank you for the feedback.
> 
> The line-break strategy was fixed, and now it is according to
> the top one suggested.
> 
> The __free is a wrapper to __attribute__((__cleanup__())) so
> the variavel definition is needed. And according to Julia, it
> is preferred to combine the declaration and the allocation to
> ensure that there is no return that can occur after the declaration,
> but before the allocation (or more precisely the initialization).
> If there is no other option for the initialization of the variable,
> then it should be NULL.
> 
>   drivers/leds/leds-powernv.c | 28 +++++++++-------------------
>   1 file changed, 9 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/leds/leds-powernv.c b/drivers/leds/leds-powernv.c
> index 4f01acb75727..49ab8c9a3f29 100644
> --- a/drivers/leds/leds-powernv.c
> +++ b/drivers/leds/leds-powernv.c
> @@ -246,29 +246,25 @@ static int powernv_led_classdev(struct platform_device *pdev,
>   	const char *cur = NULL;
>   	int rc = -1;
>   	struct property *p;
> -	struct device_node *np;
>   	struct powernv_led_data *powernv_led;
>   	struct device *dev = &pdev->dev;
>   
> -	for_each_available_child_of_node(led_node, np) {
> +	for_each_available_child_of_node_scoped(led_node, np) {
>   		p = of_find_property(np, "led-types", NULL);
>   
>   		while ((cur = of_prop_next_string(p, cur)) != NULL) {
>   			powernv_led = devm_kzalloc(dev, sizeof(*powernv_led),
>   						   GFP_KERNEL);
> -			if (!powernv_led) {
> -				of_node_put(np);
> +			if (!powernv_led)
>   				return -ENOMEM;
> -			}
>   
>   			powernv_led->common = powernv_led_common;
>   			powernv_led->loc_code = (char *)np->name;
>   
>   			rc = powernv_led_create(dev, powernv_led, cur);
> -			if (rc) {
> -				of_node_put(np);
> +			if (rc)
>   				return rc;
> -			}
> +
>   		} /* while end */
>   	}
>   
> @@ -278,12 +274,11 @@ static int powernv_led_classdev(struct platform_device *pdev,
>   /* Platform driver probe */
>   static int powernv_led_probe(struct platform_device *pdev)
>   {
> -	struct device_node *led_node;
>   	struct powernv_led_common *powernv_led_common;
>   	struct device *dev = &pdev->dev;
> -	int rc;
> +	struct device_node *led_node
> +		__free(device_node) = of_find_node_by_path("/ibm,opal/leds");
>   
> -	led_node = of_find_node_by_path("/ibm,opal/leds");
>   	if (!led_node) {
>   		dev_err(dev, "%s: LED parent device node not found\n",
>   			__func__);
> @@ -292,20 +287,15 @@ static int powernv_led_probe(struct platform_device *pdev)
>   
>   	powernv_led_common = devm_kzalloc(dev, sizeof(*powernv_led_common),
>   					  GFP_KERNEL);
> -	if (!powernv_led_common) {
> -		rc = -ENOMEM;
> -		goto out;
> -	}
> +	if (!powernv_led_common)
> +		return -ENOMEM;
>   
>   	mutex_init(&powernv_led_common->lock);
>   	powernv_led_common->max_led_type = cpu_to_be64(OPAL_SLOT_LED_TYPE_MAX);
>   
>   	platform_set_drvdata(pdev, powernv_led_common);
>   
> -	rc = powernv_led_classdev(pdev, led_node, powernv_led_common);
> -out:
> -	of_node_put(led_node);
> -	return rc;
> +	return powernv_led_classdev(pdev, led_node, powernv_led_common);
>   }
>   
>   /* Platform driver remove */

Hello,
Did you have a chance to look at the patch after the requested change?

Thank you,
Marilene

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

* Re: [PATCH v3 linux-next] leds: powernv: replace of_node_put to __free
  2024-06-07 11:25 ` Marilene Andrade Garcia
@ 2024-06-13 16:52   ` Lee Jones
  0 siblings, 0 replies; 4+ messages in thread
From: Lee Jones @ 2024-06-13 16:52 UTC (permalink / raw)
  To: Marilene Andrade Garcia
  Cc: Pavel Machek, Michael Ellerman, Nicholas Piggin, Christophe Leroy,
	Naveen N. Rao, Julia Lawall, Shuah Khan, Javier Carrasco,
	linux-leds, linuxppc-dev, linux-kernel

On Fri, 07 Jun 2024, Marilene Andrade Garcia wrote:

> On 01/06/2024 00:17, MarileneGarcia wrote:
> > Use __free for device_node values, and thus drop calls to
> > of_node_put.
> > 
> > The variable attribute __free adds a scope based cleanup to
> > the device node. The goal is to reduce memory management issues
> > in the kernel code.
> > 
> > The of_node_put calls were removed, and the
> > for_each_available_child_of_node was replaced to the equivalent
> > for_each_available_child_of_node_scoped which use the __free.
> > 
> > Suggested-by: Julia Lawall <julia.lawall@inria.fr>
> > Signed-off-by: MarileneGarcia <marilene.agarcia@gmail.com>
> > ---
> > Hello,
> > Thank you for the feedback.
> > 
> > The line-break strategy was fixed, and now it is according to
> > the top one suggested.
> > 
> > The __free is a wrapper to __attribute__((__cleanup__())) so
> > the variavel definition is needed. And according to Julia, it
> > is preferred to combine the declaration and the allocation to
> > ensure that there is no return that can occur after the declaration,
> > but before the allocation (or more precisely the initialization).
> > If there is no other option for the initialization of the variable,
> > then it should be NULL.
> > 
> >   drivers/leds/leds-powernv.c | 28 +++++++++-------------------
> >   1 file changed, 9 insertions(+), 19 deletions(-)
> > 
> > diff --git a/drivers/leds/leds-powernv.c b/drivers/leds/leds-powernv.c
> > index 4f01acb75727..49ab8c9a3f29 100644
> > --- a/drivers/leds/leds-powernv.c
> > +++ b/drivers/leds/leds-powernv.c
> > @@ -246,29 +246,25 @@ static int powernv_led_classdev(struct platform_device *pdev,
> >   	const char *cur = NULL;
> >   	int rc = -1;
> >   	struct property *p;
> > -	struct device_node *np;
> >   	struct powernv_led_data *powernv_led;
> >   	struct device *dev = &pdev->dev;
> > -	for_each_available_child_of_node(led_node, np) {
> > +	for_each_available_child_of_node_scoped(led_node, np) {
> >   		p = of_find_property(np, "led-types", NULL);
> >   		while ((cur = of_prop_next_string(p, cur)) != NULL) {
> >   			powernv_led = devm_kzalloc(dev, sizeof(*powernv_led),
> >   						   GFP_KERNEL);
> > -			if (!powernv_led) {
> > -				of_node_put(np);
> > +			if (!powernv_led)
> >   				return -ENOMEM;
> > -			}
> >   			powernv_led->common = powernv_led_common;
> >   			powernv_led->loc_code = (char *)np->name;
> >   			rc = powernv_led_create(dev, powernv_led, cur);
> > -			if (rc) {
> > -				of_node_put(np);
> > +			if (rc)
> >   				return rc;
> > -			}
> > +
> >   		} /* while end */
> >   	}
> > @@ -278,12 +274,11 @@ static int powernv_led_classdev(struct platform_device *pdev,
> >   /* Platform driver probe */
> >   static int powernv_led_probe(struct platform_device *pdev)
> >   {
> > -	struct device_node *led_node;
> >   	struct powernv_led_common *powernv_led_common;
> >   	struct device *dev = &pdev->dev;
> > -	int rc;
> > +	struct device_node *led_node
> > +		__free(device_node) = of_find_node_by_path("/ibm,opal/leds");
> > -	led_node = of_find_node_by_path("/ibm,opal/leds");
> >   	if (!led_node) {
> >   		dev_err(dev, "%s: LED parent device node not found\n",
> >   			__func__);
> > @@ -292,20 +287,15 @@ static int powernv_led_probe(struct platform_device *pdev)
> >   	powernv_led_common = devm_kzalloc(dev, sizeof(*powernv_led_common),
> >   					  GFP_KERNEL);
> > -	if (!powernv_led_common) {
> > -		rc = -ENOMEM;
> > -		goto out;
> > -	}
> > +	if (!powernv_led_common)
> > +		return -ENOMEM;
> >   	mutex_init(&powernv_led_common->lock);
> >   	powernv_led_common->max_led_type = cpu_to_be64(OPAL_SLOT_LED_TYPE_MAX);
> >   	platform_set_drvdata(pdev, powernv_led_common);
> > -	rc = powernv_led_classdev(pdev, led_node, powernv_led_common);
> > -out:
> > -	of_node_put(led_node);
> > -	return rc;
> > +	return powernv_led_classdev(pdev, led_node, powernv_led_common);
> >   }
> >   /* Platform driver remove */
> 
> Hello,
> Did you have a chance to look at the patch after the requested change?

Was that for me?  Please refrain from pinging.

My TODO list is long and I'm doing my best to get through it.

-- 
Lee Jones [李琼斯]

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

* Re: (subset) [PATCH v3 linux-next] leds: powernv: replace of_node_put to __free
  2024-06-01  3:17 [PATCH v3 linux-next] leds: powernv: replace of_node_put to __free MarileneGarcia
  2024-06-07 11:25 ` Marilene Andrade Garcia
@ 2024-06-13 17:34 ` Lee Jones
  1 sibling, 0 replies; 4+ messages in thread
From: Lee Jones @ 2024-06-13 17:34 UTC (permalink / raw)
  To: Pavel Machek, Michael Ellerman, Nicholas Piggin, Christophe Leroy,
	Naveen N. Rao, Julia Lawall, MarileneGarcia
  Cc: Shuah Khan, Javier Carrasco, linux-leds, linuxppc-dev,
	linux-kernel

On Sat, 01 Jun 2024 00:17:13 -0300, MarileneGarcia wrote:
> Use __free for device_node values, and thus drop calls to
> of_node_put.
> 
> The variable attribute __free adds a scope based cleanup to
> the device node. The goal is to reduce memory management issues
> in the kernel code.
> 
> [...]

Applied, thanks!

[1/1] leds: powernv: replace of_node_put to __free
      commit: 7c85503b6d597b84ea58fe3dd95cd9eaeb1f3206

--
Lee Jones [李琼斯]


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

end of thread, other threads:[~2024-06-13 17:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-01  3:17 [PATCH v3 linux-next] leds: powernv: replace of_node_put to __free MarileneGarcia
2024-06-07 11:25 ` Marilene Andrade Garcia
2024-06-13 16:52   ` Lee Jones
2024-06-13 17:34 ` (subset) " Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).