linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 5.1] rtw88: fix subscript above array bounds compiler warning
@ 2019-05-06  6:23 Stanislaw Gruszka
  2019-05-06  6:32 ` Tony Chuang
  0 siblings, 1 reply; 8+ messages in thread
From: Stanislaw Gruszka @ 2019-05-06  6:23 UTC (permalink / raw)
  To: linux-wireless; +Cc: Yan-Hsuan Chuang

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.

 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)
+		power_db = 1;
+
 	/* 1dB ~ 96dB */
 	i = (power_db - 1) >> 3;
 	j = (power_db - 1) - (i << 3);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* RE: [PATCH 5.1] rtw88: fix subscript above array bounds compiler warning
  2019-05-06  6:23 [PATCH 5.1] rtw88: fix subscript above array bounds compiler warning Stanislaw Gruszka
@ 2019-05-06  6:32 ` Tony Chuang
  2019-05-06  6:43   ` Stanislaw Gruszka
  0 siblings, 1 reply; 8+ messages in thread
From: Tony Chuang @ 2019-05-06  6:32 UTC (permalink / raw)
  To: Stanislaw Gruszka, linux-wireless

> 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.
> 
>  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)
> +		power_db = 1;

I think it's "return 1" here.

> +
>  	/* 1dB ~ 96dB */
>  	i = (power_db - 1) >> 3;
>  	j = (power_db - 1) - (i << 3);
> --

Yan-Hsuan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 5.1] rtw88: fix subscript above array bounds compiler warning
  2019-05-06  6:32 ` Tony Chuang
@ 2019-05-06  6:43   ` Stanislaw Gruszka
  2019-05-06  6:51     ` Tony Chuang
  0 siblings, 1 reply; 8+ messages in thread
From: Stanislaw Gruszka @ 2019-05-06  6:43 UTC (permalink / raw)
  To: Tony Chuang; +Cc: linux-wireless

On Mon, May 06, 2019 at 06:32:01AM +0000, Tony Chuang wrote:
> > 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.
> > 
> >  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)
> > +		power_db = 1;
> 
> I think it's "return 1" here.

Ehh, I missed that in your comment. However 'return 1' change
the output of rtw_phy_db_2_linear() quite substantially
as the smallest value (for power_db = 1) from db_invert_table[][]
is 10. I'll post v2 patch, but please double check it's indeed
correct logic. Thanks.

Stanislaw


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH 5.1] rtw88: fix subscript above array bounds compiler warning
  2019-05-06  6:43   ` Stanislaw Gruszka
@ 2019-05-06  6:51     ` Tony Chuang
  0 siblings, 0 replies; 8+ messages in thread
From: Tony Chuang @ 2019-05-06  6:51 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: linux-wireless

> Subject: Re: [PATCH 5.1] rtw88: fix subscript above array bounds compiler
> warning
> 
> On Mon, May 06, 2019 at 06:32:01AM +0000, Tony Chuang wrote:
> > > 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.
> > >
> > >  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)
> > > +		power_db = 1;
> >
> > I think it's "return 1" here.
> 
> Ehh, I missed that in your comment. However 'return 1' change
> the output of rtw_phy_db_2_linear() quite substantially
> as the smallest value (for power_db = 1) from db_invert_table[][]
> is 10. I'll post v2 patch, but please double check it's indeed
> correct logic. Thanks.
> 

I think "return 1" is correct because 0 is not in domain 1~96.
And indeed anything to the power of zero is 1.
Thanks.

Yan-Hsuan


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 5.1] rtw88: fix subscript above array bounds compiler warning
  2019-05-06  7:39 Stanislaw Gruszka
  2019-05-06  8:29 ` Tony Chuang
  2019-05-06  8:42 ` Stanislaw Gruszka
@ 2019-05-28 11:29 ` Kalle Valo
  2 siblings, 0 replies; 8+ messages in thread
From: Kalle Valo @ 2019-05-28 11:29 UTC (permalink / raw)
  To: Stanislaw Gruszka; +Cc: linux-wireless, Yan-Hsuan Chuang

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

-- 
https://patchwork.kernel.org/patch/10930671/

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 5.1] rtw88: fix subscript above array bounds compiler warning
  2019-05-06  7:39 Stanislaw Gruszka
  2019-05-06  8:29 ` Tony Chuang
@ 2019-05-06  8:42 ` Stanislaw Gruszka
  2019-05-28 11:29 ` Kalle Valo
  2 siblings, 0 replies; 8+ messages in thread
From: Stanislaw Gruszka @ 2019-05-06  8:42 UTC (permalink / raw)
  To: linux-wireless, Kalle Valo; +Cc: Yan-Hsuan Chuang

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
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH 5.1] rtw88: fix subscript above array bounds compiler warning
  2019-05-06  7:39 Stanislaw Gruszka
@ 2019-05-06  8:29 ` Tony Chuang
  2019-05-06  8:42 ` Stanislaw Gruszka
  2019-05-28 11:29 ` Kalle Valo
  2 siblings, 0 replies; 8+ messages in thread
From: Tony Chuang @ 2019-05-06  8:29 UTC (permalink / raw)
  To: Stanislaw Gruszka, linux-wireless

> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 5.1] rtw88: fix subscript above array bounds compiler warning
@ 2019-05-06  7:39 Stanislaw Gruszka
  2019-05-06  8:29 ` Tony Chuang
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Stanislaw Gruszka @ 2019-05-06  7:39 UTC (permalink / raw)
  To: linux-wireless; +Cc: Yan-Hsuan Chuang

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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-05-28 11:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-06  6:23 [PATCH 5.1] rtw88: fix subscript above array bounds compiler warning Stanislaw Gruszka
2019-05-06  6:32 ` Tony Chuang
2019-05-06  6:43   ` Stanislaw Gruszka
2019-05-06  6:51     ` Tony Chuang
2019-05-06  7:39 Stanislaw Gruszka
2019-05-06  8:29 ` Tony Chuang
2019-05-06  8:42 ` Stanislaw Gruszka
2019-05-28 11:29 ` Kalle Valo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).