diff mbox series

[3/3] of: property: Do some clean up with use of __free()

Message ID 20240830020626.115933-4-zhangzekun11@huawei.com
State Accepted
Headers show
Series Do some cleanup with use of __free() | expand

Checks

Context Check Description
robh/checkpatch success
robh/patch-applied fail build log

Commit Message

Zhang Zekun Aug. 30, 2024, 2:06 a.m. UTC
__free() provides a scoped of_node_put() functionality to put the
device_node automatically, and we don't need to call of_node_put()
directly. Let's simplify the code a bit with the use of __free().

Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
---
 drivers/of/property.c | 28 ++++++++--------------------
 1 file changed, 8 insertions(+), 20 deletions(-)

Comments

Krzysztof Kozlowski Aug. 31, 2024, 6:38 a.m. UTC | #1
On Fri, Aug 30, 2024 at 10:06:26AM +0800, Zhang Zekun wrote:
> __free() provides a scoped of_node_put() functionality to put the
> device_node automatically, and we don't need to call of_node_put()
> directly. Let's simplify the code a bit with the use of __free().
> 
> Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
> ---
>  drivers/of/property.c | 28 ++++++++--------------------
>  1 file changed, 8 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/of/property.c b/drivers/of/property.c
> index 164d77cb9445..940324225c34 100644
> --- a/drivers/of/property.c
> +++ b/drivers/of/property.c
> @@ -773,16 +773,11 @@ EXPORT_SYMBOL(of_graph_get_port_parent);
>  struct device_node *of_graph_get_remote_port_parent(
>  			       const struct device_node *node)
>  {
> -	struct device_node *np, *pp;
> -
>  	/* Get remote endpoint node. */
> -	np = of_graph_get_remote_endpoint(node);
> -
> -	pp = of_graph_get_port_parent(np);
> +	struct device_node *np __free(device_node) =
> +		of_graph_get_remote_endpoint(node);
>  
> -	of_node_put(np);
> -
> -	return pp;
> +	return of_graph_get_port_parent(np);

Original code was obvious and simple. This is not an improvement.

>  }
>  EXPORT_SYMBOL(of_graph_get_remote_port_parent);
>  
> @@ -1064,19 +1059,15 @@ static void of_link_to_phandle(struct device_node *con_np,
>  			      struct device_node *sup_np,
>  			      u8 flags)
>  {
> -	struct device_node *tmp_np = of_node_get(sup_np);
> +	struct device_node *tmp_np __free(device_node) = of_node_get(sup_np);
>  
>  	/* Check that sup_np and its ancestors are available. */
>  	while (tmp_np) {
> -		if (of_fwnode_handle(tmp_np)->dev) {
> -			of_node_put(tmp_np);
> +		if (of_fwnode_handle(tmp_np)->dev)
>  			break;
> -		}
>  
> -		if (!of_device_is_available(tmp_np)) {
> -			of_node_put(tmp_np);
> +		if (!of_device_is_available(tmp_np))
>  			return;
> -		}
>  
>  		tmp_np = of_get_next_parent(tmp_np);
>  	}
> @@ -1440,16 +1431,13 @@ static int of_link_property(struct device_node *con_np, const char *prop_name)
>  		}
>  
>  		while ((phandle = s->parse_prop(con_np, prop_name, i))) {
> -			struct device_node *con_dev_np;
> +			struct device_node *con_dev_np __free(device_node) =
> +				s->get_con_dev ? s->get_con_dev(con_np) : of_node_get(con_np);
>  
> -			con_dev_np = s->get_con_dev
> -					? s->get_con_dev(con_np)
> -					: of_node_get(con_np);
>  			matched = true;
>  			i++;
>  			of_link_to_phandle(con_dev_np, phandle, s->fwlink_flags);
>  			of_node_put(phandle);
> -			of_node_put(con_dev_np);

Neither is this.

Best regards,
Krzysztof
Rob Herring (Arm) Sept. 12, 2024, 8:25 p.m. UTC | #2
On Fri, 30 Aug 2024 10:06:26 +0800, Zhang Zekun wrote:
> __free() provides a scoped of_node_put() functionality to put the
> device_node automatically, and we don't need to call of_node_put()
> directly. Let's simplify the code a bit with the use of __free().
> 
> Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com>
> ---
>  drivers/of/property.c | 28 ++++++++--------------------
>  1 file changed, 8 insertions(+), 20 deletions(-)
> 

Applied, thanks!
diff mbox series

Patch

diff --git a/drivers/of/property.c b/drivers/of/property.c
index 164d77cb9445..940324225c34 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -773,16 +773,11 @@  EXPORT_SYMBOL(of_graph_get_port_parent);
 struct device_node *of_graph_get_remote_port_parent(
 			       const struct device_node *node)
 {
-	struct device_node *np, *pp;
-
 	/* Get remote endpoint node. */
-	np = of_graph_get_remote_endpoint(node);
-
-	pp = of_graph_get_port_parent(np);
+	struct device_node *np __free(device_node) =
+		of_graph_get_remote_endpoint(node);
 
-	of_node_put(np);
-
-	return pp;
+	return of_graph_get_port_parent(np);
 }
 EXPORT_SYMBOL(of_graph_get_remote_port_parent);
 
@@ -1064,19 +1059,15 @@  static void of_link_to_phandle(struct device_node *con_np,
 			      struct device_node *sup_np,
 			      u8 flags)
 {
-	struct device_node *tmp_np = of_node_get(sup_np);
+	struct device_node *tmp_np __free(device_node) = of_node_get(sup_np);
 
 	/* Check that sup_np and its ancestors are available. */
 	while (tmp_np) {
-		if (of_fwnode_handle(tmp_np)->dev) {
-			of_node_put(tmp_np);
+		if (of_fwnode_handle(tmp_np)->dev)
 			break;
-		}
 
-		if (!of_device_is_available(tmp_np)) {
-			of_node_put(tmp_np);
+		if (!of_device_is_available(tmp_np))
 			return;
-		}
 
 		tmp_np = of_get_next_parent(tmp_np);
 	}
@@ -1440,16 +1431,13 @@  static int of_link_property(struct device_node *con_np, const char *prop_name)
 		}
 
 		while ((phandle = s->parse_prop(con_np, prop_name, i))) {
-			struct device_node *con_dev_np;
+			struct device_node *con_dev_np __free(device_node) =
+				s->get_con_dev ? s->get_con_dev(con_np) : of_node_get(con_np);
 
-			con_dev_np = s->get_con_dev
-					? s->get_con_dev(con_np)
-					: of_node_get(con_np);
 			matched = true;
 			i++;
 			of_link_to_phandle(con_dev_np, phandle, s->fwlink_flags);
 			of_node_put(phandle);
-			of_node_put(con_dev_np);
 		}
 		s++;
 	}