Skip to contentSkip to conversation

rtw88: fix subscript above array bounds compiler warning

PATCH In review Stanislaw Gruszka 3 participants 4 messages May 6, 2019 – May 28, 2019 Realtek wireless driver (rtw88)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtw88: fix subscript above array bounds compiler warning

My compiler complains about:

drivers/net/wireless/realtek/rtw88/phy.c: In function ‘rtw_phy_rf_power_2_rssi’:
drivers/net/wireless/realtek/rtw88/phy.c:430:26: warning: array subscript is above array bounds [-Warray-bounds]
linear = db_invert_table[i][j];

According to comment power_db should be in range 1 ~ 96 . To fix add check for boundaries before access the array.

---
RFC -> v1
- add check before accessing the array insted of
rtw_phy_power_2_db() change.
v1 -> v2:
- return 1 for power_db < 1

 drivers/net/wireless/realtek/rtw88/phy.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/wireless/realtek/rtw88/phy.c +5 -0
index 4381b360b5b5..9ca52a4d025a 100644
@@ -423,6 +423,11 @@ static u64 rtw_phy_db_2_linear(u8 power_db)
 	u8 i, j;
 	u64 linear;
 
+	if (power_db > 96)
+		power_db = 96;
+	else if (power_db < 1)
+		return 1;
+
 	/* 1dB ~ 96dB */
 	i = (power_db - 1) >> 3;
 	j = (power_db - 1) - (i << 3);
Signature · 1 line
2.20.1
Acked-by on v1 1/1
#1 lore raw
Quoted 32 lines

Subject: [PATCH 5.1] rtw88: fix subscript above array bounds compiler warning

My compiler complains about:

drivers/net/wireless/realtek/rtw88/phy.c: In function ‘rtw_phy_rf_power_2_rssi’:
drivers/net/wireless/realtek/rtw88/phy.c:430:26: warning: array subscript is above array bounds [-Warray-bounds]
linear = db_invert_table[i][j];

According to comment power_db should be in range 1 ~ 96 . To fix add check for boundaries before access the array.

---
RFC -> v1
- add check before accessing the array insted of
rtw_phy_power_2_db() change.
v1 -> v2:
- return 1 for power_db < 1

 drivers/net/wireless/realtek/rtw88/phy.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/wireless/realtek/rtw88/phy.c +0 -0
index 4381b360b5b5..9ca52a4d025a 100644
@@ -423,6 +423,11 @@ static u64 rtw_phy_db_2_linear(u8 power_db)
 	u8 i, j;
 	u64 linear;

drivers/net/wireless/realtek/rtw88/phy.c static u64 rtw_phy_db_2_linear(u8 power_db)

Quoted 10 lines
drivers/net/wireless/realtek/rtw88/phy.c +5 -1
 
+	if (power_db > 96)
+		power_db = 96;
+	else if (power_db < 1)
+		return 1;
+
 	/* 1dB ~ 96dB */
 	i = (power_db - 1) >> 3;
 	j = (power_db - 1) - (i << 3);
--

Thanks. For this patch.

Yan-Hsuan

#2 lore raw
In reply to Stanislaw Gruszka

This is for 5.2 and v2 obviously.

Stanislaw

Quoted 39 lines · Stanislaw Gruszka

My compiler complains about:

drivers/net/wireless/realtek/rtw88/phy.c: In function ???rtw_phy_rf_power_2_rssi???:
drivers/net/wireless/realtek/rtw88/phy.c:430:26: warning: array subscript is above array bounds [-Warray-bounds]
linear = db_invert_table[i][j];

According to comment power_db should be in range 1 ~ 96 . To fix add check for boundaries before access the array.

---
RFC -> v1
- add check before accessing the array insted of
rtw_phy_power_2_db() change.
v1 -> v2:
- return 1 for power_db < 1

 drivers/net/wireless/realtek/rtw88/phy.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/wireless/realtek/rtw88/phy.c +5 -0
index 4381b360b5b5..9ca52a4d025a 100644
@@ -423,6 +423,11 @@ static u64 rtw_phy_db_2_linear(u8 power_db)
 	u8 i, j;
 	u64 linear;
 
+	if (power_db > 96)
+		power_db = 96;
+	else if (power_db < 1)
+		return 1;
+
 	/* 1dB ~ 96dB */
 	i = (power_db - 1) >> 3;
 	j = (power_db - 1) - (i << 3);
Signature · 1 line
2.20.1
#3 lore raw
In reply to Stanislaw Gruszka
Quoted 11 lines · Stanislaw Gruszka

My compiler complains about:

drivers/net/wireless/realtek/rtw88/phy.c: In function ‘rtw_phy_rf_power_2_rssi’:
drivers/net/wireless/realtek/rtw88/phy.c:430:26: warning: array subscript is above array bounds [-Warray-bounds]
linear = db_invert_table[i][j];

According to comment power_db should be in range 1 ~ 96 . To fix add check for boundaries before access the array.

Patch applied to wireless-drivers.git, thanks.

8a03447dd311 rtw88: fix subscript above array bounds compiler warning

Signature · 3 lines
https://patchwork.kernel.org/patch/10930671/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches