From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F937C43219 for ; Fri, 3 May 2019 12:24:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 667952070B for ; Fri, 3 May 2019 12:24:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726887AbfECMY3 (ORCPT ); Fri, 3 May 2019 08:24:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60316 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726047AbfECMY3 (ORCPT ); Fri, 3 May 2019 08:24:29 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14ABE3092664; Fri, 3 May 2019 12:24:29 +0000 (UTC) Received: from localhost (unknown [10.43.2.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id B2D7D5C6A6; Fri, 3 May 2019 12:24:28 +0000 (UTC) Date: Fri, 3 May 2019 14:24:26 +0200 From: Stanislaw Gruszka To: Tony Chuang Cc: "linux-wireless@vger.kernel.org" Subject: Re: [RFC] rtw88: fix subscript above array bounds compiler warning Message-ID: <20190503122426.GA4423@redhat.com> References: <20190503115333.GA23109@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Fri, 03 May 2019 12:24:29 +0000 (UTC) Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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 > > --- > > 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