diff options
author | Thanos Makatos <thanos.makatos@nutanix.com> | 2020-12-01 10:17:20 -0500 |
---|---|---|
committer | Thanos <tmakatos@gmail.com> | 2020-12-01 15:41:25 +0000 |
commit | 892de236f336f5cee84a864da2639e7c64998e98 (patch) | |
tree | 30a70bb30028d0a1d8735ee4af17eab17c346fa7 | |
parent | 2bf85d990fd93abd2076438040406fa33b1e1e01 (diff) | |
download | libvfio-user-892de236f336f5cee84a864da2639e7c64998e98.zip libvfio-user-892de236f336f5cee84a864da2639e7c64998e98.tar.gz libvfio-user-892de236f336f5cee84a864da2639e7c64998e98.tar.bz2 |
drop unnecessary restore_fd
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
-rw-r--r-- | lib/irq.c | 14 | ||||
-rw-r--r-- | lib/libvfio-user.c | 8 | ||||
-rw-r--r-- | test/unit-tests.c | 8 |
3 files changed, 13 insertions, 17 deletions
@@ -171,14 +171,12 @@ irqs_set_data_eventfd(vfu_ctx_t *vfu_ctx, struct vfio_irq_set *irq_set, vfu_ctx->irqs->efds[i] = -1; } - if (data[j] >= 0) { /* TODO IIUC this will always be >= 0? */ - vfu_ctx->irqs->efds[i] = data[j]; - /* - * We've already checked in handle_device_set_irqs that - * nr_fds == irq_set->count. - */ - consume_fd(data, irq_set->count, j); - } + assert(data[j] >= 0); + /* + * We've already checked in handle_device_set_irqs that + * nr_fds == irq_set->count. + */ + vfu_ctx->irqs->efds[i] = consume_fd(data, irq_set->count, j); vfu_log(vfu_ctx, VFU_DBG, "event fd[%d]=%d", i, vfu_ctx->irqs->efds[i]); } diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c index 2d77555..964091c 100644 --- a/lib/libvfio-user.c +++ b/lib/libvfio-user.c @@ -514,12 +514,6 @@ consume_fd(int *fds, size_t nr_fds, size_t index) return fd; } -void -restore_fd(int *fds, size_t index, int fd) -{ - fds[index] = fd; -} - /* * Handles a DMA map/unmap request. * @@ -576,7 +570,7 @@ handle_dma_map_or_unmap(vfu_ctx_t *vfu_ctx, uint32_t size, bool map, dma_regions[i].offset); if (ret < 0) { if (fd != -1) { - restore_fd(fds, fdi - 1, fd); + close(fd); } vfu_log(vfu_ctx, VFU_INF, "failed to add DMA region %#lx-%#lx offset=%#lx fd=%d: %s", diff --git a/test/unit-tests.c b/test/unit-tests.c index 306f70a..a20f4fe 100644 --- a/test/unit-tests.c +++ b/test/unit-tests.c @@ -140,8 +140,8 @@ test_dma_add_regions_mixed(void **state __attribute__((unused))) } /* - * Tests that handle_dma_map_or_unmap sets the correct number of file - * descriptors when failing halfway through. + * Tests that handle_dma_map_or_unmap closes unconsumed file descriptors when + * failing halfway through. */ static void test_dma_add_regions_mixed_partial_failure(void **state __attribute__((unused))) @@ -196,6 +196,10 @@ test_dma_add_regions_mixed_partial_failure(void **state __attribute__((unused))) expect_value(__wrap_dma_controller_add_region, offset, r[2].offset); will_return(__wrap_dma_controller_add_region, -0x1234); + patch(close); + expect_value(__wrap_close, fd, 0xb); + will_return(__wrap_close, 0); + assert_int_equal(-0x1234, handle_dma_map_or_unmap(&vfu_ctx, ARRAY_SIZE(r) * sizeof(struct vfio_user_dma_region), |