mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] gpu: ipu-v3: Removal of of_node_put with __free for auto cleanup
@ 2024-07-02 15:01 Abhinav Jain
  2024-07-02 15:29 ` Javier Carrasco
  0 siblings, 1 reply; 5+ messages in thread
From: Abhinav Jain @ 2024-07-02 15:01 UTC (permalink / raw)
  To: p.zabel, airlied, daniel, dri-devel, linux-kernel
  Cc: skhan, javier.carrasco.cruz, jain.abhinav177, julia.lawall

Remove of_node_put for device node prg_node.

Suggested-by: Julia Lawall <julia.lawall@inria.fr>
Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
---
 drivers/gpu/ipu-v3/ipu-prg.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-prg.c b/drivers/gpu/ipu-v3/ipu-prg.c
index 729605709955..d1f46bc761ec 100644
--- a/drivers/gpu/ipu-v3/ipu-prg.c
+++ b/drivers/gpu/ipu-v3/ipu-prg.c
@@ -84,8 +84,8 @@ static LIST_HEAD(ipu_prg_list);
 struct ipu_prg *
 ipu_prg_lookup_by_phandle(struct device *dev, const char *name, int ipu_id)
 {
-	struct device_node *prg_node = of_parse_phandle(dev->of_node,
-							name, 0);
+	struct device_node *prg_node __free(device_node) =
+		of_parse_phandle(dev->of_node, name, 0);
 	struct ipu_prg *prg;
 
 	mutex_lock(&ipu_prg_list_mutex);
@@ -95,14 +95,11 @@ ipu_prg_lookup_by_phandle(struct device *dev, const char *name, int ipu_id)
 			device_link_add(dev, prg->dev,
 					DL_FLAG_AUTOREMOVE_CONSUMER);
 			prg->id = ipu_id;
-			of_node_put(prg_node);
 			return prg;
 		}
 	}
 	mutex_unlock(&ipu_prg_list_mutex);
 
-	of_node_put(prg_node);
-
 	return NULL;
 }
 
-- 
2.34.1


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

* Re: [PATCH] gpu: ipu-v3: Removal of of_node_put with __free for auto cleanup
  2024-07-02 15:01 [PATCH] gpu: ipu-v3: Removal of of_node_put with __free for auto cleanup Abhinav Jain
@ 2024-07-02 15:29 ` Javier Carrasco
  2024-07-04 13:26   ` Abhinav Jain
  0 siblings, 1 reply; 5+ messages in thread
From: Javier Carrasco @ 2024-07-02 15:29 UTC (permalink / raw)
  To: Abhinav Jain, p.zabel, airlied, daniel, dri-devel, linux-kernel
  Cc: skhan, julia.lawall

On 02/07/2024 17:01, Abhinav Jain wrote:
> Remove of_node_put for device node prg_node.
> 
> Suggested-by: Julia Lawall <julia.lawall@inria.fr>
> Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
> ---
>  drivers/gpu/ipu-v3/ipu-prg.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/gpu/ipu-v3/ipu-prg.c b/drivers/gpu/ipu-v3/ipu-prg.c
> index 729605709955..d1f46bc761ec 100644
> --- a/drivers/gpu/ipu-v3/ipu-prg.c
> +++ b/drivers/gpu/ipu-v3/ipu-prg.c
> @@ -84,8 +84,8 @@ static LIST_HEAD(ipu_prg_list);
>  struct ipu_prg *
>  ipu_prg_lookup_by_phandle(struct device *dev, const char *name, int ipu_id)
>  {
> -	struct device_node *prg_node = of_parse_phandle(dev->of_node,
> -							name, 0);
> +	struct device_node *prg_node __free(device_node) =
> +		of_parse_phandle(dev->of_node, name, 0);
>  	struct ipu_prg *prg;
>  
>  	mutex_lock(&ipu_prg_list_mutex);
> @@ -95,14 +95,11 @@ ipu_prg_lookup_by_phandle(struct device *dev, const char *name, int ipu_id)
>  			device_link_add(dev, prg->dev,
>  					DL_FLAG_AUTOREMOVE_CONSUMER);
>  			prg->id = ipu_id;
> -			of_node_put(prg_node);
>  			return prg;
>  		}
>  	}
>  	mutex_unlock(&ipu_prg_list_mutex);
>  
> -	of_node_put(prg_node);
> -
>  	return NULL;
>  }
>  

Hi Abhinav,

Apart form having sent two different patches with the same title (hence
the confusion), this cleanup is right from a functional point of view.

On the other hand, the description should address why you are doing this
cleanup (e.g. to remove the need for explicit of_node_put() when the
variable goes out of scope). The need for of_node_put() does no vanish,
it is only automated and no longer visible at first glance by means of
the cleanup attribute.

Best regards,
Javier Carrasco

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

* Re: [PATCH] gpu: ipu-v3: Removal of of_node_put with __free for auto cleanup
  2024-07-02 15:29 ` Javier Carrasco
