From 62bad0c682c68bae78e24b2f36bd7640e5d28cc8 Mon Sep 17 00:00:00 2001 From: Colin Ian King Date: Sat, 24 Jul 2021 15:44:21 +0800 Subject: [PATCH] net: hns3: Fix potential null pointer defererence of null ae_dev mainline inclusion from mainline-v5.13-rc1 commit d0494135f94c7ab5a9cf7a9094fbb233275c7ba6 category: bugfix bugzilla: 173966 CVE: NA Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d0494135f94c7ab5a9cf7a9094fbb233275c7ba6 ---------------------------------------------------------------------- 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 Signed-off-by: David S. Miller Reviewed-by: Yongxin Li Signed-off-by: Junxin Chen Signed-off-by: Zheng Zengkai --- 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 3c4726f1de98..e1a32e023d82 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3_enet.c @@ -2366,9 +2366,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); } @@ -2379,9 +2379,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); } -- GitLab