Skip to contentSkip to conversation

wifi: mt76: clamp channel power to the s8 range

PATCH New JB Tsai 1 participant 1 message Nov 11

Subsystems (2)
lore
Share & tools
lore

JB Tsai

author
#0 lore raw

PATCH 1/1 wifi: mt76: clamp channel power to the s8 range

From: "allen.chien" <[email protected]>

mt76_connac_get_ch_power() computes power as an int from 2 * ch->max_reg_power and then compares it with target_power through min_t(s8, ...), which truncates the value to 8 bits. An out-of-range max_reg_power would wrap (e.g. 300 becomes 44) and could lower target_power wrongly.

Clamp the value into the s8 range when it is calculated. Regulatory limits are far below that range, so valid input is not affected.

---
 drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c +2 -1
index ad53bb60d5cd..f5215fa27faf 100644
@@ -2168,7 +2168,8 @@ s8 mt76_connac_get_ch_power(struct mt76_phy *phy,
 
 		if (ch->hw_value == chan->hw_value) {
 			if (!(ch->flags & IEEE80211_CHAN_DISABLED)) {
-				int power = 2 * ch->max_reg_power;
+				int power = clamp_t(int, 2 * ch->max_reg_power,
+						    S8_MIN, S8_MAX);
 
 				if (is_mt7663(dev) && (power > 63 || power < -64))
 					power = 63;
Signature · 1 line
2.45.2