Skip to content

Commit a3034bf

Browse files
Veerendranath Jakkamjmberg-intel
authored andcommitted
wifi: cfg80211: Fix bitrate calculation overflow for HE rates
An integer overflow occurs in cfg80211_calculate_bitrate_he() when calculating bitrates for high throughput HE configurations. For example, with 160 MHz bandwidth, HE-MCS 13, HE-NSS 4, and HE-GI 0, the multiplication (result * rate->nss) overflows the 32-bit 'result' variable before division by 8, leading to significantly underestimated bitrate values. The overflow occurs because the NSS multiplication operates on a 32-bit integer that cannot accommodate intermediate values exceeding 4,294,967,295. When overflow happens, the value wraps around, producing incorrect bitrates for high MCS and NSS combinations. Fix this by utilizing the 64-bit 'tmp' variable for the NSS multiplication and subsequent divisions via do_div(). This approach preserves full precision throughout the entire calculation, with the final value assigned to 'result' only after completing all operations. Signed-off-by: Veerendranath Jakkam <veerendranath.jakkam@oss.qualcomm.com> Link: https://patch.msgid.link/20260109-he_bitrate_overflow-v1-1-95575e466b6e@oss.qualcomm.com Signed-off-by: Johannes Berg <johannes.berg@intel.com>
1 parent 4f431d8 commit a3034bf

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

net/wireless/util.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,12 +1561,14 @@ static u32 cfg80211_calculate_bitrate_he(struct rate_info *rate)
15611561
tmp = result;
15621562
tmp *= SCALE;
15631563
do_div(tmp, mcs_divisors[rate->mcs]);
1564-
result = tmp;
15651564

15661565
/* and take NSS, DCM into account */
1567-
result = (result * rate->nss) / 8;
1566+
tmp *= rate->nss;
1567+
do_div(tmp, 8);
15681568
if (rate->he_dcm)
1569-
result /= 2;
1569+
do_div(tmp, 2);
1570+
1571+
result = tmp;
15701572

15711573
return result / 10000;
15721574
}

0 commit comments

Comments
 (0)