media: drx39xyj: use u64 for VSB BER values
PATCH 1/1 media: drx39xyj: use u64 for VSB BER values
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.
--- drivers/media/dvb-frontends/drx39xyj/drxj.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/media/dvb-frontends/drx39xyj/drxj.c +5 -4
@@ -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);
Signature · 1 line
2.43.0