public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kousik Sanagavarapu <five231003@gmail.com>
To: Nishanth Menon <nm@ti.com>,
	Santosh Shilimkar <ssantosh@kernel.org>,
	Julia Lawall <julia.lawall@inria.fr>
Cc: Shuah Khan <skhan@linuxfoundation.org>,
	Javier Carrasco <javier.carrasco.cruz@gmail.com>,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Kousik Sanagavarapu <five231003@gmail.com>
Subject: [PATCH 2/3] soc: ti: knav_qmss_queue: do device_node auto cleanup
Date: Fri, 10 May 2024 12:43:23 +0530	[thread overview]
Message-ID: <20240510071432.62913-3-five231003@gmail.com> (raw)
In-Reply-To: <20240510071432.62913-1-five231003@gmail.com>

Use scope based cleanup, instead of manual of_node_put() calls, which
automatically free()s "struct device_node".

Doing the cleanup this way has the advantage of reducing the chance of
memory leaks in case we need to read from new OF nodes in the future
when we probe.

Suggested-by: Julia Lawall <julia.lawall@inria.fr>
Signed-off-by: Kousik Sanagavarapu <five231003@gmail.com>
---
 drivers/soc/ti/knav_qmss_queue.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/soc/ti/knav_qmss_queue.c b/drivers/soc/ti/knav_qmss_queue.c
index 06fb5505c22c..237946312080 100644
--- a/drivers/soc/ti/knav_qmss_queue.c
+++ b/drivers/soc/ti/knav_qmss_queue.c
@@ -1755,7 +1755,6 @@ MODULE_DEVICE_TABLE(of, keystone_qmss_of_match);
 static int knav_queue_probe(struct platform_device *pdev)
 {
 	struct device_node *node = pdev->dev.of_node;
-	struct device_node *qmgrs, *queue_pools, *regions, *pdsps;
 	struct device *dev = &pdev->dev;
 	u32 temp[2];
 	int ret;
@@ -1799,19 +1798,20 @@ static int knav_queue_probe(struct platform_device *pdev)
 	kdev->num_queues = temp[1];
 
 	/* Initialize queue managers using device tree configuration */
-	qmgrs =  of_get_child_by_name(node, "qmgrs");
+	struct device_node *qmgrs __free(device_node) =
+			of_get_child_by_name(node, "qmgrs");
 	if (!qmgrs) {
 		dev_err(dev, "queue manager info not specified\n");
 		ret = -ENODEV;
 		goto err;
 	}
 	ret = knav_queue_init_qmgrs(kdev, qmgrs);
-	of_node_put(qmgrs);
 	if (ret)
 		goto err;
 
 	/* get pdsp configuration values from device tree */
-	pdsps =  of_get_child_by_name(node, "pdsps");
+	struct device_node *pdsps __free(device_node) =
+			of_get_child_by_name(node, "pdsps");
 	if (pdsps) {
 		ret = knav_queue_init_pdsps(kdev, pdsps);
 		if (ret)
@@ -1821,17 +1821,16 @@ static int knav_queue_probe(struct platform_device *pdev)
 		if (ret)
 			goto err;
 	}
-	of_node_put(pdsps);
 
 	/* get usable queue range values from device tree */
-	queue_pools = of_get_child_by_name(node, "queue-pools");
+	struct device_node *queue_pools __free(device_node) =
+			of_get_child_by_name(node, "queue-pools");
 	if (!queue_pools) {
 		dev_err(dev, "queue-pools not specified\n");
 		ret = -ENODEV;
 		goto err;
 	}
 	ret = knav_setup_queue_pools(kdev, queue_pools);
-	of_node_put(queue_pools);
 	if (ret)
 		goto err;
 
@@ -1853,14 +1852,14 @@ static int knav_queue_probe(struct platform_device *pdev)
 	if (ret)
 		goto err;
 
-	regions = of_get_child_by_name(node, "descriptor-regions");
+	struct device_node *regions __free(device_node) =
+			of_get_child_by_name(node, "descriptor-regions");
 	if (!regions) {
 		dev_err(dev, "descriptor-regions not specified\n");
 		ret = -ENODEV;
 		goto err;
 	}
 	ret = knav_queue_setup_regions(kdev, regions);
-	of_node_put(regions);
 	if (ret)
 		goto err;
 
-- 
2.45.0.rc1.8.ge326e52010


  parent reply	other threads:[~2024-05-10  7:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-10  7:13 [PATCH 0/3] Use scope based cleanup in drivers/soc/ti/ Kousik Sanagavarapu
2024-05-10  7:13 ` [PATCH 1/3] soc: ti: pruss: do device_node auto cleanup Kousik Sanagavarapu
2024-05-16 14:41   ` Jonathan Cameron
2024-05-10  7:13 ` Kousik Sanagavarapu [this message]
2024-05-11 10:12   ` [PATCH 2/3] soc: ti: knav_qmss_queue: " kernel test robot
2024-05-12 10:26     ` Kousik Sanagavarapu
2024-05-12 10:36       ` Julia Lawall
2024-05-13  6:44       ` Nathan Chancellor
2024-05-13  7:23         ` Kousik Sanagavarapu
2024-05-16 14:48           ` Jonathan Cameron
2024-05-10  7:13 ` [PATCH 3/3] soc: ti: pm33xx: " Kousik Sanagavarapu
2024-05-11  9:06 ` [PATCH 0/3] Use scope based cleanup in drivers/soc/ti/ Kousik Sanagavarapu

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=20240510071432.62913-3-five231003@gmail.com \
    --to=five231003@gmail.com \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=julia.lawall@inria.fr \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=skhan@linuxfoundation.org \
    --cc=ssantosh@kernel.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