Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3916689rwb; Sat, 3 Dec 2022 13:36:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf6g1NgczenVqmmeuk8yHq+MYdmakpdYo0yH8ktlC7bsMoh/8yhV3X+SKlmsQIiAOLuTJgIt X-Received: by 2002:a17:90a:ab08:b0:219:aea9:4487 with SMTP id m8-20020a17090aab0800b00219aea94487mr3476819pjq.161.1670103363872; Sat, 03 Dec 2022 13:36:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670103363; cv=none; d=google.com; s=arc-20160816; b=cFuG5Pc7hKCcAXVRls7AUm1zjAx0jxhn8vyyrINGkPF/Jhwdv5UWXmGBWa3pAhhaoW /U5CfTrOy4ghpXNSiWsrFUAVYjUuUUtmq226e1UEbMY3UK1geq/dtVGiilEImoYoY2IK Kn4sLZJ66FrGXCoXCQW4/1wRkj+uhoTN3VD9vta6d8XyPwdGGPMnWu7p0o8snO2I3mNl s0vWdAQbVDIIlPG9CoXZI+W1TTRuneJRxHL1JNMgYZx5qqcs7IETFKqVeKV6O5GqZGQL b23+2ag2+6zXEwuvbRqqyKmEeVgWnTldVjgl4LhjNfqjxyBKjDGn1nNJppyo7f7yMddo /1uQ== 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 :dkim-signature; bh=CWwG02TSaInKtmUV+WNqTAMV/tocxbg7bIfdefA8Tso=; b=h3JdKNL4T416nsfKqNyL0DI5+80E3JhsCXWTVSlxhM77aXncX5e6LK9RosYnHrqivf 7xnYWSZehmBGQwd/3MpxwN7Xq+MJX/74wXnBWCqmsQjfex+nbtEWKwvzBH1bm9TvIIlV KAp2QOYmhVftlratXv/4vF1HTkz9YPaqQyIyMLu8ICWETjTklejhf41+I0Kajz2OKQWU K1U+pWL7nVni2Qla8D5MfutSicqdPh5X+8mQVIGuWli2AGeUnbmqZqUNkVxXfg4r9lbZ 8LqSy3alMQZTU6w4MkbpzwCxV9oG8WVwOtfIFmmxx+sQsguwpto3rTlBhtbT1VDK3eTl K8pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=Gs0+MCCH; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c19-20020a056a000ad300b0056e770672c1si11700633pfl.305.2022.12.03.13.35.55; Sat, 03 Dec 2022 13:36:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b=Gs0+MCCH; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229680AbiLCVdj (ORCPT + 66 others); Sat, 3 Dec 2022 16:33:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229691AbiLCVde (ORCPT ); Sat, 3 Dec 2022 16:33:34 -0500 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE57210B71 for ; Sat, 3 Dec 2022 13:33:29 -0800 (PST) X-UUID: 0c663f3cf4c540d0909a7586b921a53b-20221204 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=CWwG02TSaInKtmUV+WNqTAMV/tocxbg7bIfdefA8Tso=; b=Gs0+MCCH1uX7Gb6HzSSg12LsyxSNpmKfM6TPYhv06b63E8UUkqjIa1beYkengrJwPv8nwONbujGwsgIzN6ekI2H891hhMkkPzo5WtAl10mCN6M7n3q2jsXjfHmovYyjmq4lImw9sg9tKs3gwuas6g4BETZbaQfVYfDGUQh+Llmw=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.14,REQID:d42b8f6f-c37e-4857-ab01-4517e47cb523,IP:0,U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:90 X-CID-INFO: VERSION:1.1.14,REQID:d42b8f6f-c37e-4857-ab01-4517e47cb523,IP:0,URL :0,TC:0,Content:-5,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTIO N:quarantine,TS:90 X-CID-META: VersionHash:dcaaed0,CLOUDID:bff59330-2938-482e-aafd-98d66723b8a9,B ulkID:221204053324YYIDDYKS,BulkQuantity:1,Recheck:0,SF:38|28|17|19|48,TC:n il,Content:0,EDM:-3,IP:nil,URL:0,File:nil,Bulk:43,QS:nil,BEC:nil,COL:0 X-UUID: 0c663f3cf4c540d0909a7586b921a53b-20221204 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1633810790; Sun, 04 Dec 2022 05:33:21 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Sun, 4 Dec 2022 05:33:20 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Sun, 4 Dec 2022 05:33:20 +0800 From: Ryder Lee To: Felix Fietkau , CC: Lorenzo Bianconi , Shayne Chen , Evelyn Tsai , , Ryder Lee Subject: [PATCH v2 1/3] wifi: mt76: mt7915: check return value before accessing free_block_num Date: Sun, 4 Dec 2022 05:33:17 +0800 Message-ID: <3fec8b8c618a78d1197f4060f89fa8bdd836b425.1670102099.git.ryder.lee@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Check return value of mt7915_mcu_get_eeprom_free_block() first before accessing free_block_num. Fixes: bbc1d4154ec1 ("mt76: mt7915: add default calibrated data support") Signed-off-by: Ryder Lee --- change since v2 - check return value of mt7915_mcu_get_eeprom() as well. --- .../wireless/mediatek/mt76/mt7915/eeprom.c | 19 ++++++++++++------- .../net/wireless/mediatek/mt76/mt7915/mcu.c | 10 ++++++---- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c index 59069fb86414..24efa280dd86 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/eeprom.c @@ -110,18 +110,23 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) } else { u8 free_block_num; u32 block_num, i; + u32 eeprom_blk_size = MT7915_EEPROM_BLOCK_SIZE; - mt7915_mcu_get_eeprom_free_block(dev, &free_block_num); - /* efuse info not enough */ + ret = mt7915_mcu_get_eeprom_free_block(dev, &free_block_num); + if (ret < 0) + return ret; + + /* efuse info isn't enough */ if (free_block_num >= 29) return -EINVAL; /* read eeprom data from efuse */ - block_num = DIV_ROUND_UP(eeprom_size, - MT7915_EEPROM_BLOCK_SIZE); - for (i = 0; i < block_num; i++) - mt7915_mcu_get_eeprom(dev, - i * MT7915_EEPROM_BLOCK_SIZE); + block_num = DIV_ROUND_UP(eeprom_size, eeprom_blk_size); + for (i = 0; i < block_num; i++) { + ret = mt7915_mcu_get_eeprom(dev, i * eeprom_blk_size); + if (ret < 0) + return ret; + } } return mt7915_check_eeprom(dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c index ca315af3905b..86ec767266cc 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7915/mcu.c @@ -2792,8 +2792,9 @@ int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset) int ret; u8 *buf; - ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(EFUSE_ACCESS), &req, - sizeof(req), true, &skb); + ret = mt76_mcu_send_and_get_msg(&dev->mt76, + MCU_EXT_QUERY(EFUSE_ACCESS), + &req, sizeof(req), true, &skb); if (ret) return ret; @@ -2818,8 +2819,9 @@ int mt7915_mcu_get_eeprom_free_block(struct mt7915_dev *dev, u8 *block_num) struct sk_buff *skb; int ret; - ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(EFUSE_FREE_BLOCK), &req, - sizeof(req), true, &skb); + ret = mt76_mcu_send_and_get_msg(&dev->mt76, + MCU_EXT_QUERY(EFUSE_FREE_BLOCK), + &req, sizeof(req), true, &skb); if (ret) return ret; -- 2.18.0