From 0b9ba6a3308396569e189dacb2bbea56943e6dd3 Mon Sep 17 00:00:00 2001 From: GangCao Date: Thu, 1 Sep 2022 21:29:59 -0400 Subject: [PATCH] lib/vmd: return -1 if NVMe driver is not found Fix issue: potential NULL pointer dereference Change-Id: I23f90616661fdebaacb041bc9f47284231601136 Signed-off-by: GangCao Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14329 Tested-by: SPDK CI Jenkins Reviewed-by: Dong Yi Reviewed-by: Konrad Sztyber Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Community-CI: Mellanox Build Bot --- lib/vmd/vmd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/vmd/vmd.c b/lib/vmd/vmd.c index 92595f993..f3181454c 100644 --- a/lib/vmd/vmd.c +++ b/lib/vmd/vmd.c @@ -882,6 +882,7 @@ vmd_init_end_device(struct vmd_pci_device *dev) { struct vmd_pci_bus *bus = dev->bus; struct vmd_adapter *vmd; + struct spdk_pci_driver *driver; uint8_t bdf[32]; int rc; @@ -898,7 +899,9 @@ vmd_init_end_device(struct vmd_pci_device *dev) SPDK_INFOLOG(vmd, "Initializing NVMe device at %s\n", bdf); dev->pci.parent = dev->bus->vmd->pci; - rc = spdk_pci_hook_device(spdk_pci_nvme_get_driver(), &dev->pci); + driver = spdk_pci_nvme_get_driver(); + assert(driver != NULL); + rc = spdk_pci_hook_device(driver, &dev->pci); if (rc != 0) { SPDK_ERRLOG("Failed to hook device %s: %s\n", bdf, spdk_strerror(-rc)); return -1;