diff options
author | Peter Grehan <grehan@FreeBSD.org> | 2013-03-06 07:28:20 +0000 |
---|---|---|
committer | Peter Grehan <grehan@FreeBSD.org> | 2013-03-06 07:28:20 +0000 |
commit | 6be7c5e31c4f6b27f7729a8a52515d96ffaf01f5 (patch) | |
tree | 5c821ef513a52f4120229c192ce73c4a9e73d99c /usr.sbin | |
parent | 0cfbcf8c7b75a8a67c154e8d8ceab9b3c9bf356b (diff) | |
download | src-6be7c5e31c4f6b27f7729a8a52515d96ffaf01f5.tar.gz src-6be7c5e31c4f6b27f7729a8a52515d96ffaf01f5.zip |
Notes
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bhyve/pci_virtio_block.c | 17 | ||||
-rw-r--r-- | usr.sbin/bhyve/pci_virtio_net.c | 15 |
2 files changed, 21 insertions, 11 deletions
diff --git a/usr.sbin/bhyve/pci_virtio_block.c b/usr.sbin/bhyve/pci_virtio_block.c index 31ff2e62ac76..0c34666f5466 100644 --- a/usr.sbin/bhyve/pci_virtio_block.c +++ b/usr.sbin/bhyve/pci_virtio_block.c @@ -164,14 +164,19 @@ pci_vtblk_iosize(struct pci_devinst *pi) static int hq_num_avail(struct vring_hqueue *hq) { - int ndesc; + uint16_t ndesc; - if (*hq->hq_avail_idx >= hq->hq_cur_aidx) - ndesc = *hq->hq_avail_idx - hq->hq_cur_aidx; - else - ndesc = UINT16_MAX - hq->hq_cur_aidx + *hq->hq_avail_idx + 1; + /* + * We're just computing (a-b) in GF(216). + * + * The only glitch here is that in standard C, + * uint16_t promotes to (signed) int when int has + * more than 16 bits (pretty much always now), so + * we have to force it back to unsigned. + */ + ndesc = (unsigned)*hq->hq_avail_idx - (unsigned)hq->hq_cur_aidx; - assert(ndesc >= 0 && ndesc <= hq->hq_size); + assert(ndesc <= hq->hq_size); return (ndesc); } diff --git a/usr.sbin/bhyve/pci_virtio_net.c b/usr.sbin/bhyve/pci_virtio_net.c index a5cf8b3c85cd..11647d62fe0f 100644 --- a/usr.sbin/bhyve/pci_virtio_net.c +++ b/usr.sbin/bhyve/pci_virtio_net.c @@ -172,12 +172,17 @@ hq_num_avail(struct vring_hqueue *hq) { int ndesc; - if (*hq->hq_avail_idx >= hq->hq_cur_aidx) - ndesc = *hq->hq_avail_idx - hq->hq_cur_aidx; - else - ndesc = UINT16_MAX - hq->hq_cur_aidx + *hq->hq_avail_idx + 1; + /* + * We're just computing (a-b) in GF(216). + * + * The only glitch here is that in standard C, + * uint16_t promotes to (signed) int when int has + * more than 16 bits (pretty much always now), so + * we have to force it back to unsigned. + */ + ndesc = (unsigned)*hq->hq_avail_idx - (unsigned)hq->hq_cur_aidx; - assert(ndesc >= 0 && ndesc <= hq->hq_size); + assert(ndesc <= hq->hq_size); return (ndesc); } |