Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2138119yba; Sun, 5 May 2019 23:46:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwoIu8ZdD2D1BKgSxicaEiLNUxi5+IyY4Fbc0L5nrdiM3W86Qh10q9mKloTSZnISW3Iia4g X-Received: by 2002:aa7:884b:: with SMTP id k11mr31290242pfo.49.1557125165586; Sun, 05 May 2019 23:46:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557125165; cv=none; d=google.com; s=arc-20160816; b=TlNJomPcmVMZ2cWvElaSsaR8N3PXfdasivquw1OTdVRm1P8R/tGaRbVKtAFTD0ZeX9 91BXHp4YL9VQqlt6dNt3V09bZB8Y4tyXTnJDyZgxiezta64HBZPQV3j/pEKqkaECnyGP 8ppgKadxnxRcVvwtT5kodwrMcxhy8P0MviZzR8wX5ibJ3gY+OSe6UMwVMFwmIhfTOlr0 q27vK0e73+sjwlesbQlSQLdbAM6/i0Ja7B9j2NIrEF2OHTaAQlEXsYVPrq/XRlfC89Xk RCdwHzbJ/xNEICdsHptb+kF1RjC0kuK9noRFqYSPPpYzvSzNxa7b8BOrquoSsBErYPoD co6A== 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=KKbs+eJJZxA4nMUrojVSZGu38suTgV8tEKUq8XbFPxY=; b=X4MKKh53acI58OcEhpupm237k8FfVviywyX5HJ6SCt3hfYZqcQ9SnBgs3n0W2OUCTk tpD4pGHr6KcpZXpijCMIsNx51GE2XwAdd68jwOAn9lZnW8z4l+Hw0a6gdBfGsX395xSc mQOQWqj/lJimYJZRtvGtuhJYRHG3yV99dUBH+REBmL9ff9SeemASVAf4UatcA7dEnczq n5Q3hwY4SBiYIEnPjj7PUAbmpIZ3SN8W0aLMibAa1SpnyG4IBMIwvYXvsiXCecM18r3r p4STZWceZS5zKsWaPRXb8tAYqJklNm/NM1lnNayX1pMArP8GwVEjgGRd5Lki53O59S30 lVxQ== 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 j5si13765223pfa.63.2019.05.05.23.45.44; Sun, 05 May 2019 23:46:05 -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 S1725840AbfEFGn7 (ORCPT + 99 others); Mon, 6 May 2019 02:43:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48890 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725830AbfEFGn6 (ORCPT ); Mon, 6 May 2019 02:43:58 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C57DB3086226; Mon, 6 May 2019 06:43:58 +0000 (UTC) Received: from localhost (ovpn-204-123.brq.redhat.com [10.40.204.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6915560C44; Mon, 6 May 2019 06:43:58 +0000 (UTC) Date: Mon, 6 May 2019 08:43:57 +0200 From: Stanislaw Gruszka To: Tony Chuang Cc: "linux-wireless@vger.kernel.org" Subject: Re: [PATCH 5.1] rtw88: fix subscript above array bounds compiler warning Message-ID: <20190506064357.GB5115@redhat.com> References: <20190506062358.8288-1-sgruszka@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.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Mon, 06 May 2019 06:43:58 +0000 (UTC) Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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 > > --- > > 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