From c070b5a6cf4eeef964f32fb8ea52dfb0dff6c1b5 Mon Sep 17 00:00:00 2001 From: Roy Date: Wed, 25 Nov 2026 23:02:29 +0800 Subject: [PATCH 1/2] media/hevc_d: Accept the unset default SPS in try_ctrl_sps The default value of the SPS control is all zeros, and a zero pic_width_in_luma_samples is how the driver marks the SPS as not yet set (is_sps_set()). try_ctrl_sps() rejects that value though, because chroma_format_idc is 0 and the picture is 0x0, so the control's own default cannot be written back. v4l2-compliance reads the control and passes the value to VIDIOC_TRY_EXT_CTRLS, which fails: fail: v4l2-test-controls.cpp(939): try_ext_ctrls returned an error (22) test VIDIOC_G/S/TRY_EXT_CTRLS: FAIL and every attempt also logs "Chroma format (0) unsupported". Upstream commit 4f4b6a9220f0 ("media: v4l2-ctrls: default HEVC SPS chroma format to 4:2:0") would not fix this on its own, as the 0x0 picture is still rejected. Giving the control a non-zero default size instead would make is_sps_set() true before userspace has set an SPS and change the CAPTURE format enumeration. Treat a zero width as unset and accept it without further checks. Decoding already refuses to start with "SPS never set", and the CAPTURE format code keeps offering all formats until a real SPS is set. Tested on a Pi 5 with 6.18.39 and this change built as an out-of-tree module: - v4l2-compliance -m /dev/media0: 56/57 -> 57/57 - a 4:2:2, 12-bit or 8192 wide SPS is still rejected - CAPTURE ENUM_FMT before an SPS is set is unchanged (4 formats) - ffmpeg -hwaccel drm decoding 8-bit and 10-bit 720p HEVC gives frame MD5s identical to software decoding, before and after the change The failure was found by running v4l2-compliance on a Pi 5. The analysis, the fix and this changelog were written with the help of an AI coding assistant (Claude), and the testing above was run on real hardware. Fixes: 6853a7e84e97 ("media: platform: Add Raspberry Pi HEVC decoder driver") Signed-off-by: Roy --- .../media/platform/raspberrypi/hevc_dec/hevc_d_h265.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c index e6a035e99ca46d..8f10ae8803113e 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c @@ -2412,6 +2412,15 @@ static int try_ctrl_sps(struct v4l2_ctrl *ctrl) const unsigned int max_tb_log2_size_y = min_tb_log2_size_y + sps->log2_diff_max_min_luma_transform_block_size; + /* + * A zero width is how the driver marks the SPS as not yet set (see + * is_sps_set()) and it is the control's default value. Accept it so + * the default can be read back and set again; decoding still refuses + * to start with it ("SPS never set"). + */ + if (!is_sps_set(sps)) + return 0; + if (sps->chroma_format_idc != 1) { v4l2_warn(&dev->v4l2_dev, "Chroma format (%d) unsupported\n", From dbe056f7c5c39f7b40f975c7649f7a0bd5d93fd5 Mon Sep 17 00:00:00 2001 From: Roy Date: Thu, 26 Nov 2026 00:16:19 +0800 Subject: [PATCH 2/2] media/hevc_d: Don't log rejected control values at warning level try_ctrl_sps(), try_ctrl_pps() and try_ctrl_slice_params() print a v4l2_warn() for every value they reject. Any user who can open the device can call VIDIOC_TRY_EXT_CTRLS in a loop and fill the kernel log. Use hevc_d_dbg() at level 1 instead, so the messages are still available with the debug module parameter. Tested on a Pi 5 (6.18.39, out-of-tree module), as a normal user in the video group, with 20000 VIDIOC_TRY_EXT_CTRLS calls using a 4:2:2 SPS, counting new kernel log records with the /dev/kmsg sequence number: - before: 20000 new log records - after: 0 new log records - after, with debug=1: 20000 new log records v4l2-compliance and 8-bit and 10-bit ffmpeg -hwaccel drm decoding give the same results as before. try_ctrl_slice_params() does not exist in the 6.18.39 driver, so its 3 messages were only build tested. Suggested by Dave Stevenson in the review of this pull request. The change and this changelog were written with the help of an AI coding assistant (Claude). Signed-off-by: Roy --- .../platform/raspberrypi/hevc_dec/hevc_d_h265.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c index 8f10ae8803113e..e2fe6edc0915be 100644 --- a/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c +++ b/drivers/media/platform/raspberrypi/hevc_dec/hevc_d_h265.c @@ -2422,7 +2422,7 @@ static int try_ctrl_sps(struct v4l2_ctrl *ctrl) return 0; if (sps->chroma_format_idc != 1) { - v4l2_warn(&dev->v4l2_dev, + hevc_d_dbg(1, &dev->v4l2_dev, "Chroma format (%d) unsupported\n", sps->chroma_format_idc); return -EINVAL; @@ -2430,14 +2430,14 @@ static int try_ctrl_sps(struct v4l2_ctrl *ctrl) if (sps->bit_depth_luma_minus8 != 0 && sps->bit_depth_luma_minus8 != 2) { - v4l2_warn(&dev->v4l2_dev, + hevc_d_dbg(1, &dev->v4l2_dev, "Luma depth (%d) unsupported\n", sps->bit_depth_luma_minus8 + 8); return -EINVAL; } if (sps->bit_depth_luma_minus8 != sps->bit_depth_chroma_minus8) { - v4l2_warn(&dev->v4l2_dev, + hevc_d_dbg(1, &dev->v4l2_dev, "Chroma depth (%d) != Luma depth (%d)\n", sps->bit_depth_chroma_minus8 + 8, sps->bit_depth_luma_minus8 + 8); @@ -2448,7 +2448,7 @@ static int try_ctrl_sps(struct v4l2_ctrl *ctrl) sps->pic_height_in_luma_samples < HEVC_D_MIN_HEIGHT || sps->pic_width_in_luma_samples > HEVC_D_MAX_WIDTH || sps->pic_height_in_luma_samples > HEVC_D_MAX_HEIGHT) { - v4l2_warn(&dev->v4l2_dev, + hevc_d_dbg(1, &dev->v4l2_dev, "Bad sps width (%u) x height (%u)\n", sps->pic_width_in_luma_samples, sps->pic_height_in_luma_samples); @@ -2497,7 +2497,7 @@ static int try_ctrl_pps(struct v4l2_ctrl *ctrl) V4L2_HEVC_PPS_FLAG_ENTROPY_CODING_SYNC_ENABLED) && (pps->flags & V4L2_HEVC_PPS_FLAG_TILES_ENABLED) && (pps->num_tile_columns_minus1 || pps->num_tile_rows_minus1)) { - v4l2_warn(&dev->v4l2_dev, + hevc_d_dbg(1, &dev->v4l2_dev, "WPP + Tiles not supported\n"); return -EINVAL; } @@ -2507,7 +2507,7 @@ static int try_ctrl_pps(struct v4l2_ctrl *ctrl) ARRAY_SIZE(pps->column_width_minus1) || pps->num_tile_rows_minus1 > ARRAY_SIZE(pps->row_height_minus1))) { - v4l2_warn(&dev->v4l2_dev, "Tiles cols/rows too big\n"); + hevc_d_dbg(1, &dev->v4l2_dev, "Tiles cols/rows too big\n"); return -EINVAL; } @@ -2533,7 +2533,7 @@ static int try_ctrl_slice_params(struct v4l2_ctrl *ctrl) * slice_segment_address for slice 0 */ if (sh->slice_segment_addr != 0) { - v4l2_warn(&dev->v4l2_dev, "New frame but segment_addr=%d\n", + hevc_d_dbg(1, &dev->v4l2_dev, "New frame but segment_addr=%d\n", sh->slice_segment_addr); return -EINVAL; } @@ -2542,7 +2542,7 @@ static int try_ctrl_slice_params(struct v4l2_ctrl *ctrl) if (sh->slice_type != HEVC_SLICE_B && sh->slice_type != HEVC_SLICE_P && sh->slice_type != HEVC_SLICE_I) { - v4l2_warn(&dev->v4l2_dev, + hevc_d_dbg(1, &dev->v4l2_dev, "Slice %u: bad slice type %u\n", i, sh->slice_type); return -EINVAL;