The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Xulin Sun <xulin.sun@windriver.com>
To: nas.chung@chipsnmedia.com, jackson.lee@chipsnmedia.com,
	mchehab@kernel.org
Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	xulin.sun@windriver.com
Subject: [PATCH 1/3] media: wave5: Fix PM runtime usage count underflow
Date: Wed,  3 Dec 2025 12:09:33 +0800	[thread overview]
Message-ID: <20251203040935.2685490-2-xulin.sun@windriver.com> (raw)
In-Reply-To: <20251203040935.2685490-1-xulin.sun@windriver.com>

Symptom:
  ------------[ cut here ]------------
  WARNING: CPU: 1 PID: 963 at kernel/kthread.c:1430 kthread_destroy_worker+0x84/0x98
  ...
  vdec 30210000.video-codec: Runtime PM usage count underflow!

Root cause:
  The driver calls pm_runtime_put_sync() unconditionally in remove, but
  the device may already be suspended due to autosuspend configured in
  probe. When autosuspend has already suspended the device, the usage
  count is 0, and pm_runtime_put_sync() decrements it to -1, causing
  the underflow warning.

Fix:
  Replace pm_runtime_put_sync() with pm_runtime_dont_use_autosuspend()
  which properly pairs with pm_runtime_use_autosuspend() from probe.
  This allows pm_runtime_disable() to handle reference count cleanup
  correctly regardless of current suspend state. The disable function
  internally handles the usage count properly without causing underflow.

Signed-off-by: Xulin Sun <xulin.sun@windriver.com>
---
 drivers/media/platform/chips-media/wave5/wave5-vpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu.c b/drivers/media/platform/chips-media/wave5/wave5-vpu.c
index e1715d3f43b0..23aa3ab51a0e 100644
--- a/drivers/media/platform/chips-media/wave5/wave5-vpu.c
+++ b/drivers/media/platform/chips-media/wave5/wave5-vpu.c
@@ -356,7 +356,7 @@ static void wave5_vpu_remove(struct platform_device *pdev)
 		hrtimer_cancel(&dev->hrtimer);
 	}
 
-	pm_runtime_put_sync(&pdev->dev);
+	pm_runtime_dont_use_autosuspend(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
 
 	mutex_destroy(&dev->dev_lock);
-- 
2.49.1


  reply	other threads:[~2025-12-03  4:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-03  4:09 [PATCH 0/3] media: wave5: Fix critical issues in driver remove path Xulin Sun
2025-12-03  4:09 ` Xulin Sun [this message]
2025-12-03  4:09 ` [PATCH 2/3] media: wave5: Fix kthread worker destruction in polling mode Xulin Sun
2025-12-03  4:09 ` [PATCH 3/3] media: wave5: Fix device cleanup order to prevent kernel panic Xulin Sun
2025-12-03 18:10 ` [PATCH 0/3] media: wave5: Fix critical issues in driver remove path Nicolas Dufresne

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=20251203040935.2685490-2-xulin.sun@windriver.com \
    --to=xulin.sun@windriver.com \
    --cc=jackson.lee@chipsnmedia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=nas.chung@chipsnmedia.com \
    /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