diff mbox series

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

Message ID 20190506073917.10106-1-sgruszka@redhat.com (mailing list archive)
State Accepted
Commit 8a03447dd311da2ad2df74dcf730a1a15f673379
Delegated to: Kalle Valo
Headers show
Series [5.1] rtw88: fix subscript above array bounds compiler warning | expand

Commit Message

Stanislaw Gruszka May 6, 2019, 7:39 a.m. UTC
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.

Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
---
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(+)

Comments

Tony Chuang May 6, 2019, 8:29 a.m. UTC | #1
> 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.
> 
> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> ---
> 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(+)
> 
> diff --git a/drivers/net/wireless/realtek/rtw88/phy.c
> b/drivers/net/wireless/realtek/rtw88/phy.c
> index 4381b360b5b5..9ca52a4d025a 100644
> --- a/drivers/net/wireless/realtek/rtw88/phy.c
> +++ b/drivers/net/wireless/realtek/rtw88/phy.c
> @@ -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);
> --

Thanks. For this patch.

Acked-by: Yan-Hsuan Chuang <yhchuang@realtek.com>

Yan-Hsuan
Stanislaw Gruszka May 6, 2019, 8:42 a.m. UTC | #2
This is for 5.2 and v2 obviously.

Stanislaw

On Mon, May 06, 2019 at 09:39:17AM +0200, Stanislaw Gruszka wrote:
> 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.
> 
> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> ---
> 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(+)
> 
> diff --git a/drivers/net/wireless/realtek/rtw88/phy.c b/drivers/net/wireless/realtek/rtw88/phy.c
> index 4381b360b5b5..9ca52a4d025a 100644
> --- a/drivers/net/wireless/realtek/rtw88/phy.c
> +++ b/drivers/net/wireless/realtek/rtw88/phy.c
> @@ -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);
> -- 
> 2.20.1
>
Kalle Valo May 28, 2019, 11:29 a.m. UTC | #3
Stanislaw Gruszka <sgruszka@redhat.com> wrote:

> 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.
> 
> Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> Acked-by: Yan-Hsuan Chuang <yhchuang@realtek.com>

Patch applied to wireless-drivers.git, thanks.

8a03447dd311 rtw88: fix subscript above array bounds compiler warning
diff mbox series

Patch

diff --git a/drivers/net/wireless/realtek/rtw88/phy.c b/drivers/net/wireless/realtek/rtw88/phy.c
index 4381b360b5b5..9ca52a4d025a 100644
--- a/drivers/net/wireless/realtek/rtw88/phy.c
+++ b/drivers/net/wireless/realtek/rtw88/phy.c
@@ -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);