Skip to content

Commit acbc2d1

Browse files
authored
Merge pull request #313 from fredericdalleau/various-fixes
Various fixes
2 parents cf1581b + af5eba2 commit acbc2d1

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/lib/pci_virtio_rnd.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pci_vtrnd_notify(void *vsc, struct vqueue_info *vq)
100100
{
101101
struct iovec iov;
102102
struct pci_vtrnd_softc *sc;
103-
int len;
103+
int len, n;
104104
uint16_t idx;
105105

106106
sc = vsc;
@@ -111,7 +111,11 @@ pci_vtrnd_notify(void *vsc, struct vqueue_info *vq)
111111
}
112112

113113
while (vq_has_descs(vq)) {
114-
vq_getchain(vq, &idx, &iov, 1, NULL);
114+
n = vq_getchain(vq, &idx, &iov, 1, NULL);
115+
if (n < 0) {
116+
fprintf(stderr, "vtrnd: vtrnd_notify(): n %d\r\n", n);
117+
return;
118+
}
115119

116120
len = (int) read(sc->vrsc_fd, iov.iov_base, iov.iov_len);
117121

src/lib/pci_virtio_sock.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,11 @@ static void pci_vtsock_proc_tx(struct pci_vtsock_softc *sc,
11211121
size_t pulled;
11221122

11231123
iovec_len = vq_getchain(vq, &idx, iov, VTSOCK_MAXSEGS, flags);
1124+
if (iovec_len < 0) {
1125+
fprintf(stderr, "TX: failed to get chain at idx %"PRIx16"\n", idx);
1126+
return;
1127+
}
1128+
11241129
assert(iovec_len <= VTSOCK_MAXSEGS);
11251130

11261131
DPRINTF(("TX: chain with %d buffers at idx %"PRIx16"\n",

src/lib/virtio.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,10 @@ vi_pci_read(UNUSED int vcpu, struct pci_devinst *pi, int baridx,
559559
max = vc->vc_cfgsize ? vc->vc_cfgsize : 0x100000000;
560560
if ((newoff + ((unsigned) size)) > max)
561561
goto bad;
562-
error = (*vc->vc_cfgread)(DEV_SOFTC(vs), ((int) newoff), size, &value);
562+
if (vc->vc_cfgread != NULL)
563+
error = (*vc->vc_cfgread)(DEV_SOFTC(vs), ((int) newoff), size, &value);
564+
else
565+
error = 0;
563566
if (!error)
564567
goto done;
565568
}
@@ -678,8 +681,11 @@ vi_pci_write(UNUSED int vcpu, struct pci_devinst *pi, int baridx,
678681
max = vc->vc_cfgsize ? vc->vc_cfgsize : 0x100000000;
679682
if ((newoff + ((unsigned) size)) > max)
680683
goto bad;
681-
error = (*vc->vc_cfgwrite)(DEV_SOFTC(vs), ((int) newoff), size,
682-
((uint32_t) value));
684+
if (vc->vc_cfgwrite != NULL)
685+
error = (*vc->vc_cfgwrite)(DEV_SOFTC(vs), ((int) newoff), size,
686+
((uint32_t) value));
687+
else
688+
error = 0;
683689
if (!error)
684690
goto done;
685691
}

0 commit comments

Comments
 (0)