public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: patches@lists.linux.dev, stable@vger.kernel.org
Cc: Brandon Brnich <b-brnich@ti.com>,
	Nicolas Dufresne <nicolas.dufresne@collabora.com>,
	Hans Verkuil <hverkuil+cisco@kernel.org>,
	Sasha Levin <sashal@kernel.org>,
	nas.chung@chipsnmedia.com, jackson.lee@chipsnmedia.com,
	linux-media@vger.kernel.org
Subject: [PATCH AUTOSEL 6.19-6.12] media: chips-media: wave5: Fix conditional in start_streaming
Date: Fri, 13 Feb 2026 19:58:05 -0500	[thread overview]
Message-ID: <20260214010245.3671907-5-sashal@kernel.org> (raw)
In-Reply-To: <20260214010245.3671907-1-sashal@kernel.org>

From: Brandon Brnich <b-brnich@ti.com>

[ Upstream commit b4e26c6fc1b3c225caf80d4a95c6f9fcbe959e17 ]

When STREAMON(CAP) is called after STREAMON(OUT), the driver was failing to
switch states from VPU_INST_STATE_OPEN to VPU_INST_STATE_INIT_SEQ and
VPU_INST_STATE_PIC_RUN because the capture queue streaming boolean had not
yet been set to true. This led to a hang in the encoder since the state
was stuck in VPU_INST_STATE_OPEN. During the second call to
start_streaming, the sequence initialization and frame buffer allocation
should occur.

Signed-off-by: Brandon Brnich <b-brnich@ti.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:

This confirms the key finding. Now I have all the information needed for
a comprehensive analysis.

## Detailed Analysis

### 1. COMMIT MESSAGE ANALYSIS

The subject "Fix conditional in start_streaming" clearly indicates a
**bug fix**. The commit message explains:
- **Trigger**: When `STREAMON(CAPTURE)` is called after
  `STREAMON(OUTPUT)`, the encoder hangs.
- **Root cause**: The capture queue's `streaming` boolean hasn't been
  set to `true` yet at the time the condition is checked.
- **Symptom**: The VPU instance state gets stuck at
  `VPU_INST_STATE_OPEN`, never advancing to `VPU_INST_STATE_INIT_SEQ` or
  `VPU_INST_STATE_PIC_RUN`, causing the encoder to **hang**.

The commit has "Reviewed-by: Nicolas Dufresne" (Collabora engineer,
active V4L2 contributor) and was merged by Hans Verkuil (the V4L2
subsystem maintainer), indicating proper review.

### 2. CODE CHANGE ANALYSIS

The fix is a **one-line conditional change** (technically a 2-line
reformatting of a single condition):

**Before:**
```c
if (inst->state == VPU_INST_STATE_OPEN &&
m2m_ctx->cap_q_ctx.q.streaming) {
```

**After:**
```c
if (inst->state == VPU_INST_STATE_OPEN &&
    (m2m_ctx->cap_q_ctx.q.streaming || q->type ==
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) {
```

The logic bug is clear and verified by examining `vb2_core_streamon()`:

```2347:2353:drivers/media/common/videobuf2/videobuf2-core.c
        if (q->queued_count >= q->min_queued_buffers) {
                ret = vb2_start_streaming(q);
                if (ret)
                        goto unprepare;
        }

        q->streaming = 1;
```

The `q->streaming = 1` is set **AFTER** the driver's `start_streaming()`
callback returns. So inside `wave5_vpu_enc_start_streaming()`, when
called for the capture queue, `m2m_ctx->cap_q_ctx.q.streaming` is still
`0` because vb2 hasn't set it yet. This means the second `if` block (the
state transition from OPEN -> INIT_SEQ -> PIC_RUN) is **never entered**
when streaming is started in the normal OUT-then-CAP order.

The fix adds `q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE` as an
alternative condition: if we're currently inside `start_streaming` for
the capture queue, we know that capture streaming is about to become
active, so proceed with the state transition.

This is **identical** to how the decoder handles it — the decoder uses
`q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE` directly (line 1346 of
wave5-vpu-dec.c) rather than checking the streaming flag.

### 3. CLASSIFICATION

This is a clear **bug fix** that resolves a **system hang**. The encoder
gets stuck because its state machine never advances past
`VPU_INST_STATE_OPEN`. This is not a feature addition, refactoring, or
optimization.

### 4. SCOPE AND RISK ASSESSMENT

- **Lines changed**: 2 lines (one condition modified)
- **Files touched**: 1 file (`wave5-vpu-enc.c`)
- **Complexity**: Extremely low — a simple boolean condition expansion
- **Risk**: Very low. The added condition (`q->type ==
  V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE`) only evaluates to true when
  `start_streaming` is called for the capture queue, which is precisely
  when the streaming flag would be about to be set. This is logically
  sound and matches the decoder's approach.
- **Regression potential**: Near zero. The fix only adds a case that was
  previously unreachable (the dead path that caused the hang).

