Linux Media Controller development
 help / color / mirror / Atom feed
From: Biren Pandya <birenpandya@gmail.com>
To: mchehab@kernel.org, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: jacopo.mondi+renesas@ideasonboard.com,
	Biren Pandya <birenpandya@gmail.com>
Subject: [PATCH v6 4/4] media: renesas: rzg2l-core: Add missing media_entity_cleanup()
Date: Thu,  9 Jul 2026 14:48:18 +0530	[thread overview]
Message-ID: <20260709091813.67081-10-birenpandya@gmail.com> (raw)
In-Reply-To: <20260709091813.67081-6-birenpandya@gmail.com>

The media initialization error path and the remove function fail to call
media_entity_cleanup() upon teardown.

While currently a no-op, calling media_entity_cleanup()
is an API requirement for entities initialized with
media_entity_pads_init() to prevent memory leaks.

Add the missing media_entity_cleanup() calls.

Additionally, rework the error path in rzg2l_cru_media_init() to use
an error_mc_parse label, ensuring that cleanup functions are invoked
and the unnecessary mutex lock is removed.

Signed-off-by: Biren Pandya <birenpandya@gmail.com>
---
 .../media/platform/renesas/rzg2l-cru/rzg2l-core.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c
index 3c5fbd857371c..ee555b01c3aa1 100644
--- a/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c
+++ b/drivers/media/platform/renesas/rzg2l-cru/rzg2l-core.c
@@ -230,13 +230,17 @@ static int rzg2l_cru_media_init(struct rzg2l_cru_dev *cru)
 	media_device_init(mdev);
 
 	ret = rzg2l_cru_mc_parse_of_graph(cru);
-	if (ret) {
-		mutex_lock(&cru->mdev_lock);
-		cru->v4l2_dev.mdev = NULL;
-		mutex_unlock(&cru->mdev_lock);
-	}
+	if (ret)
+		goto error_mc_parse;
 
 	return 0;
+
+error_mc_parse:
+	media_device_cleanup(mdev);
+	cru->v4l2_dev.mdev = NULL;
+	media_entity_cleanup(&cru->vdev.entity);
+	mutex_destroy(&cru->mdev_lock);
+	return ret;
 }
 
 static int rzg2l_cru_probe(struct platform_device *pdev)
@@ -312,6 +316,7 @@ static void rzg2l_cru_remove(struct platform_device *pdev)
 	v4l2_async_nf_cleanup(&cru->notifier);
 
 	rzg2l_cru_video_unregister(cru);
+	media_entity_cleanup(&cru->vdev.entity);
 	media_device_cleanup(&cru->mdev);
 	mutex_destroy(&cru->mdev_lock);
 
-- 
2.50.1 (Apple Git-155)


      parent reply	other threads:[~2026-07-09  9:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260709091813.67081-6-birenpandya@gmail.com>
2026-07-09  9:18 ` [PATCH v6 1/4] media: renesas: rcar-csi2: Add missing media_entity_cleanup() Biren Pandya
2026-07-09  9:18 ` [PATCH v6 2/4] media: renesas: csisp: " Biren Pandya
2026-07-09  9:18 ` [PATCH v6 3/4] media: renesas: rcar-core: " Biren Pandya
2026-07-09  9:18 ` Biren Pandya [this message]

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=20260709091813.67081-10-birenpandya@gmail.com \
    --to=birenpandya@gmail.com \
    --cc=jacopo.mondi+renesas@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@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