Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2124379yba; Sun, 5 May 2019 23:24:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwudbMgs1Wjlb3fRonvMLxLETYLttiZCHDKBYkYMeZJkRVvbyZmfCOk92wByW2M03GwknvA X-Received: by 2002:a17:902:8b83:: with SMTP id ay3mr29980040plb.187.1557123878285; Sun, 05 May 2019 23:24:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557123878; cv=none; d=google.com; s=arc-20160816; b=cUM0z06sjmWxn6JIBxkov0O0QfNfjuWL28qccOc4SujrYUv0mfBbNPNttv9C23W0yH f+BoLVcHvAA2/gCw1FmHHuGFKSa7rFWLIemXRdI8UjhXCPUSeV4sS45EV0XybkJjgeXg VJGk+e3zWe5qqsLbz38NQJXbrCmd2Z139QC88duRyfMsVg10AfDv5lMUGVTcJeco7C6/ K+5XM7TQH4559B4T9xfM0Qyu3cuewPYO/cdPgKE2PU5NirZjLKt9a+zROAHJ7L2Tm8Qd +SupgdGEzeDgfqT/OhgZ/XY+EkxBsj2SDCZKcsJvJjI71XN00npvnhjpy3qR8UKEJ67K yaDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=kXKj8k9JF5tPdSbdxgYWikXC7JV1+TdWfMxAA/d5VUs=; b=Sjg2lEXtQV/soHoLOgyCnggxbeR00n3rIoh9YxjUmwnVpD9S/67TTKVYsQsvtdu5F1 xlN3YawO22/hGrp6IZ1UoEIyslptWvd/tBvQfb7kM7rIsZu+M/B4ryeQ8BTC5KKtszum z1GMkdtNKwE7RoM1Tj4s1nyDes78h1L1akUzBo21H4gEdPLwwGO0HAc7+ItvHUzmL6ud WUpfZNvUEEn1X5CHqG3Ni4os+i2ovsrI0CJ6npKiYVkpeSLSyiRAeZsgVhK5+h4YkceQ j3veXtm/FXjXxQTV9TEkFTgybOwuTT22UkbmfMt4OcqVVpQm19tNhIfwJXvD877mTIOc F8/A== 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 m73si14513573pga.271.2019.05.05.23.24.13; Sun, 05 May 2019 23:24:38 -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 S1725830AbfEFGYA (ORCPT + 99 others); Mon, 6 May 2019 02:24:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47814 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725710AbfEFGYA (ORCPT ); Mon, 6 May 2019 02:24:00 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 36996308FE8D; Mon, 6 May 2019 06:24:00 +0000 (UTC) Received: from localhost (ovpn-204-123.brq.redhat.com [10.40.204.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id A67135D9CD; Mon, 6 May 2019 06:23:59 +0000 (UTC) From: Stanislaw Gruszka To: linux-wireless@vger.kernel.org Cc: Yan-Hsuan Chuang Subject: [PATCH 5.1] rtw88: fix subscript above array bounds compiler warning Date: Mon, 6 May 2019 08:23:58 +0200 Message-Id: <20190506062358.8288-1-sgruszka@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 06 May 2019 06:24:00 +0000 (UTC) Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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; + /* 1dB ~ 96dB */ i = (power_db - 1) >> 3; j = (power_db - 1) - (i << 3); -- 2.20.1