aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-02-18 16:01:21 +0000
committerGitHub <noreply@github.com>2021-02-18 16:01:21 +0000
commitc4f6f81007cf6ab720067d8f8e9288c5dfd5a720 (patch)
treeb407c1b6355b8d3646a4f75ccd04f6610d4ae0b3 /lib
parent22a80ef616beaf7ac495698a4219f37efe5635c8 (diff)
downloadlibvfio-user-c4f6f81007cf6ab720067d8f8e9288c5dfd5a720.zip
libvfio-user-c4f6f81007cf6ab720067d8f8e9288c5dfd5a720.tar.gz
libvfio-user-c4f6f81007cf6ab720067d8f8e9288c5dfd5a720.tar.bz2
use sizeof() consistently (#351)
The most common way we have written this is as "sizeof()"; use this form consistently. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/dma.c2
-rw-r--r--lib/irq.c6
-rw-r--r--lib/libvfio-user.c40
-rw-r--r--lib/migration.c2
-rw-r--r--lib/pci_caps.c22
-rw-r--r--lib/tran_sock.c32
6 files changed, 52 insertions, 52 deletions
diff --git a/lib/dma.c b/lib/dma.c
index c860154..07d12b3 100644
--- a/lib/dma.c
+++ b/lib/dma.c
@@ -175,7 +175,7 @@ dma_controller_remove_region(dma_controller_t *dma,
* check whether memmove eliminates this warning.
*/
memcpy(region, &dma->regions[dma->nregions - 1],
- sizeof *region);
+ sizeof(*region));
dma->nregions--;
return 0;
}
diff --git a/lib/irq.c b/lib/irq.c
index 5cc0cd2..a1d855f 100644
--- a/lib/irq.c
+++ b/lib/irq.c
@@ -332,7 +332,7 @@ handle_device_get_irq_info(vfu_ctx_t *vfu_ctx, uint32_t size,
assert(irq_info_in != NULL);
assert(irq_info_out != NULL);
- if (size != sizeof *irq_info_in || size != irq_info_in->argsz) {
+ if (size != sizeof(*irq_info_in) || size != irq_info_in->argsz) {
vfu_log(vfu_ctx, LOG_WARNING, "IRQ info size %d", size);
return -EINVAL;
}
@@ -349,7 +349,7 @@ handle_device_set_irqs(vfu_ctx_t *vfu_ctx, uint32_t size,
assert(vfu_ctx != NULL);
assert(irq_set != NULL);
- if (size < sizeof *irq_set || size != irq_set->argsz) {
+ if (size < sizeof(*irq_set) || size != irq_set->argsz) {
vfu_log(vfu_ctx, LOG_ERR, "bad size %d", size);
return -EINVAL;
}
@@ -422,7 +422,7 @@ vfu_irq_message(vfu_ctx_t *vfu_ctx, uint32_t subindex)
irq_info.subindex = subindex;
ret = vfu_ctx->tran->send_msg(vfu_ctx, msg_id,
VFIO_USER_VM_INTERRUPT,
- &irq_info, sizeof irq_info,
+ &irq_info, sizeof(irq_info),
NULL, NULL, 0);
if (ret < 0) {
return ERROR_INT(-ret);
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c
index 8aeb572..07412c8 100644
--- a/lib/libvfio-user.c
+++ b/lib/libvfio-user.c
@@ -71,7 +71,7 @@ vfu_log(vfu_ctx_t *vfu_ctx, int level, const char *fmt, ...)
}
va_start(ap, fmt);
- vsnprintf(buf, sizeof buf, fmt, ap);
+ vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
vfu_ctx->log(vfu_ctx, level, buf);
errno = _errno;
@@ -245,14 +245,14 @@ is_valid_region_access(vfu_ctx_t *vfu_ctx, size_t size, uint16_t cmd,
assert(vfu_ctx != NULL);
assert(ra != NULL);
- if (size < sizeof (*ra)) {
+ if (size < sizeof(*ra)) {
vfu_log(vfu_ctx, LOG_ERR, "message size too small (%d)", size);
return false;
}
- if (cmd == VFIO_USER_REGION_WRITE && size - sizeof (*ra) != ra->count) {
+ if (cmd == VFIO_USER_REGION_WRITE && size - sizeof(*ra) != ra->count) {
vfu_log(vfu_ctx, LOG_ERR, "region write count too small: "
- "expected %lu, got %u", size - sizeof (*ra), ra->count);
+ "expected %lu, got %u", size - sizeof(*ra), ra->count);
return false;
}
@@ -303,7 +303,7 @@ handle_region_access(vfu_ctx_t *vfu_ctx, uint32_t size, uint16_t cmd,
return 0;
}
- *len = sizeof (*ra);
+ *len = sizeof(*ra);
if (cmd == VFIO_USER_REGION_READ) {
*len += ra->count;
}
@@ -435,12 +435,12 @@ handle_device_get_info(vfu_ctx_t *vfu_ctx, uint32_t in_size,
assert(in_dev_info != NULL);
assert(out_dev_info != NULL);
- if (in_size < sizeof (*in_dev_info) ||
- in_dev_info->argsz < sizeof (*in_dev_info)) {
+ if (in_size < sizeof(*in_dev_info) ||
+ in_dev_info->argsz < sizeof(*in_dev_info)) {
return -EINVAL;
}
- out_dev_info->argsz = sizeof (*in_dev_info);
+ out_dev_info->argsz = sizeof(*in_dev_info);
out_dev_info->flags = VFIO_DEVICE_FLAGS_PCI | VFIO_DEVICE_FLAGS_RESET;
out_dev_info->num_regions = vfu_ctx->nr_regions;
out_dev_info->num_irqs = VFU_DEV_NUM_IRQS;
@@ -633,7 +633,7 @@ handle_dirty_pages(vfu_ctx_t *vfu_ctx, uint32_t size,
assert(nr_iovecs != NULL);
assert(dirty_bitmap != NULL);
- if (size < sizeof *dirty_bitmap || size != dirty_bitmap->argsz) {
+ if (size < sizeof(*dirty_bitmap) || size != dirty_bitmap->argsz) {
vfu_log(vfu_ctx, LOG_ERR, "invalid header size %u", size);
return -EINVAL;
}
@@ -646,7 +646,7 @@ handle_dirty_pages(vfu_ctx_t *vfu_ctx, uint32_t size,
} 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),
- size - sizeof *dirty_bitmap);
+ size - sizeof(*dirty_bitmap));
} else {
vfu_log(vfu_ctx, LOG_ERR, "bad flags %#x", dirty_bitmap->flags);
ret = -EINVAL;
@@ -670,7 +670,7 @@ validate_header(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr, size_t size)
{
assert(hdr != NULL);
- if (size < sizeof hdr) {
+ if (size < sizeof(hdr)) {
vfu_log(vfu_ctx, LOG_ERR, "short header read %ld", size);
return -EINVAL;
}
@@ -680,7 +680,7 @@ validate_header(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr, size_t size)
return -EINVAL;
}
- if (hdr->msg_size < sizeof hdr) {
+ if (hdr->msg_size < sizeof(hdr)) {
vfu_log(vfu_ctx, LOG_ERR, "msg%#hx: bad size %d in header",
hdr->msg_id, hdr->msg_size);
return -EINVAL;
@@ -791,7 +791,7 @@ exec_command(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr, size_t size,
return -EINVAL;
}
- cmd_data_size = hdr->msg_size - sizeof (*hdr);
+ cmd_data_size = hdr->msg_size - sizeof(*hdr);
if (cmd_data_size > 0) {
ret = vfu_ctx->tran->recv_body(vfu_ctx, hdr, &cmd_data);
@@ -810,7 +810,7 @@ exec_command(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr, size_t size,
break;
case VFIO_USER_DEVICE_GET_INFO:
- dev_info = calloc(1, sizeof *dev_info);
+ dev_info = calloc(1, sizeof(*dev_info));
if (dev_info == NULL) {
ret = -ENOMEM;
break;
@@ -842,7 +842,7 @@ exec_command(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr, size_t size,
break;
case VFIO_USER_DEVICE_GET_IRQ_INFO:
- irq_info = calloc(1, sizeof *irq_info);
+ irq_info = calloc(1, sizeof(*irq_info));
if (irq_info == NULL) {
ret = -ENOMEM;
break;
@@ -851,7 +851,7 @@ exec_command(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr, size_t size,
irq_info);
if (ret == 0) {
_iovecs[1].iov_base = irq_info;
- _iovecs[1].iov_len = sizeof *irq_info;
+ _iovecs[1].iov_len = sizeof(*irq_info);
*iovecs = _iovecs;
*nr_iovecs = 2;
} else {
@@ -1183,7 +1183,7 @@ vfu_create_ctx(vfu_trans_t trans, const char *path, int flags, void *pvt,
* and move it into vfu_ctx.migration.
*/
vfu_ctx->nr_regions = VFU_PCI_DEV_NUM_REGIONS;
- vfu_ctx->reg_info = calloc(vfu_ctx->nr_regions, sizeof *vfu_ctx->reg_info);
+ vfu_ctx->reg_info = calloc(vfu_ctx->nr_regions, sizeof(*vfu_ctx->reg_info));
if (vfu_ctx->reg_info == NULL) {
err = -ENOMEM;
goto err_out;
@@ -1253,7 +1253,7 @@ static int
copyin_mmap_areas(vfu_reg_info_t *reg_info,
struct iovec *mmap_areas, uint32_t nr_mmap_areas)
{
- size_t size = nr_mmap_areas * sizeof (*mmap_areas);
+ size_t size = nr_mmap_areas * sizeof(*mmap_areas);
if (mmap_areas == NULL || nr_mmap_areas == 0) {
return 0;
@@ -1384,7 +1384,7 @@ vfu_setup_region(vfu_ctx_t *vfu_ctx, int region_idx, size_t size,
out:
if (ret < 0) {
free(reg->mmap_areas);
- memset(reg, 0, sizeof (*reg));
+ memset(reg, 0, sizeof(*reg));
return ERROR_INT(-ret);
}
return 0;
@@ -1536,7 +1536,7 @@ vfu_dma_read(vfu_ctx_t *vfu_ctx, dma_sg_t *sg, void *data)
dma_send.addr = sg->dma_addr;
dma_send.count = sg->length;
ret = vfu_ctx->tran->send_msg(vfu_ctx, msg_id, VFIO_USER_DMA_READ,
- &dma_send, sizeof dma_send, NULL,
+ &dma_send, sizeof(dma_send), NULL,
dma_recv, recv_size);
memcpy(data, dma_recv->data, sg->length); /* FIXME no need for memcpy */
free(dma_recv);
diff --git a/lib/migration.c b/lib/migration.c
index 234366c..cc7abcf 100644
--- a/lib/migration.c
+++ b/lib/migration.c
@@ -70,7 +70,7 @@ init_migration(const vfu_migration_callbacks_t * callbacks,
return NULL;
}
- migr = calloc(1, sizeof *migr);
+ migr = calloc(1, sizeof(*migr));
if (migr == NULL) {
*err = ENOMEM;
return NULL;
diff --git a/lib/pci_caps.c b/lib/pci_caps.c
index 8adf2f7..58165c7 100644
--- a/lib/pci_caps.c
+++ b/lib/pci_caps.c
@@ -138,17 +138,17 @@ cap_write_pm(vfu_ctx_t *vfu_ctx, struct pci_cap *cap, char * buf,
switch (offset - cap->off) {
case offsetof(struct pmcap, pc):
- if (count != sizeof (struct pc)) {
+ if (count != sizeof(struct pc)) {
return -EINVAL;
}
assert(false); /* FIXME implement */
break;
case offsetof(struct pmcap, pmcs):
- if (count != sizeof (struct pmcs)) {
+ if (count != sizeof(struct pmcs)) {
return -EINVAL;
}
handle_pmcs_write(vfu_ctx, pm, (struct pmcs *)buf);
- return sizeof (struct pmcs);
+ return sizeof(struct pmcs);
}
return -EINVAL;
}
@@ -561,7 +561,7 @@ vfu_pci_add_capability(vfu_ctx_t *vfu_ctx, size_t pos, int flags, void *data)
}
cap.id = ((struct pcie_ext_cap_hdr *)data)->id;
- cap.hdr_size = sizeof (struct pcie_ext_cap_hdr);
+ cap.hdr_size = sizeof(struct pcie_ext_cap_hdr);
switch (cap.id) {
case PCI_EXT_CAP_ID_DSN:
@@ -571,7 +571,7 @@ vfu_pci_add_capability(vfu_ctx_t *vfu_ctx, size_t pos, int flags, void *data)
case PCI_EXT_CAP_ID_VNDR:
cap.name = "Vendor-Specific";
cap.cb = ext_cap_write_vendor;
- cap.hdr_size = sizeof (struct pcie_ext_cap_vsc_hdr);
+ cap.hdr_size = sizeof(struct pcie_ext_cap_vsc_hdr);
break;
default:
vfu_log(vfu_ctx, LOG_ERR, "unsupported capability %#x\n", cap.id);
@@ -592,7 +592,7 @@ vfu_pci_add_capability(vfu_ctx_t *vfu_ctx, size_t pos, int flags, void *data)
}
cap.id = ((struct cap_hdr *)data)->id;
- cap.hdr_size = sizeof (struct cap_hdr);
+ cap.hdr_size = sizeof(struct cap_hdr);
switch (cap.id) {
case PCI_CAP_ID_PM:
@@ -610,7 +610,7 @@ vfu_pci_add_capability(vfu_ctx_t *vfu_ctx, size_t pos, int flags, void *data)
case PCI_CAP_ID_VNDR:
cap.name = "Vendor-Specific";
cap.cb = cap_write_vendor;
- cap.hdr_size = sizeof (struct vsc);
+ cap.hdr_size = sizeof(struct vsc);
break;
default:
vfu_log(vfu_ctx, LOG_ERR, "unsupported capability %#x\n", cap.id);
@@ -632,10 +632,10 @@ vfu_pci_add_capability(vfu_ctx_t *vfu_ctx, size_t pos, int flags, void *data)
if (extended) {
memcpy(&vfu_ctx->pci.ext_caps[vfu_ctx->pci.nr_ext_caps],
- &cap, sizeof (cap));
+ &cap, sizeof(cap));
vfu_ctx->pci.nr_ext_caps++;
} else {
- memcpy(&vfu_ctx->pci.caps[vfu_ctx->pci.nr_caps], &cap, sizeof (cap));
+ memcpy(&vfu_ctx->pci.caps[vfu_ctx->pci.nr_caps], &cap, sizeof(cap));
vfu_ctx->pci.nr_caps++;
}
@@ -647,7 +647,7 @@ vfu_pci_find_next_ext_capability(vfu_ctx_t *vfu_ctx, size_t offset, int cap_id)
{
struct pcie_ext_cap_hdr *hdr = NULL;
- if (offset + sizeof (*hdr) >= pci_config_space_size(vfu_ctx)) {
+ if (offset + sizeof(*hdr) >= pci_config_space_size(vfu_ctx)) {
errno = EINVAL;
return 0;
}
@@ -663,7 +663,7 @@ vfu_pci_find_next_ext_capability(vfu_ctx_t *vfu_ctx, size_t offset, int cap_id)
for (;;) {
offset = (uint8_t *)hdr - pci_config_space_ptr(vfu_ctx, 0);
- if (offset + sizeof (*hdr) >= pci_config_space_size(vfu_ctx)) {
+ if (offset + sizeof(*hdr) >= pci_config_space_size(vfu_ctx)) {
errno = EINVAL;
return 0;
}
diff --git a/lib/tran_sock.c b/lib/tran_sock.c
index 7d2db0e..76801ef 100644
--- a/lib/tran_sock.c
+++ b/lib/tran_sock.c
@@ -68,7 +68,7 @@ tran_sock_send_iovec(int sock, uint16_t msg_id, bool is_reply,
struct vfio_user_header hdr = {.msg_id = msg_id};
struct msghdr msg;
size_t i;
- size_t size = count * sizeof *fds;
+ size_t size = count * sizeof(*fds);
char *buf;
if (nr_iovecs == 0) {
@@ -216,7 +216,7 @@ tran_sock_recv_fds(int sock, struct vfio_user_header *hdr, bool is_reply,
/* FIXME if ret == -1 then fcntl can overwrite recv's errno */
- ret = get_msg(hdr, sizeof *hdr, fds, nr_fds, sock, 0);
+ ret = get_msg(hdr, sizeof(*hdr), fds, nr_fds, sock, 0);
if (ret == -1) {
return -errno;
}
@@ -248,8 +248,8 @@ tran_sock_recv_fds(int sock, struct vfio_user_header *hdr, bool is_reply,
}
}
- if (len != NULL && *len > 0 && hdr->msg_size > sizeof *hdr) {
- ret = recv(sock, data, MIN(hdr->msg_size - sizeof *hdr, *len),
+ if (len != NULL && *len > 0 && hdr->msg_size > sizeof(*hdr)) {
+ ret = recv(sock, data, MIN(hdr->msg_size - sizeof(*hdr), *len),
MSG_WAITALL);
if (ret < 0) {
return ret;
@@ -289,9 +289,9 @@ tran_sock_recv_alloc(int sock, struct vfio_user_header *hdr, bool is_reply,
return ret;
}
- assert(hdr->msg_size >= sizeof (*hdr));
+ assert(hdr->msg_size >= sizeof(*hdr));
- len = hdr->msg_size - sizeof (*hdr);
+ len = hdr->msg_size - sizeof(*hdr);
if (len == 0) {
*datap = NULL;
@@ -339,7 +339,7 @@ tran_sock_msg_iovec(int sock, uint16_t msg_id, enum vfio_user_command cmd,
return ret;
}
if (hdr == NULL) {
- hdr = alloca(sizeof *hdr);
+ hdr = alloca(sizeof(*hdr));
}
return tran_sock_recv_fds(sock, hdr, true, &msg_id, recv_data, &recv_len,
recv_fds, recv_fd_count);
@@ -411,7 +411,7 @@ tran_sock_init(vfu_ctx_t *vfu_ctx)
}
}
- ret = snprintf(addr.sun_path, sizeof addr.sun_path, "%s", vfu_ctx->uuid);
+ ret = snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", vfu_ctx->uuid);
if (ret >= (int)sizeof(addr.sun_path)) {
ret = -ENAMETOOLONG;
}
@@ -564,7 +564,7 @@ recv_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t *msg_idp,
goto out;
}
- if (vlen < sizeof (*cversion)) {
+ if (vlen < sizeof(*cversion)) {
vfu_log(vfu_ctx, LOG_ERR,
"msg%#hx: VFIO_USER_VERSION: invalid size %lu", *msg_idp, vlen);
ret = -EINVAL;
@@ -580,9 +580,9 @@ recv_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t *msg_idp,
vfu_ctx->client_max_fds = 1;
- if (vlen > sizeof (*cversion)) {
+ if (vlen > sizeof(*cversion)) {
const char *json_str = (const char *)cversion->data;
- size_t len = vlen - sizeof (*cversion);
+ size_t len = vlen - sizeof(*cversion);
size_t pgsize = 0;
if (json_str[len - 1] != '\0') {
@@ -647,7 +647,7 @@ send_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t msg_id,
int slen;
if (vfu_ctx->migration == NULL) {
- slen = snprintf(server_caps, sizeof (server_caps),
+ slen = snprintf(server_caps, sizeof(server_caps),
"{"
"\"capabilities\":{"
"\"max_fds\":%u,"
@@ -655,7 +655,7 @@ send_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t msg_id,
"}"
"}", SERVER_MAX_FDS, SERVER_MAX_MSG_SIZE);
} else {
- slen = snprintf(server_caps, sizeof (server_caps),
+ slen = snprintf(server_caps, sizeof(server_caps),
"{"
"\"capabilities\":{"
"\"max_fds\":%u,"
@@ -675,7 +675,7 @@ send_version(vfu_ctx_t *vfu_ctx, int sock, uint16_t msg_id,
/* [0] is for the header. */
iovecs[1].iov_base = &sversion;
- iovecs[1].iov_len = sizeof (sversion);
+ iovecs[1].iov_len = sizeof(sversion);
iovecs[2].iov_base = server_caps;
/* Include the NUL. */
iovecs[2].iov_len = slen + 1;
@@ -755,7 +755,7 @@ tran_sock_get_request(vfu_ctx_t *vfu_ctx, struct vfio_user_header *hdr,
if (vfu_ctx->flags & LIBVFIO_USER_FLAG_ATTACH_NB) {
sock_flags = MSG_DONTWAIT | MSG_WAITALL;
}
- return get_msg(hdr, sizeof *hdr, fds, nr_fds, ts->conn_fd, sock_flags);
+ return get_msg(hdr, sizeof(*hdr), fds, nr_fds, ts->conn_fd, sock_flags);
}
static int
@@ -779,7 +779,7 @@ tran_sock_recv_body(vfu_ctx_t *vfu_ctx, const struct vfio_user_header *hdr,
ts = vfu_ctx->tran_data;
- body_size = hdr->msg_size - sizeof (*hdr);
+ body_size = hdr->msg_size - sizeof(*hdr);
data = malloc(body_size);