LKML Archive mirror
 help / color / mirror / Atom feed
From: Amer Al Shanawany <amer.shanawany@gmail.com>
To: Maxime Ripard <mripard@kernel.org>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Cc: Julia Lawall <julia.lawall@inria.fr>,
	Shuah Khan <shuah@kernel.org>,
	Javier Carrasco <javier.carrasco.cruz@gmail.com>
Subject: [PATCH] drm/vc4: remove all usages of of_node_put()
Date: Sat, 27 Apr 2024 15:40:44 +0200	[thread overview]
Message-ID: <20240427134044.38910-1-amer.shanawany@gmail.com> (raw)

Use the scope-based cleanup feature to clean up 'struct device_node *'
when they go out of scope, and remove all instances of of_node_put()
within the same scope, to simplify function exit and avoid potential
memory leaks.

Suggested-by: Julia Lawall <julia.lawall@inria.fr>
Signed-off-by: Amer Al Shanawany <amer.shanawany@gmail.com>
---
 drivers/gpu/drm/vc4/vc4_drv.c  | 14 ++++++--------
 drivers/gpu/drm/vc4/vc4_hdmi.c |  4 +---
 drivers/gpu/drm/vc4/vc4_hvs.c  |  4 +---
 3 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/vc4/vc4_drv.c b/drivers/gpu/drm/vc4/vc4_drv.c
index c133e96b8aca..bb0bb052e595 100644
--- a/drivers/gpu/drm/vc4/vc4_drv.c
+++ b/drivers/gpu/drm/vc4/vc4_drv.c
@@ -289,7 +289,6 @@ static int vc4_drm_bind(struct device *dev)
 	struct rpi_firmware *firmware = NULL;
 	struct drm_device *drm;
 	struct vc4_dev *vc4;
-	struct device_node *node;
 	struct drm_crtc *crtc;
 	bool is_vc5;
 	int ret = 0;
@@ -302,11 +301,10 @@ static int vc4_drm_bind(struct device *dev)
 	else
 		driver = &vc4_drm_driver;
 
-	node = of_find_matching_node_and_match(NULL, vc4_dma_range_matches,
-					       NULL);
+	struct device_node *node __free(device_node) =
+		of_find_matching_node_and_match(NULL, vc4_dma_range_matches, NULL);
 	if (node) {
 		ret = of_dma_configure(dev, node, true);
-		of_node_put(node);
 
 		if (ret)
 			return ret;
@@ -341,10 +339,10 @@ static int vc4_drm_bind(struct device *dev)
 			goto err;
 	}
 
-	node = of_find_compatible_node(NULL, NULL, "raspberrypi,bcm2835-firmware");
-	if (node) {
-		firmware = rpi_firmware_get(node);
-		of_node_put(node);
+	struct device_node *np __free(device_node) =
+		of_find_compatible_node(NULL, NULL, "raspberrypi,bcm2835-firmware");
+	if (np) {
+		firmware = rpi_firmware_get(np);
 
 		if (!firmware) {
 			ret = -EPROBE_DEFER;
diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
index d30f8e8e8967..915e8da3f41a 100644
--- a/drivers/gpu/drm/vc4/vc4_hdmi.c
+++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
@@ -3661,7 +3661,6 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
 	struct drm_device *drm = dev_get_drvdata(master);
 	struct vc4_hdmi *vc4_hdmi;
 	struct drm_encoder *encoder;
-	struct device_node *ddc_node;
 	int ret;
 
 	vc4_hdmi = drmm_kzalloc(drm, sizeof(*vc4_hdmi), GFP_KERNEL);
@@ -3699,14 +3698,13 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
 	if (ret)
 		return ret;
 
-	ddc_node = of_parse_phandle(dev->of_node, "ddc", 0);
+	struct device_node *ddc_node __free(device_node) = of_parse_phandle(dev->of_node, "ddc", 0);
 	if (!ddc_node) {
 		DRM_ERROR("Failed to find ddc node in device tree\n");
 		return -ENODEV;
 	}
 
 	vc4_hdmi->ddc = of_find_i2c_adapter_by_node(ddc_node);
-	of_node_put(ddc_node);
 	if (!vc4_hdmi->ddc) {
 		DRM_DEBUG("Failed to get ddc i2c adapter by node\n");
 		return -EPROBE_DEFER;
diff --git a/drivers/gpu/drm/vc4/vc4_hvs.c b/drivers/gpu/drm/vc4/vc4_hvs.c
index 04af672caacb..6e3613e06e09 100644
--- a/drivers/gpu/drm/vc4/vc4_hvs.c
+++ b/drivers/gpu/drm/vc4/vc4_hvs.c
@@ -845,15 +845,13 @@ static int vc4_hvs_bind(struct device *dev, struct device *master, void *data)
 
 	if (vc4->is_vc5) {
 		struct rpi_firmware *firmware;
-		struct device_node *node;
+		struct device_node *node __free(device_node) = rpi_firmware_find_node();
 		unsigned int max_rate;
 
-		node = rpi_firmware_find_node();
 		if (!node)
 			return -EINVAL;
 
 		firmware = rpi_firmware_get(node);
-		of_node_put(node);
 		if (!firmware)
 			return -EPROBE_DEFER;
 
-- 
2.34.1


                 reply	other threads:[~2024-04-27 13:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240427134044.38910-1-amer.shanawany@gmail.com \
    --to=amer.shanawany@gmail.com \
    --cc=airlied@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=julia.lawall@inria.fr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=shuah@kernel.org \
    --cc=tzimmermann@suse.de \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).