Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4048379ybg; Fri, 25 Oct 2019 12:34:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqzAbgQ8XixVzeeQ1wW4/3DVxyNELD/fQxok8O3zZ9clv6T6lpm2FZnpDd5tU073smRTYuCv X-Received: by 2002:a50:b966:: with SMTP id m93mr5773042ede.228.1572032050357; Fri, 25 Oct 2019 12:34:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572032050; cv=none; d=google.com; s=arc-20160816; b=iDT6L67EM/XP8azZHGKVGl7DmLxktHq8rzNfSg4hTAYJjF8LJl/lUHMzT2TF8ysc4k vzrMSkHC3pfu0LcyiPEH5JvQOmDCmPgJoTE2ZULEqtMHOd+9XFrz/5kI2Mm2DvLfkJT5 ZgUhzjwELkpYB/B2i8RYZgcluLUil8BwXU/BoVfhRi192tjCurRoLo768kmt0d9x5sAc fnCexzukoQcOx9VAnokf+fKDvH48zD5TOFHn2UUy0zzcQZAxsOaZH2PzaJ782mWhyOu2 la4AnxBLtIHXIuq+mkk44R0mZOCx31WOkuSXy3KkNTRXjMpwBjdo5fCWP67qjzwPND1p wbfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:authenticated-by; bh=wrhpIqNpRPgGets0y54wx8pUp+KH02YlZ6dXYvk2v/Y=; b=RNfPQKgqzGjhZJnqWpXlX5Hcqq+v3YeR3qjMVG9+TxV1WuJxVOwpkchDNbbPNu/s9L s1mZ2qsCjmsVB7vkQf3izuLE4mu//c/u7Ebei0OjcbHcj31JeBNcZQ9bGLidvvY6aJvG MmuKk628rO2jF4DiPeDNqUpJ5pU5aTF8UjrWG9bQN1aN6/k5hBCli5ubDbu3C9MmOWZ+ 5woGvtxCuwhBxtMaRP20mOjR1i38Z2jEKE0TLucC3hcLDSB6A9zkzgaQ4OZw5Mr2yK4M a/35KgUTVKTV8jW1YVml8rSZIno+O0/yBrcHOJo6xdXK3d7/sGYxiH1DaSKN3wJLZ88G 8nfA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p16si1684368ejj.360.2019.10.25.12.33.46; Fri, 25 Oct 2019 12:34:10 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730185AbfJYJeB (ORCPT + 99 others); Fri, 25 Oct 2019 05:34:01 -0400 Received: from rtits2.realtek.com ([211.75.126.72]:50490 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730249AbfJYJd6 (ORCPT ); Fri, 25 Oct 2019 05:33:58 -0400 Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.62 with qID x9P9XppV026487, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (RTITCASV01.realtek.com.tw[172.21.6.18]) by rtits2.realtek.com.tw (8.15.2/2.57/5.78) with ESMTPS id x9P9XppV026487 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 25 Oct 2019 17:33:51 +0800 Received: from localhost.localdomain (172.21.68.126) by RTITCASV01.realtek.com.tw (172.21.6.18) with Microsoft SMTP Server id 14.3.468.0; Fri, 25 Oct 2019 17:33:50 +0800 From: To: CC: , , Subject: [PATCH 5/6] rtw88: fix potential read outside array boundary Date: Fri, 25 Oct 2019 17:33:44 +0800 Message-ID: <20191025093345.22643-6-yhchuang@realtek.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191025093345.22643-1-yhchuang@realtek.com> References: <20191025093345.22643-1-yhchuang@realtek.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.21.68.126] Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Tzu-En Huang The level of cckpd is from 0 to 4, and it is the index of array pd_lvl[] and cs_lvl[]. However, the length of both arrays are 4, which is smaller than the possible maximum input index. Enumerate cck level to make sure the max level will not be wrong if new level is added in future. Fixes: 479c4ee931a6 ("rtw88: add dynamic cck pd mechanism") Signed-off-by: Tzu-En Huang Signed-off-by: Yan-Hsuan Chuang --- drivers/net/wireless/realtek/rtw88/phy.c | 17 ++++++++--------- drivers/net/wireless/realtek/rtw88/phy.h | 9 +++++++++ drivers/net/wireless/realtek/rtw88/rtw8822c.c | 4 ++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/realtek/rtw88/phy.c b/drivers/net/wireless/realtek/rtw88/phy.c index 4a41134c420e..4adba44dbd74 100644 --- a/drivers/net/wireless/realtek/rtw88/phy.c +++ b/drivers/net/wireless/realtek/rtw88/phy.c @@ -109,7 +109,7 @@ static void rtw_phy_cck_pd_init(struct rtw_dev *rtwdev) for (i = 0; i <= RTW_CHANNEL_WIDTH_40; i++) { for (j = 0; j < RTW_RF_PATH_MAX; j++) - dm_info->cck_pd_lv[i][j] = 0; + dm_info->cck_pd_lv[i][j] = CCK_PD_LV0; } dm_info->cck_fa_avg = CCK_FA_AVG_RESET; @@ -461,7 +461,6 @@ static void rtw_phy_dpk_track(struct rtw_dev *rtwdev) chip->ops->dpk_track(rtwdev); } -#define CCK_PD_LV_MAX 5 #define CCK_PD_FA_LV1_MIN 1000 #define CCK_PD_FA_LV0_MAX 500 @@ -471,10 +470,10 @@ static u8 rtw_phy_cck_pd_lv_unlink(struct rtw_dev *rtwdev) u32 cck_fa_avg = dm_info->cck_fa_avg; if (cck_fa_avg > CCK_PD_FA_LV1_MIN) - return 1; + return CCK_PD_LV1; if (cck_fa_avg < CCK_PD_FA_LV0_MAX) - return 0; + return CCK_PD_LV0; return CCK_PD_LV_MAX; } @@ -494,15 +493,15 @@ static u8 rtw_phy_cck_pd_lv_link(struct rtw_dev *rtwdev) u32 cck_fa_avg = dm_info->cck_fa_avg; if (igi > CCK_PD_IGI_LV4_VAL && rssi > CCK_PD_RSSI_LV4_VAL) - return 4; + return CCK_PD_LV4; if (igi > CCK_PD_IGI_LV3_VAL && rssi > CCK_PD_RSSI_LV3_VAL) - return 3; + return CCK_PD_LV3; if (igi > CCK_PD_IGI_LV2_VAL || rssi > CCK_PD_RSSI_LV2_VAL) - return 2; + return CCK_PD_LV2; if (cck_fa_avg > CCK_PD_FA_LV1_MIN) - return 1; + return CCK_PD_LV1; if (cck_fa_avg < CCK_PD_FA_LV0_MAX) - return 0; + return CCK_PD_LV0; return CCK_PD_LV_MAX; } diff --git a/drivers/net/wireless/realtek/rtw88/phy.h b/drivers/net/wireless/realtek/rtw88/phy.h index c389ef274ed8..af916d8784cd 100644 --- a/drivers/net/wireless/realtek/rtw88/phy.h +++ b/drivers/net/wireless/realtek/rtw88/phy.h @@ -146,6 +146,15 @@ rtw_get_tx_power_params(struct rtw_dev *rtwdev, u8 path, u8 rate, u8 bw, u8 ch, u8 regd, struct rtw_power_params *pwr_param); +enum rtw_phy_cck_pd_lv { + CCK_PD_LV0, + CCK_PD_LV1, + CCK_PD_LV2, + CCK_PD_LV3, + CCK_PD_LV4, + CCK_PD_LV_MAX, +}; + #define MASKBYTE0 0xff #define MASKBYTE1 0xff00 #define MASKBYTE2 0xff0000 diff --git a/drivers/net/wireless/realtek/rtw88/rtw8822c.c b/drivers/net/wireless/realtek/rtw88/rtw8822c.c index b77905196ffb..0c419332fd52 100644 --- a/drivers/net/wireless/realtek/rtw88/rtw8822c.c +++ b/drivers/net/wireless/realtek/rtw88/rtw8822c.c @@ -3295,8 +3295,8 @@ rtw8822c_phy_cck_pd_set_reg(struct rtw_dev *rtwdev, static void rtw8822c_phy_cck_pd_set(struct rtw_dev *rtwdev, u8 new_lvl) { struct rtw_dm_info *dm_info = &rtwdev->dm_info; - s8 pd_lvl[4] = {2, 4, 6, 8}; - s8 cs_lvl[4] = {2, 2, 2, 4}; + s8 pd_lvl[CCK_PD_LV_MAX] = {0, 2, 4, 6, 8}; + s8 cs_lvl[CCK_PD_LV_MAX] = {0, 2, 2, 2, 4}; u8 cur_lvl; u8 nrx, bw; -- 2.17.1