aboutsummaryrefslogtreecommitdiff
path: root/lib/dma.c
diff options
context:
space:
mode:
authorThanos Makatos <thanos.makatos@nutanix.com>2020-03-25 07:44:51 -0400
committerThanos Makatos <thanos.makatos@nutanix.com>2020-03-25 10:36:29 -0400
commit2312b8053699c9df1a6b162ddc51e1d1f049e1f9 (patch)
tree916027f3546a8f50bf12d0d8388c41a6801b0f70 /lib/dma.c
parent8435c007567fdd0a92ed1f4e8dd7b60bb09ae116 (diff)
downloadlibvfio-user-2312b8053699c9df1a6b162ddc51e1d1f049e1f9.zip
libvfio-user-2312b8053699c9df1a6b162ddc51e1d1f049e1f9.tar.gz
libvfio-user-2312b8053699c9df1a6b162ddc51e1d1f049e1f9.tar.bz2
don't close invalid fds and log error if close fails
This helps reduce noise and debugging. Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib/dma.c')
-rw-r--r--lib/dma.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/dma.c b/lib/dma.c
index 2897b1a..deb5511 100644
--- a/lib/dma.c
+++ b/lib/dma.c
@@ -94,9 +94,10 @@ _dma_controller_do_remove_region(lm_ctx_t *lm_ctx, dma_memory_region_t *region)
lm_log(lm_ctx, LM_DBG, "failed to unmap fd=%d vaddr=%#lx-%#lx\n",
region->fd, region->virt_addr, region->size);
}
- err = close(region->fd);
- if (err != 0) {
- lm_log(lm_ctx, LM_DBG, "failed to close fd=%d\n", region->fd);
+ if (region->fd != -1) {
+ if (close(region->fd) == -1) {
+ lm_log(lm_ctx, LM_DBG, "failed to close fd %d: %m\n", region->fd);
+ }
}
}
@@ -224,7 +225,11 @@ dma_controller_add_region(lm_ctx_t *lm_ctx, dma_controller_t *dma,
if (region->virt_addr == MAP_FAILED) {
lm_log(lm_ctx, LM_ERR, "failed to memory map DMA region %lx-%lx: %s\n",
dma_addr, dma_addr + size, strerror(errno));
- close(region->fd);
+ if (region->fd != -1) {
+ if (close(region->fd) == -1) {
+ lm_log(lm_ctx, LM_DBG, "failed to close fd %d: %m\n", region->fd);
+ }
+ }
goto err;
}
dma->nregions++;