mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: drx39xyj: use u64 for VSB BER values
@ 2026-10-22 17:23 Ilya Krutskih
  0 siblings, 0 replies; only message in thread
From: Ilya Krutskih @ 2026-10-22 17:23 UTC (permalink / raw)
  To: Mauro Carvalho Chehab
  Cc: Ilya Krutskih, lvc-project, Liao Yuanhong, Kees Cook,
	Hans Verkuil, linux-media, linux-kernel

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-10-22 17:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-22 17:23 [PATCH] media: drx39xyj: use u64 for VSB BER values Ilya Krutskih

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®