Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2172794yba; Mon, 6 May 2019 00:39:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqw1njW6WGaaDuM8wyU8i98JXbNbiIrR3JObEUb7lqBag/K4zQr2D/84Wvn1s8Z2lmwRWoYG X-Received: by 2002:a62:414a:: with SMTP id o71mr30982772pfa.240.1557128389298; Mon, 06 May 2019 00:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557128389; cv=none; d=google.com; s=arc-20160816; b=r62Ic8nCPSgwGGc4Kb6zScZVG0kV9JfdoJ/Vt94EyGNykK0t4QujmIObLlaALDjOcX itUjuTJkJtwJm5ae13SDjnF/pLPNkUNwA4z3D+IZJcjT5fR+mlvEIyJ2uxR/FIuHLFcb htiSkNgTwAlO35YmfSQMML+7RKkb33st0vGRd6w0cJrB5xGWXiX4b5HbHn5/+3W7FdyQ SNBcCPUdODEEVQZI/GXcQHTlj7/SzhV5LPq5YicUxu4rvSkn1v/OWTH5ATLIDwEZg9UG IVehZ61OYivrHXlkdowIzEA7kKAEREaNLLc/WyK92jyhCZrCNATpLGCpmemcS3X9q/0q rrGw== 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=CKoHea3pE2nLXcCLtvQHF9x2aO5lNF2xO/xVf3DscbQ=; b=O6qhjyJa2JSBxpFmQ19uharX48HxGmLEQfcTf8Va5AMsgmyLHM5+mJa4eWLedlPzOk VHdzF6dCOOKKs+ZT/gHWuBY4FZ4ZZjiVj90CuDfzm5ksHqzekd2VtrwCvg8llrQnd2ec /yx0ZjGeJS8LZ5isJdrO2VZxEvxrJdQZeomWOXV1fnuzOBwBb6zlEaWdtF3sVdEgJ5td t0yhS702DRSsVv8BRWbAfeM8eGh4l3HWfk/G3kC7z+mOahanfwt4jPvF7ZF8C9368CVh 9RC8s7wKYmoFvyAlXfPEF0hI2jQ+6iYoo73IT7wmuurnNhA9xQ5bRUfT/jIC2KB9xkaE qY3Q== 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 r17si12658629pgv.128.2019.05.06.00.39.23; Mon, 06 May 2019 00:39:49 -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 S1726347AbfEFHjT (ORCPT + 99 others); Mon, 6 May 2019 03:39:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13146 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725864AbfEFHjT (ORCPT ); Mon, 6 May 2019 03:39:19 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D561B307D924; Mon, 6 May 2019 07:39:18 +0000 (UTC) Received: from localhost (ovpn-204-123.brq.redhat.com [10.40.204.123]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C672620DB; Mon, 6 May 2019 07:39:18 +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 09:39:17 +0200 Message-Id: <20190506073917.10106-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Mon, 06 May 2019 07:39:19 +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. v1 -> v2: - return 1 for power_db < 1 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) + return 1; + /* 1dB ~ 96dB */ i = (power_db - 1) >> 3; j = (power_db - 1) - (i << 3); -- 2.20.1