### 5. USER IMPACT

- **Who is affected**: Any user of the Wave5 VPU encoder (Chips&Media IP
  used in TI processors and other SoCs)
- **Severity**: **HIGH** — the encoder **hangs completely**. This isn't
  a minor issue; the hardware cannot encode video at all when STREAMON
  is called in the standard OUT-then-CAP order.
- **Real-world impact**: This affects all V4L2 applications using the
  standard video encoding flow (which is the normal way to use a V4L2
  M2M encoder).

### 6. STABILITY INDICATORS

- Reviewed by Nicolas Dufresne (Collabora V4L2 expert)
- Merged by Hans Verkuil (V4L2 subsystem maintainer)
- The fix follows the same pattern already used by the decoder
  (wave5-vpu-dec.c), so it's a well-understood pattern

### 7. DEPENDENCY CHECK

- **Self-contained**: Yes. The fix modifies a single condition with no
  dependencies on other commits.
- **Exists in stable**: The driver was added in v6.8 via commit
  `9707a6254a8a6`. It exists in stable trees 6.8.y through 6.18.y (plus
  the active LTS tree 6.12.y).
- **The bug has existed since the driver was added** (commit
  `9707a6254a8a6`), meaning all stable trees with this driver have the
  bug.
- **Clean apply**: The surrounding code is essentially identical in
  6.12.y, 6.15.y, and 6.16.y (minor differences in pm_runtime calls that
  don't affect the patch context).

### 8. SUMMARY

This is a textbook stable backport candidate:
- **Fixes a real, user-visible bug**: encoder hangs completely
- **Small, surgical fix**: 2-line conditional change in one file
- **Obviously correct**: matches the decoder's existing pattern,
  reviewed by V4L2 experts
- **No new features**: just fixes the broken state machine transition
- **Low regression risk**: only enables a previously dead code path that
  was always supposed to be reachable
- **Affects real users**: anyone using the Wave5 encoder for video
  encoding on TI SoCs
- **Self-contained**: no dependencies on other commits

**YES**

 drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c
index 9bfaa9fb3ceb3..bca881a0a1617 100644
--- a/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c
+++ b/drivers/media/platform/chips-media/wave5/wave5-vpu-enc.c
@@ -1367,7 +1367,8 @@ static int wave5_vpu_enc_start_streaming(struct vb2_queue *q, unsigned int count
 		if (ret)
 			goto return_buffers;
 	}
-	if (inst->state == VPU_INST_STATE_OPEN && m2m_ctx->cap_q_ctx.q.streaming) {
+	if (inst->state == VPU_INST_STATE_OPEN &&
+	    (m2m_ctx->cap_q_ctx.q.streaming || q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE)) {
 		ret = initialize_sequence(inst);
 		if (ret) {
 			dev_warn(inst->dev->dev, "Sequence not found: %d\n", ret);
-- 
2.51.0


  reply	other threads:[~2026-02-14  1:02 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-14  0:58 [PATCH AUTOSEL 6.19-6.12] media: ipu6: Close firmware streams on streaming enable failure Sasha Levin
2026-02-14  0:58 ` Sasha Levin [this message]
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-6.12] media: mt9m114: Avoid a reset low spike during probe() Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-6.1] media: amphion: Clear last_buffer_dequeued flag for DEC_CMD_START Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-5.10] media: adv7180: fix frame interval in progressive mode Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-6.6] media: v4l2-async: Fix error handling on steps after finding a match Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-6.1] media: rkisp1: Fix filter mode register configuration Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-6.12] media: ipu6: Ensure stream_mutex is acquired when dealing with node list Sasha Levin
2026-02-14  0:58 ` [PATCH AUTOSEL 6.19-6.12] media: mt9m114: Return -EPROBE_DEFER if no endpoint is found Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-6.18] media: uvcvideo: Create an ID namespace for streaming output terminals Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-6.12] media: ipu6: Always close firmware stream Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-6.18] media: qcom: camss: Do not enable cpas fast ahb clock for SM8550 VFE lite Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-5.10] media: solo6x10: Check for out of bounds chip_id Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-6.18] drm/amdgpu: Refactor amdgpu_gem_va_ioctl for Handling Last Fence Update and Timeline Management v4 Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-6.12] media: chips-media: wave5: Process ready frames when CMD_STOP sent to Encoder Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-5.10] media: pvrusb2: fix URB leak in pvr2_send_request_ex Sasha Levin
2026-02-14  0:59 ` [PATCH AUTOSEL 6.19-5.10] media: dvb-core: dmxdevfilter must always flush bufs Sasha Levin

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=20260214010245.3671907-5-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=b-brnich@ti.com \
    --cc=hverkuil+cisco@kernel.org \
    --cc=jackson.lee@chipsnmedia.com \
    --cc=linux-media@vger.kernel.org \
    --cc=nas.chung@chipsnmedia.com \
    --cc=nicolas.dufresne@collabora.com \
    --cc=patches@lists.linux.dev \
    --cc=stable@vger.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