[PATCH AUTOSEL 6.19-6.1] media: amphion: Clear last_buffer_dequeued flag for DEC_CMD_START

Sasha Levin
2026-02-14T01:03:04Z

From: Ming Qian <ming.qian@oss.nxp.com>

[ Upstream commit d85f3207d75df6d7a08be6526b15ff398668206c ]

The V4L2_DEC_CMD_START command may be used to handle the dynamic source
change, which will triggers an implicit decoder drain.
The last_buffer_dequeued flag is set in the implicit decoder drain,
so driver need to clear it to continue the following decoding flow.

Signed-off-by: Ming Qian <ming.qian@oss.nxp.com>
Reviewed-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---

LLM Generated explanations, may be completely bogus:

## Analysis of commit: "media: amphion: Clear last_buffer_dequeued flag
for DEC_CMD_START"

### 1. Commit Message Analysis

The commit message clearly describes a bug fix:
- When `V4L2_DEC_CMD_START` is used to handle dynamic source changes, an
implicit decoder drain is triggered
- The drain sets the `last_buffer_dequeued` flag
- This flag is never cleared, which **breaks the subsequent decoding
flow**
- The fix clears the flag when `DEC_CMD_START` is issued, allowing
decoding to continue

Keywords: "need to clear it to continue the following decoding flow" —
this indicates the decoder becomes stuck/non-functional without this
fix.

### 2. Code Change Analysis

The change is a **single line addition**:
```c
vb2_clear_last_buffer_dequeued(v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx));
```

This is added in the `V4L2_DEC_CMD_START` case of `vdec_decoder_cmd()`,
right after the existing `vdec_cmd_start(inst)` call.

**What the bug mechanism is:**
- `last_buffer_dequeued` is a flag in the vb2 (Video Buffer 2) queue
framework
- When set, it signals that the last buffer has been dequeued and no
more buffers will come
- During dynamic source change handling, an implicit drain sets this
flag
- Without clearing it on `DEC_CMD_START`, the capture queue thinks it's
done and won't deliver any more buffers
- This effectively **breaks video decoding** after a source change event

**The fix uses well-known V4L2 APIs:**
- `vb2_clear_last_buffer_dequeued()` — standard V4L2 helper function
- `v4l2_m2m_get_dst_vq()` — standard M2M helper to get the destination
(capture) queue

### 3. Classification

This is a **clear bug fix**. Without this patch, the amphion video
decoder becomes non-functional after handling a dynamic source change
event. The decoder gets stuck because the capture queue won't deliver
any more buffers.

### 4. Scope and Risk Assessment

- **Lines changed:** 1 line added
- **Files touched:** 1 file (`drivers/media/platform/amphion/vdec.c`)
- **Complexity:** Extremely low — calls a standard framework function
- **Risk of regression:** Very low — this is a targeted fix in a
specific command handler, using a well-established API
- **Subsystem:** Media/V4L2 driver for NXP amphion video decoder

### 5. User Impact

- **Who is affected:** Users of NXP i.MX8 SoCs (common in
embedded/industrial applications) that use the amphion video decoder
- **Severity:** The bug causes the video decoder to stop working after a
dynamic source change — this is a functional failure, not a minor
issue
- **Real-world scenario:** Dynamic source changes happen when video
stream parameters change mid-stream (resolution change, codec
reconfiguration). This is a normal operational scenario in media
playback.

### 6. Stability Indicators

- **Reviewed-by:** Nicolas Dufresne (Collabora, well-known V4L2
contributor)
- **Signed-off-by:** Hans Verkuil (V4L2 subsystem maintainer)
- The patch is obviously correct — it follows the same pattern used by
other V4L2 M2M drivers

### 7. Dependency Check

- The fix uses `vb2_clear_last_buffer_dequeued()` and
`v4l2_m2m_get_dst_vq()`, which are long-standing V4L2 framework
functions available in all stable trees that contain the amphion
driver
- No dependency on other patches — this is a self-contained one-line fix

### Summary

This is a textbook stable backport candidate:
- **Obviously correct:** Single line calling a standard API at the right
place
- **Fixes a real bug:** Decoder stops working after dynamic source
change
- **Small and contained:** 1 line, 1 file
- **No new features:** Just fixes existing functionality
- **Low risk:** Uses established framework API, reviewed by subsystem
maintainer
- **Real user impact:** Video decoding breaks without it

**YES**

drivers/media/platform/amphion/vdec.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/media/platform/amphion/vdec.c b/drivers/media/platform/amphion/vdec.c
index c0d2aabb9e0e3..f25dbcebdccf6 100644
--- a/drivers/media/platform/amphion/vdec.c
+++ b/drivers/media/platform/amphion/vdec.c
@@ -724,6 +724,7 @@ static int vdec_decoder_cmd(struct file *file, void *fh, struct v4l2_decoder_cmd
switch (cmd->cmd) {
case V4L2_DEC_CMD_START:
vdec_cmd_start(inst);
+ vb2_clear_last_buffer_dequeued(v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx));
break;
case V4L2_DEC_CMD_STOP:
vdec_cmd_stop(inst);
--
2.51.0