diff options
author | John Levon <john.levon@nutanix.com> | 2021-04-13 09:45:02 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-13 09:45:02 +0100 |
commit | 06e409788131d612d4b6d6a2ef15329f68e04da0 (patch) | |
tree | b534425bf7d6d4ffc6230704fad56784336f39a2 | |
parent | ba6abc4ce1d01d7253d044f2ec59c4b484d098b9 (diff) | |
download | libvfio-user-06e409788131d612d4b6d6a2ef15329f68e04da0.zip libvfio-user-06e409788131d612d4b6d6a2ef15329f68e04da0.tar.gz libvfio-user-06e409788131d612d4b6d6a2ef15329f68e04da0.tar.bz2 |
correct DMA region add/remove returns (#427)
Code was expecting -errno style returns, but the DMA code didn't do this.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
-rw-r--r-- | lib/dma.c | 30 | ||||
-rw-r--r-- | lib/dma.h | 4 |
2 files changed, 18 insertions, 16 deletions
@@ -160,7 +160,7 @@ MOCK_DEFINE(dma_controller_remove_region)(dma_controller_t *dma, "failed to dma_unregister() DMA region [%p, %p): %s", region->info.iova.iov_base, iov_end(®ion->info.iova), strerror(err)); - return err; + return -err; } assert(region->refcnt == 0); @@ -274,7 +274,8 @@ MOCK_DEFINE(dma_controller_add_region)(dma_controller_t *dma, if (offset != region->offset) { vfu_log(dma->vfu_ctx, LOG_ERR, "bad offset for new DMA region " "%s; existing=%#lx", rstr, region->offset); - goto err; + ret = -EINVAL; + goto out; } if (!fds_are_same_file(region->fd, fd)) { /* @@ -285,12 +286,14 @@ MOCK_DEFINE(dma_controller_add_region)(dma_controller_t *dma, */ vfu_log(dma->vfu_ctx, LOG_ERR, "bad fd for new DMA region %s; " "existing=%d", rstr, region->fd); - goto err; + ret = -EINVAL; + goto out; } if (region->info.prot != prot) { vfu_log(dma->vfu_ctx, LOG_ERR, "bad prot for new DMA region " "%s; existing=%#x", rstr, region->info.prot); - goto err; + ret = -EINVAL; + goto out; } return idx; } @@ -303,14 +306,15 @@ MOCK_DEFINE(dma_controller_add_region)(dma_controller_t *dma, vfu_log(dma->vfu_ctx, LOG_INFO, "new DMA region %s overlaps with " "DMA region [%p, %p)", rstr, region->info.iova.iov_base, iov_end(®ion->info.iova)); - goto err; + ret = -EINVAL; + goto out; } } if (dma->nregions == dma->max_regions) { - idx = dma->max_regions; vfu_log(dma->vfu_ctx, LOG_ERR, "hit max regions %d", dma->max_regions); - goto err; + ret = -EINVAL; + goto out; } idx = dma->nregions; @@ -320,7 +324,8 @@ MOCK_DEFINE(dma_controller_add_region)(dma_controller_t *dma, page_size = fd_get_blocksize(fd); if (page_size < 0) { vfu_log(dma->vfu_ctx, LOG_ERR, "bad page size %d", page_size); - goto err; + ret = -EINVAL; + goto out; } } page_size = MAX(page_size, getpagesize()); @@ -346,16 +351,15 @@ MOCK_DEFINE(dma_controller_add_region)(dma_controller_t *dma, vfu_log(dma->vfu_ctx, LOG_WARNING, "failed to close fd %d: %m", region->fd); } - goto err; + goto out; } } + ret = idx; dma->nregions++; - return idx; - -err: - return -idx - 1; +out: + return ret; } int @@ -109,9 +109,7 @@ dma_controller_destroy(dma_controller_t *dma); /* Registers a new memory region. * Returns: * - On success, a non-negative region number - * - On failure, a negative integer (-x - 1) where x is the region number - * where this region would have been mapped to if the call could succeed - * (e.g. due to conflict with existing region). + * - On failure, -errno. */ MOCK_DECLARE(int, dma_controller_add_region, dma_controller_t *dma, vfu_dma_addr_t dma_addr, size_t size, int fd, off_t offset, |