Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4192555pxv; Mon, 19 Jul 2021 19:57:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAMoNLFfct/FefyRe4Cz4moEgh2iKpfSzEb3jqbc1rcQJe2wwtVkcyR97G3CBc73L0XkLA X-Received: by 2002:a17:907:2d8e:: with SMTP id gt14mr30031797ejc.159.1626749858276; Mon, 19 Jul 2021 19:57:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626749858; cv=none; d=google.com; s=arc-20160816; b=pCAoghNn8tdowz7fTge8J5nSjBpevUtLSUP4g/IwHcwhUeWys3uaZo62OPQVv6cLH4 uj2OE84t9jRQRJKn29qC70hG4UbwyzlxDgcyn+YwYJR2l4s5+/sfRaiOcHeWLoCTCOR7 g/CPaafPLZZ00WzXwwKmVMP6ql89fnfNedrNdrfaWRkC2GriWVB1+tknf596dPMsvdMo UtQrOyfDtdpUK/OIs5p0qE+LGjzxLG8o+tkL7aqNojs25SbIshZMVC7eWR99IQWCVLbW Q+izYBo8p/XBilx4cMyZxvikDk4BZZ/Jh9PzlQ2ePlz2tuWJciYEhohi4ueT7FwuDjfL fxkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=6WFcCcteaxu2wYo2pC/FLGpKwTB3PoZI7xV0hL4WLWk=; b=oZHC/CRcguPqB83nFIh9D8n8r53ennUVhfC+w2jWyt/cbSi5c7dB7n9x38E/7uu8wx sHT7VcP0/O/1qgkjm8N6x/hvTftnPlAtIuQANxZeiNK9n48Sb2j+Qk/CTsFVsaYRVFW+ 37nfD49PSxh4prM6WK9gKk6C9XqSg2wibEiGfubWydA7JQ8aPoT/zRKaSpejZgfAPBrG zOkd8Ad/nxpsTJ562TsSHXdrrr0ReaCit2FkKwoaVGDOklpEJfE7jjxH10jDpzfcgLT+ i0JckPx0hOCJBDztDP2S0e49KJkhU+F4oGjWqMsbluawsjgX/nU+SoxwPaWcHH49BE03 eAIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s22si21589269ejy.147.2021.07.19.19.57.09; Mon, 19 Jul 2021 19:57:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237979AbhGTCL2 (ORCPT + 99 others); Mon, 19 Jul 2021 22:11:28 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:44478 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S244286AbhGTCJG (ORCPT ); Mon, 19 Jul 2021 22:09:06 -0400 X-UUID: d7f1daa3109d4e218e6a62960256a8ad-20210720 X-UUID: d7f1daa3109d4e218e6a62960256a8ad-20210720 Received: from mtkexhb01.mediatek.inc [(172.21.101.102)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 923929611; Tue, 20 Jul 2021 10:49:28 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs06n1.mediatek.inc (172.21.101.129) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 20 Jul 2021 10:49:27 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 20 Jul 2021 10:49:27 +0800 From: Shayne Chen To: Felix Fietkau CC: linux-wireless , Lorenzo Bianconi , Ryder Lee , linux-mediatek , Shayne Chen , Bo Jiao Subject: [PATCH v2] mt76: mt7915: fix potential overflow of eeprom page index Date: Tue, 20 Jul 2021 10:48:32 +0800 Message-ID: <20210720024832.20265-1-shayne.chen@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org If total eeprom size is divisible by per-page size, the i in for loop will exceed max page index, which happens in our newer chipset. Fixes: 26f18380e6ca ("mt76: mt7915: add support for flash mode") Signed-off-by: Bo Jiao Signed-off-by: Shayne Chen Reported-by: kernel test robot --- v2: fix warning reported by kernel test robot drivers/net/wireless/mediatek/mt76/mt7915/mcu.c:3407:22: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand] if (i == total - 1 && MT7915_EEPROM_SIZE % PER_PAGE_SIZE) ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- drivers/net/wireless/mediatek/mt76/mt7915/mcu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c index 91efa9b..69b6796 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c @@ -3392,20 +3392,20 @@ int mt7915_mcu_set_chan_info(struct mt7915_phy *phy, int cmd) static int mt7915_mcu_set_eeprom_flash(struct mt7915_dev *dev) { -#define TOTAL_PAGE_MASK GENMASK(7, 5) +#define MAX_PAGE_IDX_MASK GENMASK(7, 5) #define PAGE_IDX_MASK GENMASK(4, 2) #define PER_PAGE_SIZE 0x400 struct mt7915_mcu_eeprom req = { .buffer_mode = EE_MODE_BUFFER }; - u8 total = MT7915_EEPROM_SIZE / PER_PAGE_SIZE; + u8 total = DIV_ROUND_UP(MT7915_EEPROM_SIZE, PER_PAGE_SIZE); u8 *eep = (u8 *)dev->mt76.eeprom.data; int eep_len; int i; - for (i = 0; i <= total; i++, eep += eep_len) { + for (i = 0; i < total; i++, eep += eep_len) { struct sk_buff *skb; int ret; - if (i == total) + if (i == total - 1 && !!(MT7915_EEPROM_SIZE % PER_PAGE_SIZE)) eep_len = MT7915_EEPROM_SIZE % PER_PAGE_SIZE; else eep_len = PER_PAGE_SIZE; @@ -3415,7 +3415,7 @@ static int mt7915_mcu_set_eeprom_flash(struct mt7915_dev *dev) if (!skb) return -ENOMEM; - req.format = FIELD_PREP(TOTAL_PAGE_MASK, total) | + req.format = FIELD_PREP(MAX_PAGE_IDX_MASK, total - 1) | FIELD_PREP(PAGE_IDX_MASK, i) | EE_FORMAT_WHOLE; req.len = cpu_to_le16(eep_len); -- 2.25.1