Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp3524191pxb; Sat, 26 Mar 2022 22:20:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzyYPm5NTlat0bsDQSFcm5vFTvK8ZROiTvHYizsyObMBrT+uhvaTTi9uLQFfQZkBzuEn/KA X-Received: by 2002:a17:90b:4b0e:b0:1c6:f499:1cc9 with SMTP id lx14-20020a17090b4b0e00b001c6f4991cc9mr34246064pjb.133.1648358431181; Sat, 26 Mar 2022 22:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648358431; cv=none; d=google.com; s=arc-20160816; b=keHnNsr0wsUSOBSoqAbyTJSIWkBkt29VGSzlg5kFwc0QkqE/eQUK7bWVt1xSXi0l3i 5NtnIoUgdET0lMuLb5UqLiGU49gY1wiQ+fj5/N2pw2fFP/G0rIwKhL/0w4N1pFBF1Ha3 I2iq9Ya3GIKRsrrQVPPpLu7edaO/F7BIejf8tJxTdCqkFuBwL/DVK1IPW+x7lsIuBQ9u 0n6AeG92BRyiNldrnwG6SqcjzOxRX9+8Iam0wnY7gwnCWxcL+L/eDYhnqadv5kn6fhSF m5RGNteBtlhMWQ3STF+7BcLyJKNGjNe66lIsjnvq3PSw52DkkrzSUnPPgk/cqrrNPuCa nc0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Hd4wBRddUfhb51GBiWqC5NB2sgIvX1j99W2nOCPax3Y=; b=hmXKH14bAn9Ix2MdSRyU8jvgwH1JHv8CWOUX0dLorcleoC5+A7psBZxddwuG9Piu7y pgB6vPk+S3uo5n43U4EBbADc4D1yDQ0d5TMHywUFV1scNMpJ1LT809xmhghw8EQF2hEz 2VDWrEdPRBMj94ZTxM70q+39yrblnLjcQ2o5NjwdKMiEBylsdETEdSEs2BEi+EA2Jcaz XNl/VsqjnndxFu+Rwa5Jy0HYmruqYi2yNnTk5C6821LiBhMYkuJmuf+b3OTyONnurkMb jccNKExZMyezjO7buFZvYrbOQt38qmiHCfkGhhp5aUaz+QYIHzaQNuuGjnPFENVABx1G ed3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b2-20020a63cf42000000b003816043eee6si7178168pgj.219.2022.03.26.22.20.08; Sat, 26 Mar 2022 22:20:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232424AbiCZJ65 (ORCPT + 99 others); Sat, 26 Mar 2022 05:58:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232303AbiCZJ6O (ORCPT ); Sat, 26 Mar 2022 05:58:14 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83DB61F606; Sat, 26 Mar 2022 02:56:38 -0700 (PDT) Received: from kwepemi500010.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KQZ7n2CSwzfZX2; Sat, 26 Mar 2022 17:55:01 +0800 (CST) Received: from kwepemm600016.china.huawei.com (7.193.23.20) by kwepemi500010.china.huawei.com (7.221.188.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Sat, 26 Mar 2022 17:56:36 +0800 Received: from localhost.localdomain (10.67.165.24) by kwepemm600016.china.huawei.com (7.193.23.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Sat, 26 Mar 2022 17:56:36 +0800 From: Guangbin Huang To: , CC: , , , , Subject: [PATCH net 5/6] net: hns3: add NULL pointer check for hns3_set/get_ringparam() Date: Sat, 26 Mar 2022 17:51:04 +0800 Message-ID: <20220326095105.54075-6-huangguangbin2@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220326095105.54075-1-huangguangbin2@huawei.com> References: <20220326095105.54075-1-huangguangbin2@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm600016.china.huawei.com (7.193.23.20) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org From: Hao Chen When pci devices init failed and haven't reinit, priv->ring is NULL and hns3_set/get_ringparam() will access priv->ring. it causes call trace. So, add NULL pointer check for hns3_set/get_ringparam() to avoid this situation. Fixes: 5668abda0931 ("net: hns3: add support for set_ringparam") Signed-off-by: Hao Chen Signed-off-by: Guangbin Huang --- drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c index 49e7b022caaa..f4da77452126 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c @@ -653,8 +653,8 @@ static void hns3_get_ringparam(struct net_device *netdev, struct hnae3_handle *h = priv->ae_handle; int rx_queue_index = h->kinfo.num_tqps; - if (hns3_nic_resetting(netdev)) { - netdev_err(netdev, "dev resetting!"); + if (hns3_nic_resetting(netdev) || !priv->ring) { + netdev_err(netdev, "failed to get ringparam value, due to dev resetting or uninited\n"); return; } @@ -1074,8 +1074,14 @@ static int hns3_check_ringparam(struct net_device *ndev, { #define RX_BUF_LEN_2K 2048 #define RX_BUF_LEN_4K 4096 - if (hns3_nic_resetting(ndev)) + + struct hns3_nic_priv *priv = netdev_priv(ndev); + + if (hns3_nic_resetting(ndev) || !priv->ring) { + netdev_err(ndev, "failed to set ringparam value, due to dev resetting or uninited\n"); return -EBUSY; + } + if (param->rx_mini_pending || param->rx_jumbo_pending) return -EINVAL; -- 2.33.0