@ 2024-07-04 13:26   ` Abhinav Jain
  0 siblings, 0 replies; 5+ messages in thread
From: Abhinav Jain @ 2024-07-04 13:26 UTC (permalink / raw)
  To: javier.carrasco.cruz
  Cc: airlied, daniel, dri-devel, jain.abhinav177, julia.lawall,
	linux-kernel, p.zabel, skhan

On Tue, 2 Jul 2024 17:29:14 +0200, Javier Carrasco wrote:
> Hi Abhinav,
>
> Apart form having sent two different patches with the same title (hence
> the confusion), this cleanup is right from a functional point of view.
>
> On the other hand, the description should address why you are doing this
> cleanup (e.g. to remove the need for explicit of_node_put() when the
> variable goes out of scope). The need for of_node_put() does no vanish,
> it is only automated and no longer visible at first glance by means of
> the cleanup attribute.
>
> Best regards,
> Javier Carrasco

Hi Javier,

Thank you for the detailed feedback. I have modified the patch subject as
well as the commit description to better fit the cleanup task being done.

PATCH v2:
https://lore.kernel.org/all/20240704132142.1003887-1-jain.abhinav177@gmail.com/

Best Regards,
Abhinav Jain

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

* Re: [PATCH] gpu: ipu-v3: Removal of of_node_put with __free for auto cleanup
  2024-07-02 14:48 Abhinav Jain
@ 2024-07-02 15:08 ` Javier Carrasco
  0 siblings, 0 replies; 5+ messages in thread
From: Javier Carrasco @ 2024-07-02 15:08 UTC (permalink / raw)
  To: Abhinav Jain, p.zabel, airlied, daniel, dri-devel, linux-kernel; +Cc: skhan

On 02/07/2024 16:48, Abhinav Jain wrote:
> Remove of_node_put from device node of_node.
> Move declaration to initialization for ensuring scope sanity.
> 
> Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
> ---
>  drivers/gpu/ipu-v3/ipu-common.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c
> index 71ec1e7f657a..f8cc3f721d2a 100644
> --- a/drivers/gpu/ipu-v3/ipu-common.c
> +++ b/drivers/gpu/ipu-v3/ipu-common.c
> @@ -1150,10 +1150,10 @@ static int ipu_add_client_devices(struct ipu_soc *ipu, unsigned long ipu_base)
>  	for (i = 0; i < ARRAY_SIZE(client_reg); i++) {
>  		struct ipu_platform_reg *reg = &client_reg[i];
>  		struct platform_device *pdev;
> -		struct device_node *of_node;
> -
>  		/* Associate subdevice with the corresponding port node */
> -		of_node = of_graph_get_port_by_id(dev->of_node, i);
> +		struct device_node *of_node __free(device_node) =
> +			of_graph_get_port_by_id(dev->of_node, i);
> +
>  		if (!of_node) {
>  			dev_info(dev,
>  				 "no port@%d node in %pOF, not using %s%d\n",


Hi Abhinav,

1. You sent this patch twice.
2. The __free() macro removes the need for of_node_put(), but you kept
the calls to that function.
3. If you are aiming for a code refactoring, do not apply the __free()
macro to a single device_node, leaving the rest untouched.

Best regards,
Javier Carrasco

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

* [PATCH] gpu: ipu-v3: Removal of of_node_put with __free for auto cleanup
@ 2024-07-02 14:48 Abhinav Jain
  2024-07-02 15:08 ` Javier Carrasco
  0 siblings, 1 reply; 5+ messages in thread
From: Abhinav Jain @ 2024-07-02 14:48 UTC (permalink / raw)
  To: p.zabel, airlied, daniel, dri-devel, linux-kernel
  Cc: skhan, javier.carrasco.cruz, jain.abhinav177

Remove of_node_put from device node of_node.
Move declaration to initialization for ensuring scope sanity.

Signed-off-by: Abhinav Jain <jain.abhinav177@gmail.com>
---
 drivers/gpu/ipu-v3/ipu-common.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/ipu-v3/ipu-common.c b/drivers/gpu/ipu-v3/ipu-common.c
index 71ec1e7f657a..f8cc3f721d2a 100644
--- a/drivers/gpu/ipu-v3/ipu-common.c
+++ b/drivers/gpu/ipu-v3/ipu-common.c
@@ -1150,10 +1150,10 @@ static int ipu_add_client_devices(struct ipu_soc *ipu, unsigned long ipu_base)
 	for (i = 0; i < ARRAY_SIZE(client_reg); i++) {
 		struct ipu_platform_reg *reg = &client_reg[i];
 		struct platform_device *pdev;
-		struct device_node *of_node;
-
 		/* Associate subdevice with the corresponding port node */
-		of_node = of_graph_get_port_by_id(dev->of_node, i);
+		struct device_node *of_node __free(device_node) =
+			of_graph_get_port_by_id(dev->of_node, i);
+
 		if (!of_node) {
 			dev_info(dev,
 				 "no port@%d node in %pOF, not using %s%d\n",
-- 
2.34.1


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

end of thread, other threads:[~2024-07-04 13:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-02 15:01 [PATCH] gpu: ipu-v3: Removal of of_node_put with __free for auto cleanup Abhinav Jain
2024-07-02 15:29 ` Javier Carrasco
2024-07-04 13:26   ` Abhinav Jain
  -- strict thread matches above, loose matches on Subject: below --
2024-07-02 14:48 Abhinav Jain
2024-07-02 15:08 ` Javier Carrasco

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®