All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stanislaw Gruszka <sgruszka@redhat.com>
To: Tony Chuang <yhchuang@realtek.com>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>
Subject: Re: [RFC] rtw88: fix subscript above array bounds compiler warning
Date: Fri, 3 May 2019 14:24:26 +0200	[thread overview]
Message-ID: <20190503122426.GA4423@redhat.com> (raw)
In-Reply-To: <F7CD281DE3E379468C6D07993EA72F84D17E8846@RTITMBSVM04.realtek.com.tw>

On Fri, May 03, 2019 at 12:01:05PM +0000, Tony Chuang wrote:
> > Subject: [RFC] rtw88: fix subscript above array bounds compiler warning
> > 
> > My compiler complain 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 .
> > Correct rtw_phy_power_2_db() to make max power 96 db
> > (still min is 0). This make the warning gone.
> > 
> > However power >= 20 check still looks somewhat suspicious to me.
> > 
> > Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
> > ---
> >  drivers/net/wireless/realtek/rtw88/phy.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/net/wireless/realtek/rtw88/phy.c
> > b/drivers/net/wireless/realtek/rtw88/phy.c
> > index 35a35dbca85f..a716a44d78b0 100644
> > --- a/drivers/net/wireless/realtek/rtw88/phy.c
> > +++ b/drivers/net/wireless/realtek/rtw88/phy.c
> > @@ -410,12 +410,12 @@ void rtw_phy_dynamic_mechanism(struct rtw_dev
> > *rtwdev)
> > 
> >  static u8 rtw_phy_power_2_db(s8 power)
> >  {
> > -	if (power <= -100 || power >= 20)
> > +	if (power <= -96 || power >= 20)
> >  		return 0;
> >  	else if (power >= 0)
> > -		return 100;
> > +		return 96;
> >  	else
> > -		return 100 + power;
> > +		return 96 + power;
> >  }
> > 
> >  static u64 rtw_phy_db_2_linear(u8 power_db)
> > --
> 
> I think I should check with the radio team, that if the power from the
> rx descriptor generated by hardware can possibly get >= 20
> 
> And also check what the actual logic they expected to deal with the power.
> Thanks for reporting it.

Yeah, this could be just teoretical issue as we can not get power
values >= 0 from HW. However I think compiler correctly complains, as
for power_db=100 we get i = ((100 - 1) >> 3) = 12 , what exceed by one
max first index of db_invert_table[][], which should be in range
0 - 11.

Stanislaw


  reply	other threads:[~2019-05-03 12:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-03 11:53 [RFC] rtw88: fix subscript above array bounds compiler warning Stanislaw Gruszka
2019-05-03 12:01 ` Tony Chuang
2019-05-03 12:24   ` Stanislaw Gruszka [this message]
2019-05-06  3:42     ` Tony Chuang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190503122426.GA4423@redhat.com \
    --to=sgruszka@redhat.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=yhchuang@realtek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.