aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Makatos <thanos.makatos@nutanix.com>2019-11-06 10:24:38 -0500
committerThanos <tmakatos@gmail.com>2019-11-07 16:21:48 +0100
commit1cf913cc674f2cb3d8197c638749550bf3d4507c (patch)
tree00bb3f4953a06bda381c3adf5df7be6b4498b918
parent6686b7f5963c834566ba57787e949e7d0ffb29f7 (diff)
downloadlibvfio-user-1cf913cc674f2cb3d8197c638749550bf3d4507c.zip
libvfio-user-1cf913cc674f2cb3d8197c638749550bf3d4507c.tar.gz
libvfio-user-1cf913cc674f2cb3d8197c638749550bf3d4507c.tar.bz2
enable -Wall, -Wextra, and -Werror and fix all warnings
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
-rw-r--r--lib/CMakeLists.txt1
-rw-r--r--lib/cap.c5
-rw-r--r--lib/common.h6
-rw-r--r--lib/dma.c2
-rw-r--r--lib/dma.h21
-rw-r--r--lib/libmuser.c52
-rw-r--r--lib/libmuser_pci.c11
-rw-r--r--lib/muser.h4
-rw-r--r--lib/muser_priv.h2
9 files changed, 57 insertions, 47 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 1ae48f2..49e6280 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -40,6 +40,7 @@ add_library(muser SHARED
libmuser_pci.c
cap.c
cap.h)
+set(CMAKE_C_FLAGS "-Wall -Wextra -Werror")
set_target_properties(muser PROPERTIES PUBLIC_HEADER "muser.h;pci.h")
set(MUSER_HEADERS_DIR ${CMAKE_INSTALL_INCLUDEDIR}/muser)
install(TARGETS muser
diff --git a/lib/cap.c b/lib/cap.c
index 8536d75..c340a46 100644
--- a/lib/cap.c
+++ b/lib/cap.c
@@ -96,7 +96,6 @@ static struct cap *
cap_find(struct cap *caps, int nr_caps, loff_t offset, size_t count)
{
struct cap *cap;
- bool found = false;
cap = caps;
while (cap < caps + nr_caps) {
@@ -154,7 +153,7 @@ cap_header_access(struct caps *caps, struct cap *cap, char *buf,
}
if (offset == cap->start + 1 && count > 0) { /* next */
- if ((cap - caps->caps) / sizeof *cap == caps->nr_caps - 1) {
+ if ((cap - caps->caps) / sizeof *cap == (size_t)(caps->nr_caps - 1)) {
buf[n++] = 0;
} else {
buf[n++] = (cap + 1)->start;
@@ -170,9 +169,7 @@ ssize_t
cap_maybe_access(struct caps *caps, void *pvt, char *buf, size_t count,
loff_t offset, bool is_write)
{
- bool found;
struct cap *cap;
- int n;
if (!caps) {
return 0;
diff --git a/lib/common.h b/lib/common.h
index 85ad610..27d6735 100644
--- a/lib/common.h
+++ b/lib/common.h
@@ -51,9 +51,13 @@
void
lm_log(lm_ctx_t *lm_ctx, lm_log_lvl_t lvl, const char *fmt, ...);
+#ifdef DEBUG
void
dump_buffer(lm_ctx_t *lm_ctx, const char *prefix,
- const unsigned char *buf, uint32_t count);
+ const char *buf, uint32_t count);
+#else
+#define dump_buffer(lm_ctx, prefix, buf, count)
+#endif
#endif /* __COMMON_H__ */
diff --git a/lib/dma.c b/lib/dma.c
index b88f980..27901a1 100644
--- a/lib/dma.c
+++ b/lib/dma.c
@@ -277,7 +277,7 @@ dma_unmap_region(dma_memory_region_t *region, void *virt_addr, size_t len)
}
int
-_dma_addr_sg_split(lm_ctx_t *lm_ctx, const dma_controller_t *dma,
+_dma_addr_sg_split(const dma_controller_t *dma,
dma_addr_t dma_addr, uint32_t len,
dma_sg_t *sg, int max_sg)
{
diff --git a/lib/dma.h b/lib/dma.h
index 62df86e..9e7126e 100644
--- a/lib/dma.h
+++ b/lib/dma.h
@@ -124,7 +124,7 @@ dma_controller_remove_region(dma_controller_t *dma, dma_addr_t dma_addr,
// Helper for dma_addr_to_sg() slow path.
int
-_dma_addr_sg_split(lm_ctx_t *ctx, const dma_controller_t *dma,
+_dma_addr_sg_split(const dma_controller_t *dma,
dma_addr_t dma_addr, uint32_t len,
dma_sg_t *sg, int max_sg);
@@ -140,7 +140,7 @@ _dma_addr_sg_split(lm_ctx_t *ctx, const dma_controller_t *dma,
* necessary to complete this request.
*/
static inline int
-dma_addr_to_sg(lm_ctx_t *ctx, const dma_controller_t *dma,
+dma_addr_to_sg(const dma_controller_t *dma,
dma_addr_t dma_addr, uint32_t len,
dma_sg_t *sg, int max_sg)
{
@@ -159,7 +159,7 @@ dma_addr_to_sg(lm_ctx_t *ctx, const dma_controller_t *dma,
return 1;
}
// Slow path: search through regions.
- cnt = _dma_addr_sg_split(ctx, dma, dma_addr, len, sg, max_sg);
+ cnt = _dma_addr_sg_split(dma, dma_addr, len, sg, max_sg);
if (likely(cnt > 0)) {
region_hint = sg->region;
}
@@ -174,7 +174,12 @@ void
dma_unmap_region(dma_memory_region_t *region, void *virt_addr, size_t len);
static inline int
-dma_map_sg(dma_controller_t *dma, int prot,
+dma_map_sg(dma_controller_t *dma,
+#if DMA_MAP_FAST_IMPL
+ int prot __attribute__((unused)),
+#else
+ int prot,
+#endif
const dma_sg_t *sg, struct iovec *iov, int cnt)
{
int i;
@@ -212,13 +217,13 @@ dma_unmap_sg(dma_controller_t *dma,
}
static inline void *
-dma_map_addr(lm_ctx_t *ctx, dma_controller_t *dma, int prot,
+dma_map_addr(dma_controller_t *dma, int prot,
dma_addr_t dma_addr, uint32_t len)
{
dma_sg_t sg;
struct iovec iov;
- if (dma_addr_to_sg(ctx, dma, dma_addr, len, &sg, 1) == 1 &&
+ if (dma_addr_to_sg(dma, dma_addr, len, &sg, 1) == 1 &&
dma_map_sg(dma, prot, &sg, &iov, 1) == 0) {
return iov.iov_base;
}
@@ -227,7 +232,7 @@ dma_map_addr(lm_ctx_t *ctx, dma_controller_t *dma, int prot,
}
static inline void
-dma_unmap_addr(lm_ctx_t *ctx, dma_controller_t *dma,
+dma_unmap_addr(dma_controller_t *dma,
dma_addr_t dma_addr, uint32_t len, void *addr)
{
dma_sg_t sg;
@@ -237,7 +242,7 @@ dma_unmap_addr(lm_ctx_t *ctx, dma_controller_t *dma,
};
int r;
- r = dma_addr_to_sg(ctx, dma, dma_addr, len, &sg, 1);
+ r = dma_addr_to_sg(dma, dma_addr, len, &sg, 1);
assert(r == 1);
dma_unmap_sg(dma, &sg, &iov, 1);
diff --git a/lib/libmuser.c b/lib/libmuser.c
index 4233023..1da66f2 100644
--- a/lib/libmuser.c
+++ b/lib/libmuser.c
@@ -166,11 +166,12 @@ irqs_disable(lm_ctx_t *lm_ctx, uint32_t index)
static int
irqs_set_data_none(lm_ctx_t *lm_ctx, struct vfio_irq_set *irq_set)
{
- int efd, i;
+ int efd;
+ __u32 i;
long ret;
eventfd_t val;
- for (i = irq_set->start; i < irq_set->start + irq_set->count; i++) {
+ for (i = irq_set->start; i < (irq_set->start + irq_set->count); i++) {
efd = lm_ctx->irqs.efds[i];
if (efd >= 0) {
val = 1;
@@ -190,13 +191,14 @@ static int
irqs_set_data_bool(lm_ctx_t *lm_ctx, struct vfio_irq_set *irq_set, void *data)
{
uint8_t *d8;
- int efd, i;
+ int efd;
+ __u32 i;
long ret;
eventfd_t val;
assert(data != NULL);
- for (i = irq_set->start, d8 = data; i < irq_set->start + irq_set->count;
+ for (i = irq_set->start, d8 = data; i < (irq_set->start + irq_set->count);
i++, d8++) {
efd = lm_ctx->irqs.efds[i];
if (efd >= 0 && *d8 == 1) {
@@ -217,10 +219,11 @@ static int
irqs_set_data_eventfd(lm_ctx_t *lm_ctx, struct vfio_irq_set *irq_set, void *data)
{
int32_t *d32;
- int efd, i;
+ int efd;
+ __u32 i;
assert(data != NULL);
- for (i = irq_set->start, d32 = data; i < irq_set->start + irq_set->count;
+ for (i = irq_set->start, d32 = data; i < (irq_set->start + irq_set->count);
i++, d32++) {
efd = lm_ctx->irqs.efds[i];
if (efd >= 0) {
@@ -427,7 +430,7 @@ dev_get_sparse_mmap_cap(lm_ctx_t *lm_ctx, lm_reg_info_t *lm_reg,
/* write the sparse mmap cap info to vfio-client user pages */
ret = write(lm_ctx->fd, sparse, size);
- if (ret != size) {
+ if (ret != (ssize_t)size) {
free(sparse);
return -EIO;
}
@@ -474,11 +477,15 @@ dev_get_reginfo(lm_ctx_t *lm_ctx, struct vfio_region_info *vfio_reg)
vfio_reg->flags = lm_reg->flags;
vfio_reg->size = lm_reg->size;
- if (lm_reg->mmap_areas != NULL)
+ if (lm_reg->mmap_areas != NULL) {
err = dev_get_sparse_mmap_cap(lm_ctx, lm_reg, vfio_reg);
+ if (err) {
+ return err;
+ }
+ }
lm_log(lm_ctx, LM_DBG, "region_info[%d]\n", vfio_reg->index);
- dump_buffer(lm_ctx, "", (unsigned char *)vfio_reg, sizeof *vfio_reg);
+ dump_buffer(lm_ctx, "", (char*)vfio_reg, sizeof *vfio_reg);
return 0;
}
@@ -590,7 +597,7 @@ muser_mmap(lm_ctx_t *lm_ctx, struct muser_cmd *cmd)
int region, err = 0;
unsigned long addr;
unsigned long len = cmd->mmap.request.len;
- unsigned long offset = cmd->mmap.request.addr;
+ loff_t offset = cmd->mmap.request.addr;
region = lm_get_region(offset, len, &offset);
if (region < 0) {
@@ -648,7 +655,7 @@ lm_get_region(loff_t pos, size_t count, loff_t *off)
assert(off != NULL);
r = offset_to_region(pos);
- if (offset_to_region(pos + count) != r) {
+ if ((int)offset_to_region(pos + count) != r) {
return -ENOENT;
}
*off = pos - region_to_offset(r);
@@ -657,7 +664,9 @@ lm_get_region(loff_t pos, size_t count, loff_t *off)
}
static ssize_t
-noop_cb(void *pvt, char *buf, size_t count, loff_t offset, bool is_write) {
+noop_cb(void *pvt __attribute((unused)), char *buf __attribute((unused)),
+ size_t count __attribute((unused)), loff_t offset __attribute((unused)),
+ bool is_write __attribute((unused))) {
return count;
}
@@ -770,7 +779,7 @@ lm_access(lm_ctx_t *lm_ctx, char *buf, size_t count, loff_t *ppos,
*/
return -EFAULT;
}
- if (ret != size) {
+ if (ret != (int)size) {
lm_log(lm_ctx, LM_DBG, "bad read %d != %d\n", ret, size);
}
count -= size;
@@ -786,7 +795,6 @@ muser_access(lm_ctx_t *lm_ctx, struct muser_cmd *cmd, bool is_write)
{
char *rwbuf;
int err;
- unsigned int i;
size_t count = 0, _count;
ssize_t ret;
@@ -902,8 +910,6 @@ drive_loop(lm_ctx_t *lm_ctx)
{
struct muser_cmd cmd = { 0 };
int err;
- size_t size;
- unsigned int i;
do {
err = ioctl(lm_ctx->fd, MUSER_DEV_CMD_WAIT, &cmd);
@@ -1124,7 +1130,7 @@ lm_ctx_t *
lm_ctx_create(lm_dev_info_t *dev_info)
{
lm_ctx_t *lm_ctx = NULL;
- uint32_t max_ivs = 0, nr_mmap_areas = 0;
+ uint32_t max_ivs = 0;
uint32_t i;
int err = 0;
size_t size = 0;
@@ -1233,11 +1239,11 @@ out:
return lm_ctx;
}
-void
+#ifdef DEBUG
+static void
dump_buffer(lm_ctx_t *lm_ctx, const char *prefix,
- const unsigned char *buf, uint32_t count)
+ const char *buf, uint32_t count)
{
-#ifdef DEBUG
int i;
const size_t bytes_per_line = 0x8;
@@ -1257,8 +1263,10 @@ dump_buffer(lm_ctx_t *lm_ctx, const char *prefix,
if (i % bytes_per_line != 0) {
lm_log(lm_ctx, LM_DBG, "\n");
}
-#endif
}
+#else
+#define dump_buffer(lm_ctx, prefix, buf, count)
+#endif
/*
* Returns a pointer to the standard part of the PCI configuration space.
@@ -1291,7 +1299,7 @@ inline int
lm_addr_to_sg(lm_ctx_t *lm_ctx, dma_addr_t dma_addr,
uint32_t len, dma_sg_t *sg, int max_sg)
{
- return dma_addr_to_sg(lm_ctx, lm_ctx->dma, dma_addr, len, sg, max_sg);
+ return dma_addr_to_sg(lm_ctx->dma, dma_addr, len, sg, max_sg);
}
inline int
diff --git a/lib/libmuser_pci.c b/lib/libmuser_pci.c
index 9c3d38c..d6eb263 100644
--- a/lib/libmuser_pci.c
+++ b/lib/libmuser_pci.c
@@ -190,7 +190,7 @@ handle_erom_write(lm_ctx_t *ctx, lm_pci_config_space_t *pci,
} else if (v == 0) {
lm_log(ctx, LM_INF, "cleared EROM\n");
pci->hdr.erom = 0;
- } else if (v == ~PCI_ROM_ADDRESS_ENABLE) {
+ } else if (v == (uint32_t)~PCI_ROM_ADDRESS_ENABLE) {
lm_log(ctx, LM_INF, "EROM disable ignored\n");
} else {
lm_log(ctx, LM_ERR, "bad write to EROM 0x%x bytes\n", v);
@@ -203,7 +203,6 @@ static inline int
muser_pci_hdr_write(lm_ctx_t *lm_ctx, uint16_t offset,
const char *buf, size_t count)
{
- uint32_t *bar;
lm_pci_config_space_t *pci;
int ret = 0;
@@ -265,7 +264,7 @@ muser_pci_hdr_write(lm_ctx_t *lm_ctx, uint16_t offset,
static inline int
muser_do_pci_hdr_access(lm_ctx_t *lm_ctx, size_t *count,
loff_t *pos, bool is_write,
- unsigned char *buf)
+ char *buf)
{
size_t _count;
loff_t _pos;
@@ -290,7 +289,7 @@ muser_do_pci_hdr_access(lm_ctx_t *lm_ctx, size_t *count,
}
static inline bool
-muser_is_pci_hdr_access(const lm_reg_info_t *reg_info, loff_t pos)
+muser_is_pci_hdr_access(loff_t pos)
{
const off_t off = (loff_t) region_to_offset(LM_DEV_CFG_REG_IDX);
return pos - off >= 0 && pos - off < PCI_STD_HEADER_SIZEOF;
@@ -299,13 +298,13 @@ muser_is_pci_hdr_access(const lm_reg_info_t *reg_info, loff_t pos)
int
muser_pci_hdr_access(lm_ctx_t *lm_ctx, size_t *count,
loff_t *pos, bool is_write,
- unsigned char *buf)
+ char *buf)
{
assert(lm_ctx);
assert(count);
assert(pos);
- if (!muser_is_pci_hdr_access(lm_get_region_info(lm_ctx), *pos)) {
+ if (!muser_is_pci_hdr_access(*pos)) {
return 0;
}
return muser_do_pci_hdr_access(lm_ctx, count, pos, is_write, buf);
diff --git a/lib/muser.h b/lib/muser.h
index e1a9f85..f39557c 100644
--- a/lib/muser.h
+++ b/lib/muser.h
@@ -437,10 +437,6 @@ lm_get_region(loff_t pos, size_t count, loff_t *off);
uint8_t *
lm_get_pci_non_std_config_space(lm_ctx_t *lm_ctx);
-void
-dump_buffer(lm_ctx_t *lm_ctx, const char *prefix,
- const unsigned char *buf, uint32_t count);
-
#endif /* LIB_MUSER_H */
/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/lib/muser_priv.h b/lib/muser_priv.h
index dca6810..aa29f5a 100644
--- a/lib/muser_priv.h
+++ b/lib/muser_priv.h
@@ -37,7 +37,7 @@
int
muser_pci_hdr_access(lm_ctx_t *lm_ctx, size_t *count,
- loff_t *pos, bool write, unsigned char *buf);
+ loff_t *pos, bool write, char *buf);
lm_reg_info_t *
lm_get_region_info(lm_ctx_t *lm_ctx);