Commit 75505199 authored by Nick Kossifidis's avatar Nick Kossifidis Committed by John W. Linville
Browse files

ath5k: Fix range scaling when setting rate power table



rates[i] is unsigned but txp_offset can be negative for newer parts
with PDADC table. We cover the case when rates[i] + txp_offset > 63
but we must also cover the case when its < 0 or else rates[i] will overflow.

Signed-off-by: default avatarNick Kossifidis <mickflemm@gmail.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent d12c5c53
Loading
Loading
Loading
Loading
+7 −3
Original line number Original line Diff line number Diff line
@@ -3516,6 +3516,7 @@ ath5k_setup_rate_powertable(struct ath5k_hw *ah, u16 max_pwr,
{
{
	unsigned int i;
	unsigned int i;
	u16 *rates;
	u16 *rates;
	s16 rate_idx_scaled = 0;


	/* max_pwr is power level we got from driver/user in 0.5dB
	/* max_pwr is power level we got from driver/user in 0.5dB
	 * units, switch to 0.25dB units so we can compare */
	 * units, switch to 0.25dB units so we can compare */
@@ -3580,10 +3581,13 @@ ath5k_setup_rate_powertable(struct ath5k_hw *ah, u16 max_pwr,
	 * match the power range set by user with the power indices
	 * match the power range set by user with the power indices
	 * on PCDAC/PDADC table */
	 * on PCDAC/PDADC table */
	for (i = 0; i < 16; i++) {
	for (i = 0; i < 16; i++) {
		rates[i] += ah->ah_txpower.txp_offset;
		rate_idx_scaled = rates[i] + ah->ah_txpower.txp_offset;
		/* Don't get out of bounds */
		/* Don't get out of bounds */
		if (rates[i] > 63)
		if (rate_idx_scaled > 63)
			rates[i] = 63;
			rate_idx_scaled = 63;
		if (rate_idx_scaled < 0)
			rate_idx_scaled = 0;
		rates[i] = rate_idx_scaled;
	}
	}
}
}