mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] media: amphion: handle runtime resume failures
@ 2026-10-19  8:27 Jiale Yao
  2026-10-19  8:27 ` [PATCH 1/2] media: amphion: handle core " Jiale Yao
  2026-10-19  8:27 ` [PATCH 2/2] media: amphion: handle debug runtime resume failure Jiale Yao
  0 siblings, 2 replies; 7+ messages in thread
From: Jiale Yao @ 2026-10-19  8:27 UTC (permalink / raw)
  To: Ming Qian, Zhou Peng, Mauro Carvalho Chehab, linux-media, linux-kernel
  Cc: Jiale Yao

The Amphion core request, resume, and debugfs write paths assume that
pm_runtime_resume_and_get() always succeeds. If runtime resume fails,
these paths access VPU state or hardware while the device is unavailable
and later drop a runtime PM reference that was not acquired.

Check the resume result before taking the dependent path. The core patch
unwinds its lock and avoids VPU access, while the debugfs write handler
returns the error before accessing the core.

Jiale Yao (2):
  media: amphion: handle core runtime resume failures
  media: amphion: handle debug runtime resume failure

 drivers/media/platform/amphion/vpu_core.c | 13 +++++++++++--
 drivers/media/platform/amphion/vpu_dbg.c  |  6 +++++-
 2 files changed, 16 insertions(+), 3 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] media: amphion: handle core runtime resume failures
  2026-10-19  8:27 [PATCH 0/2] media: amphion: handle runtime resume failures Jiale Yao
@ 2026-10-19  8:27 ` Jiale Yao
  2026-10-19  8:31   ` jiale yao
  2026-10-19  9:54   ` [PATCH " Ming Qian(OSS)
  2026-10-19  8:27 ` [PATCH 2/2] media: amphion: handle debug runtime resume failure Jiale Yao
  1 sibling, 2 replies; 7+ messages in thread
From: Jiale Yao @ 2026-10-19  8:27 UTC (permalink / raw)
  To: Ming Qian, Zhou Peng, Mauro Carvalho Chehab, linux-media, linux-kernel
  Cc: Jiale Yao

The core request and resume paths continue with VPU state and hardware
access after pm_runtime_resume_and_get() fails. A failed runtime resume
leaves the device unavailable, so those accesses can fail and the later
runtime PM put does not match an acquired reference.

Check the runtime resume result before accessing the VPU. Release the
core lock and return without touching the hardware when resume fails.

Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
 drivers/media/platform/amphion/vpu_core.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/amphion/vpu_core.c b/drivers/media/platform/amphion/vpu_core.c
index ad54f014d8..3d71442807 100644
--- a/drivers/media/platform/amphion/vpu_core.c
+++ b/drivers/media/platform/amphion/vpu_core.c
@@ -372,7 +372,12 @@ struct vpu_core *vpu_request_core(struct vpu_dev *vpu, enum vpu_core_type type)
 		goto exit;
 
 	mutex_lock(&core->lock);
