Skip to contentSkip to conversation

libvhost-user: Zero memory allocated for VuVirtqInflightDesc

PATCH In review [email protected] 2 participants 2 messages Nov 19, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libvhost-user: Zero memory allocated for VuVirtqInflightDesc

From: Xie Yongji <[email protected]>

Use a zero-initialized VuVirtqInflightDesc struct to avoid that scan-build reports that vq->resubmit_list[0].counter may be garbage value in vu_check_queue_inflights().

Fixes 5f9ff1eff ("libvhost-user: Support tracking inflight I/O in

shared memory")

---
 contrib/libvhost-user/libvhost-user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/libvhost-user/libvhost-user.c +1 -1
index 68c27136ae..ec27b78ff1 100644
@@ -992,7 +992,7 @@ vu_check_queue_inflights(VuDev *dev, VuVirtq *vq)
     vq->shadow_avail_idx = vq->last_avail_idx = vq->inuse + vq->used_idx;
 
     if (vq->inuse) {
-        vq->resubmit_list = malloc(sizeof(VuVirtqInflightDesc) * vq->inuse);
+        vq->resubmit_list = calloc(vq->inuse, sizeof(VuVirtqInflightDesc));
         if (!vq->resubmit_list) {
             return -1;
         }
Signature · 1 line
2.17.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · On Tue, Nov 19, 2019 at 11:58 AM <[email protected]> wrote:

From: Xie Yongji <[email protected]>

Use a zero-initialized VuVirtqInflightDesc struct to avoid that scan-build reports that vq->resubmit_list[0].counter may be garbage value in vu_check_queue_inflights().

Fixes 5f9ff1eff ("libvhost-user: Support tracking inflight I/O in

shared memory")

Quoted 20 lines
---
 contrib/libvhost-user/libvhost-user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
contrib/libvhost-user/libvhost-user.c +1 -2
index 68c27136ae..ec27b78ff1 100644
@@ -992,7 +992,7 @@ vu_check_queue_inflights(VuDev *dev, VuVirtq *vq)
     vq->shadow_avail_idx = vq->last_avail_idx = vq->inuse + vq->used_idx;
 
     if (vq->inuse) {
-        vq->resubmit_list = malloc(sizeof(VuVirtqInflightDesc) * vq->inuse);
+        vq->resubmit_list = calloc(vq->inuse, sizeof(VuVirtqInflightDesc));
         if (!vq->resubmit_list) {
             return -1;
         }
--

2.17.1