[PATCH 4/5] media: staging: cedrus: h265: fail the job when the bit reader times out

From: Arun Iyengar via B4 Relay

Date: Tue Dec 01 2026 - 10:27:27 EST


From: Arun Iyengar <aiyengar1990@xxxxxxxxx>

>From Dmitry Osipenko's v1 [1], as Jernej asked [2].

cedrus_h265_skip_bits() logs a timeout and goes on, and
cedrus_h265_show_bits() ignores it, so the slice is set up from a wrong
position. Return -ETIMEDOUT from both and fail the job.

Fixes: 91db7a3fc7fe ("media: cedrus: Fix endless loop in cedrus_h265_skip_bits()")
Fixes: e9120e76a6f7 ("media: cedrus: hevc: Fix offset adjustments")
Cc: stable@xxxxxxxxxxxxxxx
Link: https://lore.kernel.org/all/20220914150105.209484-1-dmitry.osipenko@xxxxxxxxxxxxx/ [1]
Link: https://lore.kernel.org/all/1733932.VLH7GnMWUR@kista/ [2]
Suggested-by: Jernej Skrabec <jernej.skrabec@xxxxxxxxx>
Co-developed-by: Dmitry Osipenko <dmitry.osipenko@xxxxxxxxxxxxx>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@xxxxxxxxxxxxx>
Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>
---
drivers/staging/media/sunxi/cedrus/cedrus_h265.c | 37 ++++++++++++++++++------
1 file changed, 28 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
index 44539936b550..a00d7bc705c3 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_h265.c
@@ -237,7 +237,7 @@ static void cedrus_h265_pred_weight_write(struct cedrus_dev *dev,
}
}

-static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num)
+static int cedrus_h265_skip_bits(struct cedrus_dev *dev, int num)
{
int count = 0;

@@ -248,23 +248,32 @@ static void cedrus_h265_skip_bits(struct cedrus_dev *dev, int num)
VE_DEC_H265_TRIGGER_FLUSH_BITS |
VE_DEC_H265_TRIGGER_TYPE_N_BITS(tmp));

- if (cedrus_wait_for(dev, VE_DEC_H265_STATUS, VE_DEC_H265_STATUS_VLD_BUSY))
+ if (cedrus_wait_for(dev, VE_DEC_H265_STATUS, VE_DEC_H265_STATUS_VLD_BUSY)) {
dev_err_ratelimited(dev->dev, "timed out waiting to skip bits\n");
+ return -ETIMEDOUT;
+ }

count += tmp;
}
+
+ return 0;
}

-static u32 cedrus_h265_show_bits(struct cedrus_dev *dev, int num)
+static int cedrus_h265_show_bits(struct cedrus_dev *dev, int num, u32 *val)
{
cedrus_write(dev, VE_DEC_H265_TRIGGER,
VE_DEC_H265_TRIGGER_SHOW_BITS |
VE_DEC_H265_TRIGGER_TYPE_N_BITS(num));

- cedrus_wait_for(dev, VE_DEC_H265_STATUS,
- VE_DEC_H265_STATUS_VLD_BUSY);
+ if (cedrus_wait_for(dev, VE_DEC_H265_STATUS,
+ VE_DEC_H265_STATUS_VLD_BUSY)) {
+ dev_err_ratelimited(dev->dev, "timed out waiting to show bits\n");
+ return -ETIMEDOUT;
+ }

- return cedrus_read(dev, VE_DEC_H265_BITS_READ);
+ *val = cedrus_read(dev, VE_DEC_H265_BITS_READ);
+
+ return 0;
}

static void cedrus_h265_write_scaling_list(struct cedrus_ctx *ctx,
@@ -433,8 +442,10 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
u32 pic_order_cnt[2];
size_t slice_bytes;
u8 padding;
+ u32 bits;
int count;
u32 reg;
+ int ret;

sps = run->h265.sps;
pps = run->h265.pps;
@@ -546,9 +557,15 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
if (slice_params->data_byte_offset == 0)
return -EOPNOTSUPP;

- cedrus_h265_skip_bits(dev, (slice_params->data_byte_offset - 1) * 8);
+ ret = cedrus_h265_skip_bits(dev, (slice_params->data_byte_offset - 1) * 8);
+ if (ret)
+ return ret;
+
+ ret = cedrus_h265_show_bits(dev, 8, &bits);
+ if (ret)
+ return ret;

- padding = cedrus_h265_show_bits(dev, 8);
+ padding = bits;

/* at least one bit must be set in that byte */
if (padding == 0)
@@ -561,7 +578,9 @@ static int cedrus_h265_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
/* Include the one bit. */
count++;

- cedrus_h265_skip_bits(dev, 8 - count);
+ ret = cedrus_h265_skip_bits(dev, 8 - count);
+ if (ret)
+ return ret;

/* Bitstream parameters. */


--
2.55.0