Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp702613pxb; Tue, 5 Apr 2022 19:27:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9KtXU2x6fY062cxJK3/ZpfMG0lLAMARwhtrdAYQufpRgaNDq51FtPPEhvF30j4hEzJkvW X-Received: by 2002:a17:906:79c4:b0:6cf:5489:da57 with SMTP id m4-20020a17090679c400b006cf5489da57mr6166473ejo.48.1649212029203; Tue, 05 Apr 2022 19:27:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649212029; cv=none; d=google.com; s=arc-20160816; b=Q1r9kHeQRItIM63j3VyStNxPZS2GMpFjmZziDJCoNO4iv6PQI944vetB4bM0e/kUFk tYKpN7NISoyJfHKZQ17XTrlugKj4/Asuil2UBZB3F7JpqYW99ShI27z3HGseypl0RX8k DP74MD9Yhdn+48i4hR9tVTm46QWUNUVz02PjQUztBZBEjVQHMUB6BmnFPFtF5Deudn1u KoyWPVb2V94fCFR2kspX7huK169NsOev2C+J8VTim0J0a9ObBmdts7tJhjJ83yQLHQg+ LE/bfMfYu4S7wwIvC+8Hrr/WMEIpsP46Kz/gmn7Y6mP06bicJ3xBo4ad7pF/Jsbwfi71 JPgQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4s6CJU8j2tbs5sfi+rdbUNOEt6qvEZcJnMI+UqzdvxY=; b=fYAHLqAbtCQnLgTKJMvG9sNYxFbyYFuyZuzEdBwzr6N6jdkBEXoRFALf3vY1Njr1oG wVNfhVtK/2SvCDiMelaGwD1j0lBsK4MpTaQGFK7X5KyZY6V5dFOkGg++DCAzcMStxQ2M LMz7Gh+f/g99gG7c71uQfLRW79/SMsyQl2KROHFcFmBZSJEKnm3blJ0squL7p2giyAOj TGRRbzAECsZyjTRB69WYJGvo5Nc0ugMklnqNdh4wPogtzzh2DFY7swcj1DUEun6HbJLv uXrDMTVGEbvVsKM1NPSt4ooMjA7kpwel3tNpw6imZ5GLZ1k3OpKETwDUwKQkk7uSytUv 71xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Kj/fFUFy"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f16-20020a1709062c5000b006e4aae98be2si9889376ejh.892.2022.04.05.19.26.44; Tue, 05 Apr 2022 19:27:09 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Kj/fFUFy"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345292AbiDEJnT (ORCPT + 99 others); Tue, 5 Apr 2022 05:43:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239566AbiDEIUO (ORCPT ); Tue, 5 Apr 2022 04:20:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B8E36376; Tue, 5 Apr 2022 01:16:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1A00A60AFB; Tue, 5 Apr 2022 08:16:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B323C385A0; Tue, 5 Apr 2022 08:16:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649146591; bh=R8BSE0mKHCk/KFQuqrQfNXP7Z6hcnqedSgjDwk4Zock=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kj/fFUFyhXzQO2OhFbVpu6RmMNi9kNUPnOTUFXXkYEYWAcoWZy3O55O83Q7atjL5Z 887Deh7sY+2/51MVzc+pZz5Xlh9XWPD3fbj4EzCo7Vjg7dg9b5vR7dqoMc9yC1sZYx FCFfOnAaq5d5j48hBr7OEQLA4FYbcM1Zaa9SYGs0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hao Chen , Guangbin Huang , "David S. Miller" , Sasha Levin Subject: [PATCH 5.17 0819/1126] net: hns3: add NULL pointer check for hns3_set/get_ringparam() Date: Tue, 5 Apr 2022 09:26:06 +0200 Message-Id: <20220405070431.602796664@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070407.513532867@linuxfoundation.org> References: <20220405070407.513532867@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 [ Upstream commit 4d07c5936c2508ddd1cfd49b0a91d94cb4d1f0e8 ] 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 Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- 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 1f6d6faeec24..cbf36cc86803 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_ethtool.c @@ -651,8 +651,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; } @@ -1072,8 +1072,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.34.1