All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arun Iyengar via B4 Relay <devnull+aiyengar1990.gmail.com@kernel.org>
To: Maxime Ripard <mripard@kernel.org>,
	 Paul Kocialkowski <paulk@sys-base.io>,
	 Mauro Carvalho Chehab <mchehab@kernel.org>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Chen-Yu Tsai <wens@kernel.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	 Samuel Holland <samuel@sholland.org>,
	Hans Verkuil <hverkuil@kernel.org>
Cc: linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
	 linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev,  linux-kernel@vger.kernel.org,
	Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>,
	 Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	 Dmitry Osipenko <dmitry.osipenko@collabora.com>,
	 Nicolas Dufresne <nicolas.dufresne@collabora.com>,
	stable@vger.kernel.org,  Arun Iyengar <aiyengar1990@gmail.com>
Subject: [PATCH 4/5] media: staging: cedrus: h265: fail the job when the bit reader times out
Date: Tue, 01 Dec 2026 15:27:00 +0000	[thread overview]
Message-ID: <20261201-b4-cedrus-bitreader-v1-4-678ded51faf1@gmail.com> (raw)
In-Reply-To: <20261201-b4-cedrus-bitreader-v1-0-678ded51faf1@gmail.com>

From: Arun Iyengar <aiyengar1990@gmail.com>

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@vger.kernel.org
Link: https://lore.kernel.org/all/20220914150105.209484-1-dmitry.osipenko@collabora.com/ [1]
Link: https://lore.kernel.org/all/1733932.VLH7GnMWUR@kista/ [2]
Suggested-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Co-developed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 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



WARNING: multiple messages have this Message-ID (diff)
From: Arun Iyengar <aiyengar1990@gmail.com>
To: Maxime Ripard <mripard@kernel.org>,
	 Paul Kocialkowski <paulk@sys-base.io>,
	 Mauro Carvalho Chehab <mchehab@kernel.org>,
	 Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	 Chen-Yu Tsai <wens@kernel.org>,
	Jernej Skrabec <jernej.skrabec@gmail.com>,
	 Samuel Holland <samuel@sholland.org>,
	Hans Verkuil <hverkuil@kernel.org>
Cc: linux-media@vger.kernel.org, linux-staging@lists.linux.dev,
	 linux-arm-kernel@lists.infradead.org,
	linux-sunxi@lists.linux.dev,  linux-kernel@vger.kernel.org,
	Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>,
	 Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	 Dmitry Osipenko <dmitry.osipenko@collabora.com>,
	 Nicolas Dufresne <nicolas.dufresne@collabora.com>,
	stable@vger.kernel.org,  Arun Iyengar <aiyengar1990@gmail.com>
Subject: [PATCH 4/5] media: staging: cedrus: h265: fail the job when the bit reader times out
Date: Tue, 01 Dec 2026 15:27:00 +0000	[thread overview]
Message-ID: <20261201-b4-cedrus-bitreader-v1-4-678ded51faf1@gmail.com> (raw)
In-Reply-To: <20261201-b4-cedrus-bitreader-v1-0-678ded51faf1@gmail.com>

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@vger.kernel.org
Link: https://lore.kernel.org/all/20220914150105.209484-1-dmitry.osipenko@collabora.com/ [1]
Link: https://lore.kernel.org/all/1733932.VLH7GnMWUR@kista/ [2]
Suggested-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Co-developed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Arun Iyengar <aiyengar1990@gmail.com>
---
 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


  parent reply	other threads:[~2026-12-01 15:27 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 15:26 [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup Arun Iyengar via B4 Relay
2026-12-01 15:26 ` Arun Iyengar
2026-12-01 15:26 ` [PATCH 1/5] media: staging: cedrus: h264: bound the wait for the bit skip Arun Iyengar via B4 Relay
2026-12-01 15:26   ` Arun Iyengar
2026-12-01 15:26 ` [PATCH 2/5] media: staging: cedrus: h264: reject a slice header larger than the slice Arun Iyengar via B4 Relay
2026-12-01 15:26   ` Arun Iyengar
2026-12-01 15:26 ` [PATCH 3/5] media: staging: cedrus: h265: reject a slice data offset past " Arun Iyengar via B4 Relay
2026-12-01 15:26   ` Arun Iyengar
2026-12-01 15:27 ` Arun Iyengar via B4 Relay [this message]
2026-12-01 15:27   ` [PATCH 4/5] media: staging: cedrus: h265: fail the job when the bit reader times out Arun Iyengar
2026-12-01 15:33   ` sashiko-bot
2026-12-01 15:27 ` [PATCH 5/5] media: staging: cedrus: vp8: fail the job on a bit reader timeout Arun Iyengar via B4 Relay
2026-12-01 15:27   ` Arun Iyengar
2026-12-01 15:40   ` sashiko-bot
2026-12-01 16:07 ` [PATCH 0/5] media: staging: cedrus: bound and check the bit reader setup Jernej Škrabec
2026-12-01 17:38   ` Arun Iyengar

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=20261201-b4-cedrus-bitreader-v1-4-678ded51faf1@gmail.com \
    --to=devnull+aiyengar1990.gmail.com@kernel.org \
    --cc=aiyengar1990@gmail.com \
    --cc=dmitry.osipenko@collabora.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=gregkh@linuxfoundation.org \
    --cc=hverkuil@kernel.org \
    --cc=jernej.skrabec@gmail.com \
    --cc=linkmauve@linkmauve.fr \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=mchehab@kernel.org \
    --cc=mripard@kernel.org \
    --cc=nicolas.dufresne@collabora.com \
    --cc=paulk@sys-base.io \
    --cc=samuel@sholland.org \
    --cc=stable@vger.kernel.org \
    --cc=wens@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.