diff options
author | William Henderson <william.henderson@nutanix.com> | 2023-08-31 13:36:43 +0000 |
---|---|---|
committer | John Levon <john.levon@nutanix.com> | 2023-09-15 12:59:39 +0100 |
commit | 4b42857bfcc61a3cc3b7c23e7db8235182492e0c (patch) | |
tree | 529f7bc849ce14f2a7cc7eae358c5ed58dbe76da | |
parent | 8f9b9f95ab68763eb8f386985795ce5b14b1a607 (diff) | |
download | libvfio-user-4b42857bfcc61a3cc3b7c23e7db8235182492e0c.zip libvfio-user-4b42857bfcc61a3cc3b7c23e7db8235182492e0c.tar.gz libvfio-user-4b42857bfcc61a3cc3b7c23e7db8235182492e0c.tar.bz2 |
introduce iov_free
Signed-off-by: William Henderson <william.henderson@nutanix.com>
-rw-r--r-- | lib/common.h | 11 | ||||
-rw-r--r-- | lib/libvfio-user.c | 10 | ||||
-rw-r--r-- | lib/migration.c | 2 |
3 files changed, 17 insertions, 6 deletions
diff --git a/lib/common.h b/lib/common.h index 36c1a5e..5f07bb7 100644 --- a/lib/common.h +++ b/lib/common.h @@ -39,6 +39,7 @@ #include <limits.h> #include <stdint.h> +#include <sys/uio.h> #define UNUSED __attribute__((unused)) #define EXPORT __attribute__((visibility("default"))) @@ -103,6 +104,16 @@ get_bitmap_size(size_t region_size, size_t pgsize) return ROUND_UP(nr_pages, sizeof(uint64_t) * CHAR_BIT) / CHAR_BIT; } +static inline void +iov_free(struct iovec *iov) +{ + if (iov->iov_base != NULL) { + free(iov->iov_base); + iov->iov_base = NULL; + } + iov->iov_len = 0; +} + #ifdef UNIT_TEST #define MOCK_DEFINE(f) \ diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c index 03b1f9d..01c520e 100644 --- a/lib/libvfio-user.c +++ b/lib/libvfio-user.c @@ -970,7 +970,7 @@ handle_migration_device_feature_get(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg, + sizeof(struct vfio_user_device_feature_migration); if (req->argsz < msg->out.iov.iov_len) { - msg->out.iov.iov_len = 0; + iov_free(&msg->out.iov); return ERROR_INT(EINVAL); } @@ -1050,7 +1050,7 @@ handle_dma_device_feature_get(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg, msg->out.iov.iov_len = header_size + bitmap_size; if (req->argsz < msg->out.iov.iov_len) { - msg->out.iov.iov_len = 0; + iov_free(&msg->out.iov); return ERROR_INT(EINVAL); } @@ -1076,7 +1076,7 @@ handle_dma_device_feature_get(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg, bitmap); if (ret < 0) { - msg->out.iov.iov_len = 0; + iov_free(&msg->out.iov); } return ret; @@ -1150,7 +1150,7 @@ handle_device_feature(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg) if (req->argsz < msg->out.iov.iov_len) { vfu_log(vfu_ctx, LOG_ERR, "bad argsz (%d<%ld)", req->argsz, msg->out.iov.iov_len); - msg->out.iov.iov_len = 0; + iov_free(&msg->out.iov); return ERROR_INT(EINVAL); } @@ -1193,7 +1193,7 @@ handle_device_feature(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg) if (req->argsz < msg->out.iov.iov_len) { vfu_log(vfu_ctx, LOG_ERR, "bad argsz (%d<%ld)", req->argsz, msg->out.iov.iov_len); - msg->out.iov.iov_len = 0; + iov_free(&msg->out.iov); return ERROR_INT(EINVAL); } diff --git a/lib/migration.c b/lib/migration.c index 8901a00..cc6d271 100644 --- a/lib/migration.c +++ b/lib/migration.c @@ -337,7 +337,7 @@ handle_mig_data_read(vfu_ctx_t *vfu_ctx, vfu_msg_t *msg) if (ret < 0) { vfu_log(vfu_ctx, LOG_ERR, "read_data callback failed, errno=%d", errno); - msg->out.iov.iov_len = 0; + iov_free(&msg->out.iov); return ret; } |