devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Shresth Prasad <shresthprasad7@gmail.com>
To: robh@kernel.org, saravanak@google.com
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	skhan@linuxfoundation.org, javier.carrasco.cruz@gmail.com,
	julia.lawall@inria.fr, Shresth Prasad <shresthprasad7@gmail.com>
Subject: [PATCH][next] of: property: Remove calls to of_node_put
Date: Thu, 16 May 2024 01:59:17 +0530	[thread overview]
Message-ID: <20240515202915.16214-3-shresthprasad7@gmail.com> (raw)

Add __free cleanup handler to some variable initialisations, which
ensures that the resource is freed as soon as the variable goes out of
scope. Thus removing the need to manually free up the resource using
of_node_put.

Suggested-by: Julia Lawall <julia.lawall@inria.fr>
Signed-off-by: Shresth Prasad <shresthprasad7@gmail.com>
---
I had submitted a similar patch a couple weeks ago addressing the same 
issue, but as it turns out I wasn't thorough enough and had left a couple
instances.

I hope this isn't too big an issue.
---
 drivers/of/property.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/drivers/of/property.c b/drivers/of/property.c
index 17b294e16c56..96a74f6a8d64 100644
--- a/drivers/of/property.c
+++ b/drivers/of/property.c
@@ -773,15 +773,14 @@ 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;
+	struct device_node *pp;
 
 	/* Get remote endpoint node. */
-	np = of_graph_get_remote_endpoint(node);
+	struct device_node *np __free(device_node) =
+			    of_graph_get_remote_endpoint(node);
 
 	pp = of_graph_get_port_parent(np);
 
-	of_node_put(np);
-
 	return pp;
 }
 EXPORT_SYMBOL(of_graph_get_remote_port_parent);
@@ -835,17 +834,18 @@ EXPORT_SYMBOL(of_graph_get_endpoint_count);
 struct device_node *of_graph_get_remote_node(const struct device_node *node,
 					     u32 port, u32 endpoint)
 {
-	struct device_node *endpoint_node, *remote;
+	struct device_node *endpoint_node __free(device_node) =
+			    of_graph_get_endpoint_by_regs(node, port, endpoint);
+
+	struct device_node *remote __free(device_node) =
+			    of_graph_get_remote_port_parent(endpoint_node);
 
-	endpoint_node = of_graph_get_endpoint_by_regs(node, port, endpoint);
 	if (!endpoint_node) {
 		pr_debug("no valid endpoint (%d, %d) for node %pOF\n",
 			 port, endpoint, node);
 		return NULL;
 	}
 
-	remote = of_graph_get_remote_port_parent(endpoint_node);
-	of_node_put(endpoint_node);
 	if (!remote) {
 		pr_debug("no valid remote node\n");
 		return NULL;
@@ -853,7 +853,6 @@ struct device_node *of_graph_get_remote_node(const struct device_node *node,
 
 	if (!of_device_is_available(remote)) {
 		pr_debug("not available for remote node\n");
-		of_node_put(remote);
 		return NULL;
 	}
 
@@ -1064,19 +1063,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);
 	}
-- 
2.45.1


             reply	other threads:[~2024-05-15 20:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-15 20:29 Shresth Prasad [this message]
2024-05-15 21:22 ` [PATCH][next] of: property: Remove calls to of_node_put Saravana Kannan
2024-05-20 19:20 ` Rob Herring (Arm)
     [not found] ` <CGME20240529101246eucas1p1266853c07f5178c7e3e4b8a264eb436e@eucas1p1.samsung.com>
2024-05-29 10:12   ` Marek Szyprowski
2024-05-29 10:50     ` Shresth Prasad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240515202915.16214-3-shresthprasad7@gmail.com \
    --to=shresthprasad7@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=julia.lawall@inria.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=saravanak@google.com \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).