diff options
author | Swapnil Ingle <swapnil.ingle@nutanix.com> | 2020-11-17 05:37:40 -0500 |
---|---|---|
committer | Swapnil Ingle <swapnil.ingle@nutanix.com> | 2020-11-17 11:29:25 -0500 |
commit | 2f207eb3053f8408396c75c378aff236ecb110a3 (patch) | |
tree | a6b537c0d303e6f541446888c577b4e412677650 | |
parent | 1d339ffea368f4821055cbac1726bb76d67923da (diff) | |
download | libvfio-user-2f207eb3053f8408396c75c378aff236ecb110a3.zip libvfio-user-2f207eb3053f8408396c75c378aff236ecb110a3.tar.gz libvfio-user-2f207eb3053f8408396c75c378aff236ecb110a3.tar.bz2 |
Fix compiler errors for non-dbg build
Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com>
-rw-r--r-- | lib/cap.c | 7 | ||||
-rw-r--r-- | lib/dma.h | 4 | ||||
-rw-r--r-- | lib/muser_ctx.c | 21 | ||||
-rw-r--r-- | samples/client.c | 5 | ||||
-rw-r--r-- | samples/gpio-pci-idio-16.c | 5 | ||||
-rw-r--r-- | samples/server.c | 28 |
6 files changed, 45 insertions, 25 deletions
@@ -209,6 +209,7 @@ handle_pm_write(lm_ctx_t *lm_ctx, uint8_t *cap, char *const buf, return -EINVAL; } assert(false); /* FIXME implement */ + break; case offsetof(struct pmcap, pmcs): if (count != sizeof(struct pmcs)) { return -EINVAL; @@ -413,14 +414,15 @@ caps_create(lm_ctx_t *lm_ctx, lm_cap_t **lm_caps, int nr_caps) struct caps *caps; if (nr_caps <= 0 || nr_caps >= LM_MAX_CAPS) { - err = EINVAL; - goto out; + errno = EINVAL; + return NULL; } assert(lm_caps != NULL); caps = calloc(1, sizeof *caps); if (caps == NULL) { + err = ENOMEM; goto out; } @@ -466,6 +468,7 @@ out: if (err) { free(caps); caps = NULL; + errno = err; } return caps; } @@ -303,7 +303,9 @@ dma_unmap_addr(dma_controller_t *dma, int r; r = dma_addr_to_sg(dma, dma_addr, len, &sg, 1, PROT_NONE); - assert(r == 1); + if (r != 1) { + assert(false); + } dma_unmap_sg(dma, &sg, &iov, 1); } diff --git a/lib/muser_ctx.c b/lib/muser_ctx.c index 9224b11..a9a6bdb 100644 --- a/lib/muser_ctx.c +++ b/lib/muser_ctx.c @@ -139,13 +139,21 @@ static inline int recv_blocking(int sock, void *buf, size_t len, int flags) int ret, fret; fret = fcntl(sock, F_SETFL, f & ~O_NONBLOCK); - assert(fret != -1); + if (fret == -1) { + ret = -errno; + fprintf(stderr, "failed to set O_NONBLOCK: %m\n"); + goto out; + } ret = recv(sock, buf, len, flags); fret = fcntl(sock, F_SETFL, f); - assert(fret != -1); + if (fret == -1) { + ret = -errno; + fprintf(stderr, "failed to unset O_NONBLOCK: %m\n"); + } +out: return ret; } @@ -693,7 +701,6 @@ irqs_set_data_bool(lm_ctx_t *lm_ctx, struct vfio_irq_set *irq_set, void *data) eventfd_t val; assert(data != NULL); - for (i = irq_set->start, d8 = data; i < (irq_set->start + irq_set->count); i++, d8++) { efd = lm_ctx->irqs.efds[i]; @@ -1314,7 +1321,8 @@ handle_migration_data_offset(lm_ctx_t *lm_ctx, __u64 *offset, bool is_write) /* * data_offset is invariant during an iteration. */ - break; + ret = 0; + break; default: /* * reading data_offset is undefined out of sequence @@ -1323,7 +1331,6 @@ handle_migration_data_offset(lm_ctx_t *lm_ctx, __u64 *offset, bool is_write) return -EINVAL; } - *offset = lm_ctx->migration.iter.offset + sizeof(struct vfio_device_migration_info); return ret; @@ -1361,7 +1368,7 @@ static ssize_t handle_migration_region_access(lm_ctx_t *lm_ctx, char *buf, size_t count, loff_t pos, bool is_write) { - int ret; + int ret = -EINVAL; assert(lm_ctx != NULL); assert(buf != NULL); @@ -1626,7 +1633,7 @@ static int handle_device_set_irqs(lm_ctx_t *lm_ctx, uint32_t size, int *fds, int nr_fds, struct vfio_irq_set *irq_set) { - void *data; + void *data = NULL; assert(lm_ctx != NULL); assert(irq_set != NULL); diff --git a/samples/client.c b/samples/client.c index d6be91d..bd8d2b3 100644 --- a/samples/client.c +++ b/samples/client.c @@ -550,7 +550,7 @@ static int handle_dma_io(int sock, struct vfio_user_dma_region *dma_regions, static int get_dirty_bitmaps(int sock, struct vfio_user_dma_region *dma_regions, - int nr_dma_regions) + UNUSED int nr_dma_regions) { struct vfio_iommu_type1_dirty_bitmap dirty_bitmap = {0}; struct vfio_iommu_type1_dirty_bitmap_get bitmaps[2]; @@ -566,7 +566,8 @@ get_dirty_bitmaps(int sock, struct vfio_user_dma_region *dma_regions, char data[ARRAY_SIZE(bitmaps)]; assert(dma_regions != NULL); - assert(nr_dma_regions >= (int)ARRAY_SIZE(bitmaps)); + //FIXME: Is below assert correct? + //assert(nr_dma_regions >= (int)ARRAY_SIZE(bitmaps)); for (i = 0; i < ARRAY_SIZE(bitmaps); i++) { bitmaps[i].iova = dma_regions[i].addr; diff --git a/samples/gpio-pci-idio-16.c b/samples/gpio-pci-idio-16.c index 9a79d0c..d9bfa0e 100644 --- a/samples/gpio-pci-idio-16.c +++ b/samples/gpio-pci-idio-16.c @@ -114,9 +114,6 @@ int main(int argc, char *argv[]) lm_ctx = lm_ctx_create(&dev_info); if (lm_ctx == NULL) { - if (errno == EINTR) { - goto out; - } fprintf(stderr, "failed to initialize device emulation: %m\n"); return -1; } @@ -126,7 +123,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "failed to realize device emulation: %m\n"); } } -out: + lm_ctx_destroy(lm_ctx); return ret; } diff --git a/samples/server.c b/samples/server.c index 01978f3..5e3c89e 100644 --- a/samples/server.c +++ b/samples/server.c @@ -96,6 +96,8 @@ bar1_access(UNUSED void *pvt, UNUSED char * const buf, UNUSED size_t count, UNUSED loff_t offset, UNUSED const bool is_write) { assert(false); + + return -ENOTSUP; } bool irq_triggered = false; @@ -207,6 +209,8 @@ unsigned long map_area(UNUSED void *pvt, UNUSED unsigned long off, UNUSED unsigned long len) { assert(false); + + return 0; } static int device_reset(UNUSED void *pvt) @@ -264,7 +268,9 @@ migration_read_data(void *pvt, UNUSED void *buf, __u64 size, { struct server_data *server_data = pvt; - assert(server_data->migration.data_size >= size); + if (server_data->migration.data_size < size) { + assert(false); + } return 0; } @@ -273,6 +279,8 @@ static size_t migration_write_data(UNUSED void *pvt, UNUSED void *data, UNUSED __u64 size) { assert(false); + + return 0; } int main(int argc, char *argv[]){ @@ -283,7 +291,6 @@ int main(int argc, char *argv[]){ struct server_data server_data = {0}; int nr_sparse_areas = 2, size = 1024, i; struct lm_sparse_mmap_areas *sparse_areas; - lm_ctx_t *lm_ctx; while ((opt = getopt(argc, argv, "v")) != -1) { @@ -310,7 +317,8 @@ int main(int argc, char *argv[]){ sparse_areas = calloc(1, sizeof(*sparse_areas) + (nr_sparse_areas * sizeof(struct lm_mmap_area))); if (sparse_areas == NULL) { - err(EXIT_FAILURE, "MMAP sparse areas ENOMEM"); + ret = -ENOMEM; + fprintf(stderr, "MMAP sparse areas ENOMEM\n"); goto out; } sparse_areas->nr_mmap_areas = nr_sparse_areas; @@ -359,15 +367,16 @@ int main(int argc, char *argv[]){ sigemptyset(&act.sa_mask); if (sigaction(SIGUSR1, &act, NULL) == -1) { - err(EXIT_FAILURE, "failed to register signal handler"); + fprintf(stderr, "failed to register signal handler\n"); + ret = -EFAULT; + goto out; } lm_ctx = lm_ctx_create(&dev_info); if (lm_ctx == NULL) { - if (errno == EINTR) { - goto out; - } - err(EXIT_FAILURE, "failed to initialize device emulation"); + fprintf(stderr, "failed to initialize device emulation\n"); + ret = -1; + goto out; } do { @@ -394,8 +403,9 @@ int main(int argc, char *argv[]){ fprintf(stderr, "failed to realize device emulation: %s\n", strerror(-ret)); } -out: lm_ctx_destroy(lm_ctx); + +out: free(server_data.bar1); free(sparse_areas); return ret; |