From patchwork Fri Apr 9 16:37:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 12194487 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A23D4C433ED for ; Fri, 9 Apr 2021 16:37:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5447A600EF for ; Fri, 9 Apr 2021 16:37:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234011AbhDIQhs (ORCPT ); Fri, 9 Apr 2021 12:37:48 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:52702 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232395AbhDIQhq (ORCPT ); Fri, 9 Apr 2021 12:37:46 -0400 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1lUu8M-0005Xp-Cg; Fri, 09 Apr 2021 16:37:26 +0000 From: Colin King To: Yisen Zhuang , Salil Mehta , "David S . Miller" , Jakub Kicinski , Huazhong Tan , Jiaran Zhang , netdev@vger.kernel.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] net: hns3: Fix potential null pointer defererence of null ae_dev Date: Fri, 9 Apr 2021 17:37:26 +0100 Message-Id: <20210409163726.670672-1-colin.king@canonical.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Colin Ian King The reset_prepare and reset_done calls have a null pointer check on ae_dev however ae_dev is being dereferenced via the call to ns3_is_phys_func with the ae->pdev argument. Fix this by performing a null pointer check on ae_dev and hence short-circuiting the dereference to ae_dev on the call to ns3_is_phys_func. Addresses-Coverity: ("Dereference before null check") Fixes: 715c58e94f0d ("net: hns3: add suspend and resume pm_ops") Signed-off-by: Colin Ian King --- drivers/net/ethernet/hisilicon/hns3/hns3_enet.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c index 25afe5a3348c..c21dd11baed9 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -2369,9 +2369,9 @@ static int __maybe_unused hns3_suspend(struct device *dev) { struct hnae3_ae_dev *ae_dev = dev_get_drvdata(dev); - if (hns3_is_phys_func(ae_dev->pdev)) { + if (ae_dev && hns3_is_phys_func(ae_dev->pdev)) { dev_info(dev, "Begin to suspend.\n"); - if (ae_dev && ae_dev->ops && ae_dev->ops->reset_prepare) + if (ae_dev->ops && ae_dev->ops->reset_prepare) ae_dev->ops->reset_prepare(ae_dev, HNAE3_FUNC_RESET); } @@ -2382,9 +2382,9 @@ static int __maybe_unused hns3_resume(struct device *dev) { struct hnae3_ae_dev *ae_dev = dev_get_drvdata(dev); - if (hns3_is_phys_func(ae_dev->pdev)) { + if (ae_dev && hns3_is_phys_func(ae_dev->pdev)) { dev_info(dev, "Begin to resume.\n"); - if (ae_dev && ae_dev->ops && ae_dev->ops->reset_done) + if (ae_dev->ops && ae_dev->ops->reset_done) ae_dev->ops->reset_done(ae_dev); }