mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ilya Krutskih <devsec@tpz.ru>
To: Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Ilya Krutskih <devsec@tpz.ru>,
	lvc-project@linuxtesting.org,
	Liao Yuanhong <liaoyuanhong@vivo.com>,
	Kees Cook <kees@kernel.org>,
	Hans Verkuil <hverkuil+cisco@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] media: drx39xyj: use u64 for VSB BER values
Date: Thu, 22 Oct 2026 17:23:48 +0000	[thread overview]
Message-ID: <20261022172349.224694-1-devsec@tpz.ru> (raw)

The VSB post-Viterbi BER calculation can overflow its u32 result.

The FEC_RS_NR_BIT_ERRORS register contains a 12-bit mantissa and a
4-bit exponent, with ranges of 0..4095 and 0..15, respectively.
A mantissa of 4095 and an exponent of 15 satisfy the high-BER
condition: (4095 << 15) >> 3 = 16773120 > 68700

For every exponent greater than two, the driver calculates cnt as
FEC_RS_MEASUREMENT_PERIOD * FEC_RS_MEASUREMENT_PRESCALE * 207. The
constant period and prescale values are 12894 and 1, so cnt
is 2669058.

The high-BER path then calculates 924255 * 26570 = 24557455350,
which exceeds U32_MAX and wraps before reaching the DVB statistics
counter.

Store VSB BER values in u64 and promote cnt before multiplying it.
The statistics uvalue field is already u64, so it preserves the
complete result.

Fixes: 38b2df95c53b ("[media] drx-j: add a driver for Trident drx-j frontend")
Signed-off-by: Ilya Krutskih <devsec@tpz.ru>
---
 drivers/media/dvb-frontends/drx39xyj/drxj.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/media/dvb-frontends/drx39xyj/drxj.c b/drivers/media/dvb-frontends/drx39xyj/drxj.c
index 367acb59b4a3..a257ecc4f2e0 100644
--- a/drivers/media/dvb-frontends/drx39xyj/drxj.c
+++ b/drivers/media/dvb-frontends/drx39xyj/drxj.c
@@ -6245,7 +6245,7 @@ static int get_vsb_post_rs_pck_err(struct i2c_device_addr *dev_addr,
 * \return Error code
 */
 static int get_vs_bpost_viterbi_ber(struct i2c_device_addr *dev_addr,
-				    u32 *ber, u32 *cnt)
+				    u64 *ber, u32 *cnt)
 {
 	int rc;
 	u16 data = 0;
@@ -6269,7 +6269,7 @@ static int get_vs_bpost_viterbi_ber(struct i2c_device_addr *dev_addr,
 	*cnt = period * prescale * 207 * ((bit_errors_exp > 2) ? 1 : 8);
 
 	if (((bit_errors_mant << bit_errors_exp) >> 3) > 68700)
-		*ber = (*cnt) * 26570;
+		*ber = (u64)*cnt * 26570;
 	else {
 		if (period * prescale == 0) {
 			pr_err("error: period and/or prescale is zero!\n");
@@ -6290,7 +6290,7 @@ static int get_vs_bpost_viterbi_ber(struct i2c_device_addr *dev_addr,
 * \return Error code
 */
 static int get_vs_bpre_viterbi_ber(struct i2c_device_addr *dev_addr,
-				   u32 *ber, u32 *cnt)
+				   u64 *ber, u32 *cnt)
 {
 	u16 data = 0;
 	int rc;
@@ -10674,7 +10674,8 @@ ctrl_sig_quality(struct drx_demod_instance *demod,
 	struct dtv_frontend_properties *p = &state->frontend.dtv_property_cache;
 	enum drx_standard standard = ext_attr->standard;
 	int rc;
-	u32 ber, cnt, err, pkt;
+	u64 ber;
+	u32 cnt, err, pkt;
 	u16 mer, strength = 0;
 
 	rc = get_sig_strength(demod, &strength);
-- 
2.43.0


                 reply	other threads:[~2026-10-22 17:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261022172349.224694-1-devsec@tpz.ru \
    --to=devsec@tpz.ru \
    --cc=hverkuil+cisco@kernel.org \
    --cc=kees@kernel.org \
    --cc=liaoyuanhong@vivo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=mchehab@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

all inboxes | Powered by JetHome®