Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp470139yba; Fri, 3 May 2019 05:26:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwN8gN6fXLcNH/pUDyI+J5+eXKFaQzTnNZ3broEDv4yDR6cC+RKWaKAc6bFymt+9ZWTisMR X-Received: by 2002:a17:902:8345:: with SMTP id z5mr9932148pln.255.1556886384134; Fri, 03 May 2019 05:26:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556886384; cv=none; d=google.com; s=arc-20160816; b=vuZvOniq2z2Sg9pAnCrQKgVyBpQV29op0wbrUiSpjNG3ifTRVryG8WNQBSwBDRU709 6UfL/RAAGJw9MwJJMJkzq5m1Gcm28fmnc6cs83cCOHeGQzZUKUJu+Wp6NYVwdDcULxC7 ukFHjwfcyKjoFG9M+C+Rjgg2oZT4OHFlN2Q++DNb4A/rw1fsFH1hnEfnjonMc6xk5sJA QOywU9OikofmCB2IjRilsfSiq2r905uvBWhDSv5UGnV+W4yZihUZxLtv6zz8Ap2NxMxM 7OdDbIRk3ai3p6IiUWJyvE45oJbD+cswL/zyGGy5ZGVLZBuB5Q/r2w5oNTI+UORTKVrD j8Vw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=C3D9O6esbRJBbwa3S6Wja0KpNyyaLhgwyHhECBkkU5E=; b=ru3TYbzMwakfUI5dPOu7iiH9Q+7M19WIHrYYQqy43wbYyIDeRgWNvZdaRfcnzg7FZR CoNuEFHSYqn1UPDcIWnDWciBKOZjxrikw/J4Md3tEpzqjSA6Pt5zANfWJtt0ciB9JvJt mNStf3UzLwk4HXvUy6cG1ddYPzsUM3A8ZDMpAQvtDeQwg5T0zf0jRMExWy63j5tsUEd6 vcl+VQ0z3GDh2dUsw5A3Q3+GemrMEygF/jJNLCFSGiXKSCSMvtrF/+28TJRFoUAsLOWI d9eY/nHejVSXEOUzC+PmtCxWdlDVq9G6MuYLgNDiuF2QEJNouIwuZ+0ighNb3K+hvwUY YI5Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i11si1958589pgj.46.2019.05.03.05.26.09; Fri, 03 May 2019 05:26:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726514AbfECMY3 (ORCPT + 99 others); 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