[PATCH 5.13 244/800] PCI: hv: Add check for hyperv_initialized in init_hv_pci_drv()

From: Greg Kroah-Hartman
Date: Mon Jul 12 2021 - 04:26:51 EST


From: Haiyang Zhang <haiyangz@xxxxxxxxxxxxx>

[ Upstream commit 7d815f4afa87f2032b650ae1bba7534b550a6b8b ]

Add check for hv_is_hyperv_initialized() at the top of
init_hv_pci_drv(), so if the pci-hyperv driver is force-loaded on non
Hyper-V platforms, the init_hv_pci_drv() will exit immediately, without
any side effects, like assignments to hvpci_block_ops, etc.

Signed-off-by: Haiyang Zhang <haiyangz@xxxxxxxxxxxxx>
Reported-and-tested-by: Mohammad Alqayeem <mohammad.alqyeem@xxxxxxxxxxx>
Reviewed-by: Wei Liu <wei.liu@xxxxxxxxxx>
Link: https://lore.kernel.org/r/1621984653-1210-1-git-send-email-haiyangz@xxxxxxxxxxxxx
Signed-off-by: Wei Liu <wei.liu@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
drivers/pci/controller/pci-hyperv.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/drivers/pci/controller/pci-hyperv.c b/drivers/pci/controller/pci-hyperv.c
index 6511648271b2..bebe3eeebc4e 100644
--- a/drivers/pci/controller/pci-hyperv.c
+++ b/drivers/pci/controller/pci-hyperv.c
@@ -3476,6 +3476,9 @@ static void __exit exit_hv_pci_drv(void)

static int __init init_hv_pci_drv(void)
{
+ if (!hv_is_hyperv_initialized())
+ return -ENODEV;
+
/* Set the invalid domain number's bit, so it will not be used */
set_bit(HVPCI_DOM_INVALID, hvpci_dom_map);

--
2.30.2