-	pm_runtime_resume_and_get(core->dev);
+	ret = pm_runtime_resume_and_get(core->dev);
+	if (ret < 0) {
+		mutex_unlock(&core->lock);
+		core = NULL;
+		goto exit;
+	}
 
 	if (core->state == VPU_CORE_DEINIT) {
 		if (vpu_iface_get_power_state(core))
@@ -760,7 +765,11 @@ static int __maybe_unused vpu_core_resume(struct device *dev)
 	int ret = 0;
 
 	mutex_lock(&core->lock);
-	pm_runtime_resume_and_get(dev);
+	ret = pm_runtime_resume_and_get(dev);
+	if (ret < 0) {
+		mutex_unlock(&core->lock);
+		return ret;
+	}
 	vpu_core_get_vpu(core);
 
 	if (core->request_count) {
-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/2] media: amphion: handle debug runtime resume failure
  2026-10-19  8:27 [PATCH 0/2] media: amphion: handle runtime resume failures Jiale Yao
  2026-10-19  8:27 ` [PATCH 1/2] media: amphion: handle core " Jiale Yao
@ 2026-10-19  8:27 ` Jiale Yao
  2026-10-19  8:31   ` jiale yao
  2026-10-19  9:58   ` [PATCH " Ming Qian(OSS)
  1 sibling, 2 replies; 7+ messages in thread
From: Jiale Yao @ 2026-10-19  8:27 UTC (permalink / raw)
  To: Ming Qian, Zhou Peng, Mauro Carvalho Chehab, linux-media, linux-kernel
  Cc: Jiale Yao

The debugfs core write handler reads the VPU power state after
pm_runtime_resume_and_get() fails. The device may be unavailable after
a failed runtime resume, and the final runtime PM put does not match an
acquired reference.

Return the resume error before taking the core lock or accessing VPU
hardware.

Signed-off-by: Jiale Yao <yaojiale02@163.com>
---
 drivers/media/platform/amphion/vpu_dbg.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/amphion/vpu_dbg.c b/drivers/media/platform/amphion/vpu_dbg.c
index 497ae4e8a2..fff4df4f45 100644
--- a/drivers/media/platform/amphion/vpu_dbg.c
+++ b/drivers/media/platform/amphion/vpu_dbg.c
@@ -382,8 +382,12 @@ static ssize_t vpu_dbg_core_write(struct file *file,
 {
 	struct seq_file *s = file->private_data;
 	struct vpu_core *core = s->private;
+	int ret;
+
+	ret = pm_runtime_resume_and_get(core->dev);
+	if (ret < 0)
+		return ret;
 
-	pm_runtime_resume_and_get(core->dev);
 	mutex_lock(&core->lock);
 	if (vpu_iface_get_power_state(core) && !core->request_count) {
 		dev_info(core->dev, "reset\n");
-- 
2.34.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re:[PATCH 1/2] media: amphion: handle core runtime resume failures
  2026-10-19  8:27 ` [PATCH 1/2] media: amphion: handle core " Jiale Yao
@ 2026-10-19  8:31   ` jiale yao
  2026-10-19  9:54   ` [PATCH " Ming Qian(OSS)
  1 sibling, 0 replies; 7+ messages in thread
From: jiale yao @ 2026-10-19  8:31 UTC (permalink / raw)
  To: Ming Qian, Zhou Peng, Mauro Carvalho Chehab, linux-media, linux-kernel

At 2026-10-19 16:27:53, "Jiale Yao" <yaojiale02@163.com> wrote:
>The core request and resume paths continue with VPU state and hardware
>access after pm_runtime_resume_and_get() fails. A failed runtime resume
>leaves the device unavailable, so those accesses can fail and the later
>runtime PM put does not match an acquired reference.
>
>Check the runtime resume result before accessing the VPU. Release the
>core lock and return without touching the hardware when resume fails.
>

Fixes: f445014a2291 ("media: amphion: fix an issue that using pm_runtime_get_sync incorrectly")

>Signed-off-by: Jiale Yao <yaojiale02@163.com>
>---
> drivers/media/platform/amphion/vpu_core.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
>diff --git a/drivers/media/platform/amphion/vpu_core.c b/drivers/media/platform/amphion/vpu_core.c
>index ad54f014d8..3d71442807 100644
>--- a/drivers/media/platform/amphion/vpu_core.c
>+++ b/drivers/media/platform/amphion/vpu_core.c
>@@ -372,7 +372,12 @@ struct vpu_core *vpu_request_core(struct vpu_dev *vpu, enum vpu_core_type type)
> 		goto exit;
> 
> 	mutex_lock(&core->lock);
>-	pm_runtime_resume_and_get(core->dev);
>+	ret = pm_runtime_resume_and_get(core->dev);
>+	if (ret < 0) {
>+		mutex_unlock(&core->lock);
>+		core = NULL;
>+		goto exit;
>+	}
> 
> 	if (core->state == VPU_CORE_DEINIT) {
> 		if (vpu_iface_get_power_state(core))
>@@ -760,7 +765,11 @@ static int __maybe_unused vpu_core_resume(struct device *dev)
> 	int ret = 0;
> 
> 	mutex_lock(&core->lock);
>-	pm_runtime_resume_and_get(dev);
>+	ret = pm_runtime_resume_and_get(dev);
>+	if (ret < 0) {
>+		mutex_unlock(&core->lock);
>+		return ret;
>+	}
> 	vpu_core_get_vpu(core);
> 
> 	if (core->request_count) {
>-- 
>2.34.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re:[PATCH 2/2] media: amphion: handle debug runtime resume failure
  2026-10-19  8:27 ` [PATCH 2/2] media: amphion: handle debug runtime resume failure Jiale Yao
@ 2026-10-19  8:31   ` jiale yao
  2026-10-19  9:58   ` [PATCH " Ming Qian(OSS)
  1 sibling, 0 replies; 7+ messages in thread
From: jiale yao @ 2026-10-19  8:31 UTC (permalink / raw)
  To: Ming Qian, Zhou Peng, Mauro Carvalho Chehab, linux-media, linux-kernel

At 2026-10-19 16:27:54, "Jiale Yao" <yaojiale02@163.com> wrote:
>The debugfs core write handler reads the VPU power state after
>pm_runtime_resume_and_get() fails. The device may be unavailable after
>a failed runtime resume, and the final runtime PM put does not match an
>acquired reference.
>
>Return the resume error before taking the core lock or accessing VPU
>hardware.
>

Fixes: f445014a2291 ("media: amphion: fix an issue that using pm_runtime_get_sync incorrectly")

>Signed-off-by: Jiale Yao <yaojiale02@163.com>
>---
> drivers/media/platform/amphion/vpu_dbg.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/media/platform/amphion/vpu_dbg.c b/drivers/media/platform/amphion/vpu_dbg.c
>index 497ae4e8a2..fff4df4f45 100644
>--- a/drivers/media/platform/amphion/vpu_dbg.c
>+++ b/drivers/media/platform/amphion/vpu_dbg.c
>@@ -382,8 +382,12 @@ static ssize_t vpu_dbg_core_write(struct file *file,
> {
> 	struct seq_file *s = file->private_data;
> 	struct vpu_core *core = s->private;
>+	int ret;
>+
>+	ret = pm_runtime_resume_and_get(core->dev);
>+	if (ret < 0)
>+		return ret;
> 
>-	pm_runtime_resume_and_get(core->dev);
> 	mutex_lock(&core->lock);
> 	if (vpu_iface_get_power_state(core) && !core->request_count) {
> 		dev_info(core->dev, "reset\n");
>-- 
>2.34.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] media: amphion: handle core runtime resume failures
  2026-10-19  8:27 ` [PATCH 1/2] media: amphion: handle core " Jiale Yao
  2026-10-19  8:31   ` jiale yao
@ 2026-10-19  9:54   ` Ming Qian(OSS)
  1 sibling, 0 replies; 7+ messages in thread
From: Ming Qian(OSS) @ 2026-10-19  9:54 UTC (permalink / raw)
  To: Jiale Yao, Ming Qian, Zhou Peng, Mauro Carvalho Chehab,
	linux-media, linux-kernel



On 10/19/2026 4:27 PM, Jiale Yao wrote:
> The core request and resume paths continue with VPU state and hardware
> access after pm_runtime_resume_and_get() fails. A failed runtime resume
> leaves the device unavailable, so those accesses can fail and the later
> runtime PM put does not match an acquired reference.
> 
> Check the runtime resume result before accessing the VPU. Release the
> core lock and return without touching the hardware when resume fails.
> 
> Signed-off-by: Jiale Yao <yaojiale02@163.com>

Reviewed-by: Ming Qian <ming.qian@oss.nxp.com>

> ---
>   drivers/media/platform/amphion/vpu_core.c | 13 +++++++++++--
>   1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/amphion/vpu_core.c b/drivers/media/platform/amphion/vpu_core.c
> index ad54f014d8..3d71442807 100644
> --- a/drivers/media/platform/amphion/vpu_core.c
> +++ b/drivers/media/platform/amphion/vpu_core.c
> @@ -372,7 +372,12 @@ struct vpu_core *vpu_request_core(struct vpu_dev *vpu, enum vpu_core_type type)
>   		goto exit;
>   
>   	mutex_lock(&core->lock);
> -	pm_runtime_resume_and_get(core->dev);
> +	ret = pm_runtime_resume_and_get(core->dev);
> +	if (ret < 0) {
> +		mutex_unlock(&core->lock);
> +		core = NULL;
> +		goto exit;
> +	}
>   
>   	if (core->state == VPU_CORE_DEINIT) {
>   		if (vpu_iface_get_power_state(core))
> @@ -760,7 +765,11 @@ static int __maybe_unused vpu_core_resume(struct device *dev)
>   	int ret = 0;
>   
>   	mutex_lock(&core->lock);
> -	pm_runtime_resume_and_get(dev);
> +	ret = pm_runtime_resume_and_get(dev);
> +	if (ret < 0) {
> +		mutex_unlock(&core->lock);
> +		return ret;
> +	}
>   	vpu_core_get_vpu(core);
>   
>   	if (core->request_count) {


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] media: amphion: handle debug runtime resume failure
  2026-10-19  8:27 ` [PATCH 2/2] media: amphion: handle debug runtime resume failure Jiale Yao
  2026-10-19  8:31   ` jiale yao
@ 2026-10-19  9:58   ` Ming Qian(OSS)
  1 sibling, 0 replies; 7+ messages in thread
From: Ming Qian(OSS) @ 2026-10-19  9:58 UTC (permalink / raw)
  To: Jiale Yao, Ming Qian, Zhou Peng, Mauro Carvalho Chehab,
	linux-media, linux-kernel



On 10/19/2026 4:27 PM, Jiale Yao wrote:
> The debugfs core write handler reads the VPU power state after
> pm_runtime_resume_and_get() fails. The device may be unavailable after
> a failed runtime resume, and the final runtime PM put does not match an
> acquired reference.
> 
> Return the resume error before taking the core lock or accessing VPU
> hardware.
> 
> Signed-off-by: Jiale Yao <yaojiale02@163.com>

Reviewed-by: Ming Qian <ming.qian@oss.nxp.com>

> ---
>   drivers/media/platform/amphion/vpu_dbg.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/media/platform/amphion/vpu_dbg.c b/drivers/media/platform/amphion/vpu_dbg.c
> index 497ae4e8a2..fff4df4f45 100644
> --- a/drivers/media/platform/amphion/vpu_dbg.c
> +++ b/drivers/media/platform/amphion/vpu_dbg.c
> @@ -382,8 +382,12 @@ static ssize_t vpu_dbg_core_write(struct file *file,
>   {
>   	struct seq_file *s = file->private_data;
>   	struct vpu_core *core = s->private;
> +	int ret;
> +
> +	ret = pm_runtime_resume_and_get(core->dev);
> +	if (ret < 0)
> +		return ret;
>   
> -	pm_runtime_resume_and_get(core->dev);
>   	mutex_lock(&core->lock);
>   	if (vpu_iface_get_power_state(core) && !core->request_count) {
>   		dev_info(core->dev, "reset\n");


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-10-19  9:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-19  8:27 [PATCH 0/2] media: amphion: handle runtime resume failures Jiale Yao
2026-10-19  8:27 ` [PATCH 1/2] media: amphion: handle core " Jiale Yao
2026-10-19  8:31   ` jiale yao
2026-10-19  9:54   ` [PATCH " Ming Qian(OSS)
2026-10-19  8:27 ` [PATCH 2/2] media: amphion: handle debug runtime resume failure Jiale Yao
2026-10-19  8:31   ` jiale yao
2026-10-19  9:58   ` [PATCH " Ming Qian(OSS)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®