git: 63898728b544 - main - bhyve: Avoid arithmetic on void pointers
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 23 Oct 2022 15:18:40 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=63898728b544763d85c062c8515c12a0c3a60e0a
commit 63898728b544763d85c062c8515c12a0c3a60e0a
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-10-22 17:40:20 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-10-23 15:11:33 +0000
bhyve: Avoid arithmetic on void pointers
No functional change intended.
MFC after: 1 week
---
usr.sbin/bhyve/iov.c | 4 ++--
usr.sbin/bhyve/net_backends.c | 6 +++---
usr.sbin/bhyve/pci_e82545.c | 4 ++--
usr.sbin/bhyve/pci_hda.c | 28 ++++++++++++++--------------
usr.sbin/bhyve/pci_hda.h | 2 +-
usr.sbin/bhyve/pci_passthru.c | 2 +-
usr.sbin/bhyve/pci_virtio_console.c | 4 ++--
usr.sbin/bhyve/pci_virtio_scsi.c | 2 +-
usr.sbin/bhyve/rfb.c | 21 ++++++++++++---------
usr.sbin/bhyve/snapshot.c | 4 ++--
10 files changed, 40 insertions(+), 37 deletions(-)
diff --git a/usr.sbin/bhyve/iov.c b/usr.sbin/bhyve/iov.c
index af36cb056229..a70abf079413 100644
--- a/usr.sbin/bhyve/iov.c
+++ b/usr.sbin/bhyve/iov.c
@@ -111,7 +111,7 @@ iov_to_buf(const struct iovec *iov, int niov, void **buf)
return (-1);
for (i = 0, ptr = 0; i < niov; i++) {
- memcpy(*buf + ptr, iov[i].iov_base, iov[i].iov_len);
+ memcpy((uint8_t *)*buf + ptr, iov[i].iov_base, iov[i].iov_len);
ptr += iov[i].iov_len;
}
@@ -137,7 +137,7 @@ buf_to_iov(const void *buf, size_t buflen, const struct iovec *iov, int niov,
for (i = 0; i < niov && off < buflen; i++) {
len = MIN(iov[i].iov_len, buflen - off);
- memcpy(iov[i].iov_base, buf + off, len);
+ memcpy(iov[i].iov_base, (const uint8_t *)buf + off, len);
off += len;
}
diff --git a/usr.sbin/bhyve/net_backends.c b/usr.sbin/bhyve/net_backends.c
index a20199a0b76e..8c6b226a455d 100644
--- a/usr.sbin/bhyve/net_backends.c
+++ b/usr.sbin/bhyve/net_backends.c
@@ -752,8 +752,8 @@ netmap_send(struct net_backend *be, const struct iovec *iov,
nm_buf_len = 0;
for (j = 0; j < iovcnt; j++) {
+ uint8_t *iov_frag_buf = iov[j].iov_base;
int iov_frag_size = iov[j].iov_len;
- void *iov_frag_buf = iov[j].iov_base;
totlen += iov_frag_size;
@@ -834,7 +834,7 @@ netmap_recv(struct net_backend *be, const struct iovec *iov, int iovcnt)
struct netmap_priv *priv = (struct netmap_priv *)be->opaque;
struct netmap_slot *slot = NULL;
struct netmap_ring *ring;
- void *iov_frag_buf;
+ uint8_t *iov_frag_buf;
int iov_frag_size;
ssize_t totlen = 0;
uint32_t head;
@@ -847,8 +847,8 @@ netmap_recv(struct net_backend *be, const struct iovec *iov, int iovcnt)
iov_frag_size = iov->iov_len;
do {
+ uint8_t *nm_buf;
int nm_buf_len;
- void *nm_buf;
if (head == ring->tail) {
return (0);
diff --git a/usr.sbin/bhyve/pci_e82545.c b/usr.sbin/bhyve/pci_e82545.c
index d630e9d1d090..ba0523b9b28e 100644
--- a/usr.sbin/bhyve/pci_e82545.c
+++ b/usr.sbin/bhyve/pci_e82545.c
@@ -1007,7 +1007,7 @@ e82545_iov_checksum(struct iovec *iov, int iovcnt, int off, int len)
odd = 0;
while (len > 0 && iovcnt > 0) {
now = MIN(len, iov->iov_len - off);
- s = e82545_buf_checksum(iov->iov_base + off, now);
+ s = e82545_buf_checksum((uint8_t *)iov->iov_base + off, now);
sum += odd ? (s << 8) : s;
odd ^= (now & 1);
len -= now;
@@ -1320,7 +1320,7 @@ e82545_transmit(struct e82545_softc *sc, uint16_t head, uint16_t tail,
left -= now, hdrp += now) {
now = MIN(left, iov->iov_len);
memcpy(hdrp, iov->iov_base, now);
- iov->iov_base += now;
+ iov->iov_base = (uint8_t *)iov->iov_base + now;
iov->iov_len -= now;
if (iov->iov_len == 0) {
iov++;
diff --git a/usr.sbin/bhyve/pci_hda.c b/usr.sbin/bhyve/pci_hda.c
index 9ebfbfbaa5bf..88f58a5fcc66 100644
--- a/usr.sbin/bhyve/pci_hda.c
+++ b/usr.sbin/bhyve/pci_hda.c
@@ -201,7 +201,7 @@ static int hda_signal_state_change(struct hda_codec_inst *hci);
static int hda_response(struct hda_codec_inst *hci, uint32_t response,
uint8_t unsol);
static int hda_transfer(struct hda_codec_inst *hci, uint8_t stream,
- uint8_t dir, void *buf, size_t count);
+ uint8_t dir, uint8_t *buf, size_t count);
static void hda_set_pib(struct hda_softc *sc, uint8_t stream_ind, uint32_t pib);
static uint64_t hda_get_clock_ns(void);
@@ -793,8 +793,8 @@ hda_corb_run(struct hda_softc *sc)
corb->rp++;
corb->rp %= corb->size;
- verb = hda_dma_ld_dword(corb->dma_vaddr + \
- HDA_CORB_ENTRY_LEN * corb->rp);
+ verb = hda_dma_ld_dword((uint8_t *)corb->dma_vaddr +
+ HDA_CORB_ENTRY_LEN * corb->rp);
err = hda_send_command(sc, verb);
assert(!err);
@@ -1088,10 +1088,10 @@ hda_response(struct hda_codec_inst *hci, uint32_t response, uint8_t unsol)
rirb->wp++;
rirb->wp %= rirb->size;
- hda_dma_st_dword(rirb->dma_vaddr + HDA_RIRB_ENTRY_LEN * \
- rirb->wp, response);
- hda_dma_st_dword(rirb->dma_vaddr + HDA_RIRB_ENTRY_LEN * \
- rirb->wp + 0x04, response_ex);
+ hda_dma_st_dword((uint8_t *)rirb->dma_vaddr +
+ HDA_RIRB_ENTRY_LEN * rirb->wp, response);
+ hda_dma_st_dword((uint8_t *)rirb->dma_vaddr +
+ HDA_RIRB_ENTRY_LEN * rirb->wp + 0x04, response_ex);
hda_set_reg_by_offset(sc, HDAC_RIRBWP, rirb->wp);
@@ -1107,7 +1107,7 @@ hda_response(struct hda_codec_inst *hci, uint32_t response, uint8_t unsol)
static int
hda_transfer(struct hda_codec_inst *hci, uint8_t stream, uint8_t dir,
- void *buf, size_t count)
+ uint8_t *buf, size_t count)
{
struct hda_softc *sc = NULL;
struct hda_stream_desc *st = NULL;
@@ -1161,11 +1161,11 @@ hda_transfer(struct hda_codec_inst *hci, uint8_t stream, uint8_t dir,
bdle_desc = &bdl[st->be];
if (dir)
- *(uint32_t *)buf = \
- hda_dma_ld_dword(bdle_desc->addr + st->bp);
+ *(uint32_t *)buf = hda_dma_ld_dword(
+ (uint8_t *)bdle_desc->addr + st->bp);
else
- hda_dma_st_dword(bdle_desc->addr + st->bp,
- *(uint32_t *)buf);
+ hda_dma_st_dword((uint8_t *)bdle_desc->addr +
+ st->bp, *(uint32_t *)buf);
buf += HDA_DMA_ACCESS_LEN;
st->bp += HDA_DMA_ACCESS_LEN;
@@ -1205,8 +1205,8 @@ hda_set_pib(struct hda_softc *sc, uint8_t stream_ind, uint32_t pib)
/* LPIB Alias */
hda_set_reg_by_offset(sc, 0x2000 + off + HDAC_SDLPIB, pib);
if (sc->dma_pib_vaddr)
- *(uint32_t *)(sc->dma_pib_vaddr + stream_ind * \
- HDA_DMA_PIB_ENTRY_LEN) = pib;
+ *(uint32_t *)((uint8_t *)sc->dma_pib_vaddr + stream_ind *
+ HDA_DMA_PIB_ENTRY_LEN) = pib;
}
static uint64_t hda_get_clock_ns(void)
diff --git a/usr.sbin/bhyve/pci_hda.h b/usr.sbin/bhyve/pci_hda.h
index e86867192193..50cbac82a1a6 100644
--- a/usr.sbin/bhyve/pci_hda.h
+++ b/usr.sbin/bhyve/pci_hda.h
@@ -84,7 +84,7 @@ struct hda_ops {
int (*response)(struct hda_codec_inst *hci, uint32_t response,
uint8_t unsol);
int (*transfer)(struct hda_codec_inst *hci, uint8_t stream,
- uint8_t dir, void *buf, size_t count);
+ uint8_t dir, uint8_t *buf, size_t count);
};
#define HDA_EMUL_SET(x) DATA_SET(hda_codec_class_set, x);
diff --git a/usr.sbin/bhyve/pci_passthru.c b/usr.sbin/bhyve/pci_passthru.c
index 8d76d564b4ae..b28277f7975e 100644
--- a/usr.sbin/bhyve/pci_passthru.c
+++ b/usr.sbin/bhyve/pci_passthru.c
@@ -438,7 +438,7 @@ msix_table_write(struct vmctx *ctx, int vcpu, struct passthru_softc *sc,
assert(entry_offset % 4 == 0);
vector_control = entry->vector_control;
- dest32 = (uint32_t *)((void *)entry + entry_offset);
+ dest32 = (uint32_t *)((uint8_t *)entry + entry_offset);
*dest32 = data;
/* If MSI-X hasn't been enabled, do nothing */
if (pi->pi_msix.enabled) {
diff --git a/usr.sbin/bhyve/pci_virtio_console.c b/usr.sbin/bhyve/pci_virtio_console.c
index fa16bfb84d79..44d0da720226 100644
--- a/usr.sbin/bhyve/pci_virtio_console.c
+++ b/usr.sbin/bhyve/pci_virtio_console.c
@@ -585,8 +585,8 @@ pci_vtcon_control_send(struct pci_vtcon_softc *sc,
memcpy(iov.iov_base, ctrl, sizeof(struct pci_vtcon_control));
if (payload != NULL && len > 0)
- memcpy(iov.iov_base + sizeof(struct pci_vtcon_control),
- payload, len);
+ memcpy((uint8_t *)iov.iov_base +
+ sizeof(struct pci_vtcon_control), payload, len);
vq_relchain(vq, req.idx, sizeof(struct pci_vtcon_control) + len);
vq_endchains(vq, 1);
diff --git a/usr.sbin/bhyve/pci_virtio_scsi.c b/usr.sbin/bhyve/pci_virtio_scsi.c
index 537b2a58097b..7f8d5a8866c9 100644
--- a/usr.sbin/bhyve/pci_virtio_scsi.c
+++ b/usr.sbin/bhyve/pci_virtio_scsi.c
@@ -590,7 +590,7 @@ pci_vtscsi_controlq_notify(void *vsc, struct vqueue_info *vq)
bufsize = iov_to_buf(iov, n, &buf);
iolen = pci_vtscsi_control_handle(sc, buf, bufsize);
- buf_to_iov(buf + bufsize - iolen, iolen, iov, n,
+ buf_to_iov((uint8_t *)buf + bufsize - iolen, iolen, iov, n,
bufsize - iolen);
/*
diff --git a/usr.sbin/bhyve/rfb.c b/usr.sbin/bhyve/rfb.c
index ad5fc4fc88e0..7f7a3514051e 100644
--- a/usr.sbin/bhyve/rfb.c
+++ b/usr.sbin/bhyve/rfb.c
@@ -322,7 +322,8 @@ rfb_recv_set_pixfmt_msg(struct rfb_softc *rc __unused, int cfd)
{
struct rfb_pixfmt_msg pixfmt_msg;
- (void)stream_read(cfd, ((void *)&pixfmt_msg)+1, sizeof(pixfmt_msg)-1);
+ (void)stream_read(cfd, (uint8_t *)&pixfmt_msg + 1,
+ sizeof(pixfmt_msg) - 1);
}
static void
@@ -332,7 +333,7 @@ rfb_recv_set_encodings_msg(struct rfb_softc *rc, int cfd)
int i;
uint32_t encoding;
- (void)stream_read(cfd, ((void *)&enc_msg)+1, sizeof(enc_msg)-1);
+ (void)stream_read(cfd, (uint8_t *)&enc_msg + 1, sizeof(enc_msg) - 1);
for (i = 0; i < htons(enc_msg.numencs); i++) {
(void)stream_read(cfd, &encoding, sizeof(encoding));
@@ -727,7 +728,7 @@ rfb_recv_update_msg(struct rfb_softc *rc, int cfd)
{
struct rfb_updt_msg updt_msg;
- (void)stream_read(cfd, ((void *)&updt_msg) + 1 , sizeof(updt_msg) - 1);
+ (void)stream_read(cfd, (uint8_t *)&updt_msg + 1 , sizeof(updt_msg) - 1);
if (rc->enc_extkeyevent_ok && (!rc->enc_extkeyevent_send)) {
rfb_send_extended_keyevent_update_msg(rc, cfd);
@@ -744,7 +745,7 @@ rfb_recv_key_msg(struct rfb_softc *rc, int cfd)
{
struct rfb_key_msg key_msg;
- (void)stream_read(cfd, ((void *)&key_msg) + 1, sizeof(key_msg) - 1);
+ (void)stream_read(cfd, (uint8_t *)&key_msg + 1, sizeof(key_msg) - 1);
console_key_event(key_msg.down, htonl(key_msg.sym), htonl(0));
rc->input_detected = true;
@@ -756,10 +757,12 @@ rfb_recv_client_msg(struct rfb_softc *rc, int cfd)
struct rfb_client_msg client_msg;
struct rfb_extended_key_msg extkey_msg;
- (void)stream_read(cfd, ((void *)&client_msg) + 1, sizeof(client_msg) - 1);
+ (void)stream_read(cfd, (uint8_t *)&client_msg + 1,
+ sizeof(client_msg) - 1);
- if (client_msg.subtype == RFB_CLIENTMSG_EXT_KEYEVENT ) {
- (void)stream_read(cfd, ((void *)&extkey_msg) + 2, sizeof(extkey_msg) - 2);
+ if (client_msg.subtype == RFB_CLIENTMSG_EXT_KEYEVENT) {
+ (void)stream_read(cfd, (uint8_t *)&extkey_msg + 2,
+ sizeof(extkey_msg) - 2);
console_key_event((int)extkey_msg.down, htonl(extkey_msg.sym), htonl(extkey_msg.code));
rc->input_detected = true;
}
@@ -770,7 +773,7 @@ rfb_recv_ptr_msg(struct rfb_softc *rc, int cfd)
{
struct rfb_ptr_msg ptr_msg;
- (void)stream_read(cfd, ((void *)&ptr_msg) + 1, sizeof(ptr_msg) - 1);
+ (void)stream_read(cfd, (uint8_t *)&ptr_msg + 1, sizeof(ptr_msg) - 1);
console_ptr_event(ptr_msg.button, htons(ptr_msg.x), htons(ptr_msg.y));
rc->input_detected = true;
@@ -783,7 +786,7 @@ rfb_recv_cuttext_msg(struct rfb_softc *rc __unused, int cfd)
unsigned char buf[32];
int len;
- len = stream_read(cfd, ((void *)&ct_msg) + 1, sizeof(ct_msg) - 1);
+ len = stream_read(cfd, (uint8_t *)&ct_msg + 1, sizeof(ct_msg) - 1);
ct_msg.length = htonl(ct_msg.length);
while (ct_msg.length > 0) {
len = stream_read(cfd, buf, ct_msg.length > sizeof(buf) ?
diff --git a/usr.sbin/bhyve/snapshot.c b/usr.sbin/bhyve/snapshot.c
index 1ca36432fc08..881c91973a02 100644
--- a/usr.sbin/bhyve/snapshot.c
+++ b/usr.sbin/bhyve/snapshot.c
@@ -452,7 +452,7 @@ lookup_struct(enum snapshot_req struct_id, struct restore_state *rstate,
assert(file_offset + size <= rstate->kdata_len);
*struct_size = (size_t)size;
- return (rstate->kdata_map + file_offset);
+ return ((uint8_t *)rstate->kdata_map + file_offset);
}
}
@@ -481,7 +481,7 @@ lookup_check_dev(const char *dev_name, struct restore_state *rstate,
assert(file_offset + size <= rstate->kdata_len);
*data_size = (size_t)size;
- return (rstate->kdata_map + file_offset);
+ return ((uint8_t *)rstate->kdata_map + file_offset);
}
return (NULL);