All of lore.kernel.org
 help / color / mirror / Atom feed
From: Myeonghun Pak <mhun512@gmail.com>
To: linux-media@vger.kernel.org
Cc: ehristev@kernel.org, mchehab@kernel.org,
	linux-kernel@vger.kernel.org, Myeonghun Pak <mhun512@gmail.com>,
	Ijae Kim <ae878000@gmail.com>
Subject: [PATCH] media: microchip-csi2dc: Power off on probe failure and remove
Date: Thu, 10 Sep 2026 18:48:37 -0400	[thread overview]
Message-ID: <20260910224837.15554-1-mhun512@gmail.com> (raw)

csi2dc_probe() leaves runtime PM enabled and the controller powered on
if subdevice registration fails. Removal also leaves an active controller
powered on, since pm_runtime_disable() does not suspend it.

Disable runtime PM and power off the controller on both paths, then mark
it suspended. Check pm_runtime_status_suspended() after disabling runtime
PM to avoid turning off clocks that runtime suspend has already disabled.

This issue was identified during our ongoing static-analysis research while
reviewing kernel code.

Fixes: 2de0b3c0f678 ("media: atmel: introduce microchip csi2dc driver")
Co-developed-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
 drivers/media/platform/microchip/microchip-csi2dc.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/microchip/microchip-csi2dc.c b/drivers/media/platform/microchip/microchip-csi2dc.c
index e69292f3b2a909be6a044db6ad086a7b0e082802..56cccb02bc562febe5e6a36e69a9ae014e005ccc 100644
--- a/drivers/media/platform/microchip/microchip-csi2dc.c
+++ b/drivers/media/platform/microchip/microchip-csi2dc.c
@@ -727,13 +727,18 @@ static int csi2dc_probe(struct platform_device *pdev)
 	ret = v4l2_async_register_subdev(&csi2dc->csi2dc_sd);
 	if (ret) {
 		dev_err(csi2dc->dev, "failed to register the subdevice\n");
-		goto csi2dc_probe_cleanup_notifier;
+		goto csi2dc_probe_disable_pm;
 	}
 
 	dev_info(dev, "Microchip CSI2DC version %x\n", ver);
 
 	return 0;
 
+csi2dc_probe_disable_pm:
+	pm_runtime_disable(dev);
+	if (!pm_runtime_status_suspended(dev))
+		csi2dc_power(csi2dc, false);
+	pm_runtime_set_suspended(dev);
 csi2dc_probe_cleanup_notifier:
 	v4l2_async_nf_cleanup(&csi2dc->notifier);
 csi2dc_probe_cleanup_entity:
@@ -746,12 +751,15 @@ static void csi2dc_remove(struct platform_device *pdev)
 {
 	struct csi2dc_device *csi2dc = platform_get_drvdata(pdev);
 
-	pm_runtime_disable(&pdev->dev);
-
 	v4l2_async_unregister_subdev(&csi2dc->csi2dc_sd);
 	v4l2_async_nf_unregister(&csi2dc->notifier);
 	v4l2_async_nf_cleanup(&csi2dc->notifier);
 	media_entity_cleanup(&csi2dc->csi2dc_sd.entity);
+
+	pm_runtime_disable(&pdev->dev);
+	if (!pm_runtime_status_suspended(&pdev->dev))
+		csi2dc_power(csi2dc, false);
+	pm_runtime_set_suspended(&pdev->dev);
 }
 
 static int __maybe_unused csi2dc_runtime_suspend(struct device *dev)

base-commit: 50d05c7c76c96b90462f24debacca971d2e86713
-- 
2.47.1

             reply	other threads:[~2026-09-10 22:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 22:48 Myeonghun Pak [this message]
2026-09-26 13:16 ` [PATCH] media: microchip-csi2dc: Power off on probe failure and remove Eugen Hristev

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=20260910224837.15554-1-mhun512@gmail.com \
    --to=mhun512@gmail.com \
    --cc=ae878000@gmail.com \
    --cc=ehristev@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.