Skip to contentSkip to conversation

wifi: b43: Use 32-bit signed integers for N-PHY RX IQ compensation math

PATCH New Ian Rogers 1 participant 1 message Nov 19 B43 wireless driver

lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

PATCH 1/1 wifi: b43: Use 32-bit signed integers for N-PHY RX IQ compensation math

In b43_nphy_calc_rx_iq_comp(), the intermediate variables tmp, a, and b are declared as u16, even though the fixed-point calibration arithmetic shifts 32-bit IQ correlation and power estimates up to bit 30 before dividing:

  a = -((iq << (30 - iq_nbits)) + (ii >> (1 + arsh)));
  tmp = ii >> arsh;
  a /= tmp;
  ...
  b = (qq << (31 - qq_nbits));
  tmp = ii >> brsh;
  b = int_sqrt(b / tmp - a * a) - (1 << 10);

Truncating these 30/31-bit numerators and ~20-bit denominators to u16 discards their upper bits (frequently collapsing b = qq << (31 - qq_nbits) to 0 and corrupting the signed division a /= tmp), producing bogus 10-bit RX IQ calibration coefficients compared to the 32-bit int implementation in lpphy_calc_rx_iq_comp().

Change tmp, a, and b to s32 so the fixed-point divisions and square-root input retain full 32-bit signed precision.

Found by enabling Clang's -Wimplicit-int-conversion-on-negation on an x86_64 allyesconfig build, with AI coding assistant help to audit the warning and prepare the fix. Verified with a standalone C fixed-point test and Clang build; not runtime-tested on Broadcom 802.11n hardware.

Fixes 34a56f2cae86 ("b43: N-PHY: implement calculating RX IQ comp")
---
 drivers/net/wireless/broadcom/b43/phy_n.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/broadcom/b43/phy_n.c +1 -1
index 007940f3996e..7b020e0fcd93 100644
@@ -4482,7 +4482,7 @@ static void b43_nphy_calc_rx_iq_comp(struct b43_wldev *dev, u8 mask)
 	u32 qq;
 	int iq_nbits, qq_nbits;
 	int arsh, brsh;
-	u16 tmp, a, b;
+	s32 tmp, a, b;
 
 	struct nphy_iq_est est;
 	struct b43_phy_n_iq_comp old;
Signature · 1 line
2.56.1.708.g77570a6a1d-goog