diff options
author | John Levon <john.levon@nutanix.com> | 2021-04-13 10:35:59 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-13 10:35:59 +0100 |
commit | 451b4180c18722b11047ba6c7554e24dde0004f9 (patch) | |
tree | b4c14a5bc834701f5fff7fc7fc498c7b023d9c7b /lib/libvfio-user.c | |
parent | 944da3686dc5e70e104fadf0d3acd616312d1388 (diff) | |
download | libvfio-user-451b4180c18722b11047ba6c7554e24dde0004f9.zip libvfio-user-451b4180c18722b11047ba6c7554e24dde0004f9.tar.gz libvfio-user-451b4180c18722b11047ba6c7554e24dde0004f9.tar.bz2 |
dma: use ERROR_INT()
The first in a series excising the use of the "return -errno" idiom. This is a
non-standard usage, and in userspace, we have "errno" for delivering side-band
error values. As there have been multiple bugs from not using standard error
return methods like -1+errno or NULL+errno, let's do that.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib/libvfio-user.c')
-rw-r--r-- | lib/libvfio-user.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c index 0440351..f4aa804 100644 --- a/lib/libvfio-user.c +++ b/lib/libvfio-user.c @@ -532,11 +532,12 @@ handle_dma_map_or_unmap(vfu_ctx_t *vfu_ctx, uint32_t size, bool map, region->size, fd, region->offset, region->prot); if (ret < 0) { + ret = -errno; + vfu_log(vfu_ctx, LOG_ERR, "failed to add DMA region %s: %m", + rstr); if (fd != -1) { close(fd); } - vfu_log(vfu_ctx, LOG_ERR, "failed to add DMA region %s: %s", - rstr, strerror(-ret)); break; } @@ -553,8 +554,9 @@ handle_dma_map_or_unmap(vfu_ctx_t *vfu_ctx, uint32_t size, bool map, vfu_ctx->dma_unregister, vfu_ctx); if (ret < 0) { - vfu_log(vfu_ctx, LOG_ERR, "failed to remove DMA region %s: %s", - rstr, strerror(-ret)); + ret = -errno; + vfu_log(vfu_ctx, LOG_ERR, "failed to remove DMA region %s: %m", + rstr); break; } } @@ -603,6 +605,7 @@ handle_dirty_pages_get(vfu_ctx_t *vfu_ctx, r->bitmap.size, (char**)&((*iovecs)[i].iov_base)); if (ret != 0) { + ret = -errno; goto out; } (*iovecs)[i].iov_len = r->bitmap.size; @@ -637,8 +640,12 @@ MOCK_DEFINE(handle_dirty_pages)(vfu_ctx_t *vfu_ctx, uint32_t size, if (dirty_bitmap->flags & VFIO_IOMMU_DIRTY_PAGES_FLAG_START) { ret = dma_controller_dirty_page_logging_start(vfu_ctx->dma, migration_get_pgsize(vfu_ctx->migration)); + if (ret == -1) { + ret = -errno; + } } else if (dirty_bitmap->flags & VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP) { - ret = dma_controller_dirty_page_logging_stop(vfu_ctx->dma); + dma_controller_dirty_page_logging_stop(vfu_ctx->dma); + ret = 0; } else if (dirty_bitmap->flags & VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP) { ret = handle_dirty_pages_get(vfu_ctx, iovecs, nr_iovecs, (struct vfio_iommu_type1_dirty_bitmap_get*)(dirty_bitmap + 1), @@ -1520,7 +1527,7 @@ vfu_map_sg(vfu_ctx_t *vfu_ctx, const dma_sg_t *sg, ret = dma_map_sg(vfu_ctx->dma, sg, iov, cnt); if (ret < 0) { - return ERROR_INT(-ret); + return -1; } return 0; |