From ccc1c72ca2079dd5848ac254a2e6b5603ac5a7ec Mon Sep 17 00:00:00 2001 From: Ziye Yang Date: Tue, 29 Oct 2019 17:56:13 +0800 Subject: [PATCH] vmd: fix the memory leak issue if vmd address cannot assigned. Also cleanup some codes. Change-Id: I45ff18cd2afcf38c50b073e80448ba5e267e3ef7 Signed-off-by: Ziye Yang Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/472664 Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto --- lib/vmd/vmd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/vmd/vmd.c b/lib/vmd/vmd.c index 7fcd8d684..a60e64079 100644 --- a/lib/vmd/vmd.c +++ b/lib/vmd/vmd.c @@ -73,6 +73,7 @@ static void vmd_align_base_addrs(struct vmd_adapter *vmd, uint32_t alignment) { uint32_t pad; + /* * Device is not in hot plug path, align the base address remaining from membar 1. */ @@ -891,6 +892,7 @@ vmd_scan_single_bus(struct vmd_pci_bus *bus, struct vmd_pci_device *parent_bridg } else { SPDK_DEBUGLOG(SPDK_LOG_VMD, "Removing failed device:%p\n", new_dev); TAILQ_REMOVE(&bus->dev_list, new_dev, tailq); + free(new_dev); if (dev_cnt) { dev_cnt--; } @@ -1003,12 +1005,13 @@ vmd_scan_pcibus(struct vmd_pci_bus *bus) return dev_cnt; } - static int vmd_map_bars(struct vmd_adapter *vmd, struct spdk_pci_device *dev) { - int rc = spdk_pci_device_map_bar(dev, 0, (void **)&vmd->cfg_vaddr, - &vmd->cfgbar, &vmd->cfgbar_size); + int rc; + + rc = spdk_pci_device_map_bar(dev, 0, (void **)&vmd->cfg_vaddr, + &vmd->cfgbar, &vmd->cfgbar_size); if (rc == 0) { rc = spdk_pci_device_map_bar(dev, 2, (void **)&vmd->mem_vaddr, &vmd->membar, &vmd->membar_size);