From fd3599321965f1bfdaed7da818e7b4bdd24c28c6 Mon Sep 17 00:00:00 2001 From: yidong0635 Date: Wed, 17 Mar 2021 05:23:27 +0800 Subject: [PATCH] vfio_user_pci: put close(device->fd) in cleanup. These three goto cases are using device->fd, so put them in cleanup, it has no impact on vfio_user_dev_setup failed. Signed-off-by: yidong0635 Change-Id: I28028dda2977cf8158e703afa5b8af38c48f3d85 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6922 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto --- lib/vfio_user/vfio_user_pci.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/vfio_user/vfio_user_pci.c b/lib/vfio_user/vfio_user_pci.c index 25fab78cc..0878399b1 100644 --- a/lib/vfio_user/vfio_user_pci.c +++ b/lib/vfio_user/vfio_user_pci.c @@ -388,7 +388,6 @@ spdk_vfio_user_setup(const char *path) ret = vfio_user_get_dev_info(device, &dev_info, sizeof(dev_info)); if (ret) { SPDK_ERRLOG("Device get info failed\n"); - close(device->fd); goto cleanup; } device->pci_regions = dev_info.num_regions; @@ -396,7 +395,6 @@ spdk_vfio_user_setup(const char *path) ret = vfio_device_map_bars_and_config_region(device); if (ret) { - close(device->fd); goto cleanup; } @@ -404,7 +402,6 @@ spdk_vfio_user_setup(const char *path) ret = vfio_device_dma_map(device); if (ret) { SPDK_ERRLOG("Container DMA map failed\n"); - close(device->fd); goto cleanup; } @@ -414,6 +411,7 @@ spdk_vfio_user_setup(const char *path) return device; cleanup: + close(device->fd); free(device); return NULL; }