Skip to content

Commit 18429c5

Browse files
Paul Zhangjmberg-intel
authored andcommitted
wifi: cfg80211: Fix bitrates overflow issue
When invoking function cfg80211_calculate_bitrate_eht about (320 MHz, EHT-MCS 13, EHT-NSS 2, EHT-GI 0), which means the parameters as flags: 0x80, bw: 7, mcs: 13, eht_gi: 0, nss: 2, this formula (result * rate->nss) will overflow and causes the returned bitrate to be 3959 when it should be 57646. Here is the explanation: u64 tmp; u32 result; … /* tmp = result = 4 * rates_996[0] * = 4 * 480388888 = 0x72889c60 */ tmp = result; /* tmp = 0x72889c60 * 6144 = 0xabccea90000 */ tmp *= SCALE; /* tmp = 0xabccea90000 / mcs_divisors[13] * = 0xabccea90000 / 5120 = 0x8970bba6 */ do_div(tmp, mcs_divisors[rate->mcs]); /* result = 0x8970bba6 */ result = tmp; /* normally (result * rate->nss) = 0x8970bba6 * 2 = 0x112e1774c, * but since result is u32, (result * rate->nss) = 0x12e1774c, * overflow happens and it loses the highest bit. * Then result = 0x12e1774c / 8 = 39595753, */ result = (result * rate->nss) / 8; Signed-off-by: Paul Zhang <quic_paulz@quicinc.com> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 57b962e commit 18429c5

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

net/wireless/util.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,10 +1557,12 @@ static u32 cfg80211_calculate_bitrate_eht(struct rate_info *rate)
15571557
tmp = result;
15581558
tmp *= SCALE;
15591559
do_div(tmp, mcs_divisors[rate->mcs]);
1560-
result = tmp;
15611560

15621561
/* and take NSS */
1563-
result = (result * rate->nss) / 8;
1562+
tmp *= rate->nss;
1563+
do_div(tmp, 8);
1564+
1565+
result = tmp;
15641566

15651567
return result / 10000;
15661568
}

0 commit comments

Comments
 (0)