Skip to contentSkip to conversation

hw/vfio-user: fix use of uninitialized variable

PATCH In review John Levon 3 participants 3 messages Jul 8, 2025 – Jul 15, 2025

lore
Share & tools
lore

John Levon

author
#0 lore raw

PATCH 1/1 hw/vfio-user: fix use of uninitialized variable

Coverity reported:

CID 1611805: Uninitialized variables

in vfio_user_dma_map(). This can occur in the happy path when ->async_ops was not set; as this doesn't typically happen, it wasn't caught during testing.

Align both map and unmap implementations to initialize ret the same way to resolve this.

---
 hw/vfio-user/container.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
hw/vfio-user/container.c +1 -5
index d318e6a339..d589dd90f5 100644
@@ -64,8 +64,6 @@ static int vfio_user_dma_unmap(const VFIOContainerBase *bcontainer,
                               0, &local_err)) {
             error_report_err(local_err);
             ret = -EFAULT;
-        } else {
-            ret = 0;
         }
     } else {
         if (!vfio_user_send_wait(container->proxy, &msgp->hdr, NULL,
@@ -92,7 +90,7 @@ static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                                                 bcontainer);
     int fd = memory_region_get_fd(mrp);
     Error *local_err = NULL;
-    int ret;
+    int ret = 0;
 
     VFIOUserFDs *fds = NULL;
     VFIOUserDMAMap *msgp = g_malloc0(sizeof(*msgp));
@@ -135,8 +133,6 @@ static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                               0, &local_err)) {
             error_report_err(local_err);
             ret = -EFAULT;
-        } else {
-            ret = 0;
         }
     } else {
         VFIOUserFDs local_fds = { 1, 0, &fd };
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 40 lines · John Levon

Coverity reported:

CID 1611805: Uninitialized variables

in vfio_user_dma_map(). This can occur in the happy path when ->async_ops was not set; as this doesn't typically happen, it wasn't caught during testing.

Align both map and unmap implementations to initialize ret the same way to resolve this.

---
  hw/vfio-user/container.c | 6 +-----
  1 file changed, 1 insertion(+), 5 deletions(-)
hw/vfio-user/container.c +1 -3
index d318e6a339..d589dd90f5 100644
@@ -64,8 +64,6 @@ static int vfio_user_dma_unmap(const VFIOContainerBase *bcontainer,
                                0, &local_err)) {
              error_report_err(local_err);
              ret = -EFAULT;
-        } else {
-            ret = 0;
          }
      } else {
          if (!vfio_user_send_wait(container->proxy, &msgp->hdr, NULL,
@@ -92,7 +90,7 @@ static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                                                  bcontainer);
      int fd = memory_region_get_fd(mrp);
      Error *local_err = NULL;
-    int ret;
+    int ret = 0;
 
      VFIOUserFDs *fds = NULL;
      VFIOUserDMAMap *msgp = g_malloc0(sizeof(*msgp));

hw/vfio-user/container.c static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova, · line 138

Quoted 8 lines
hw/vfio-user/container.c +0 -2
@@ -135,8 +133,6 @@ static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                                0, &local_err)) {
              error_report_err(local_err);
              ret = -EFAULT;
-        } else {
-            ret = 0;
          }
      } else {
          VFIOUserFDs local_fds = { 1, 0, &fd };

ATB,

Mark.

Reviewed-by on v1 1/1
#2 lore raw
In reply to John Levon
Quoted 10 lines · John Levon

Coverity reported:

CID 1611805: Uninitialized variables

in vfio_user_dma_map(). This can occur in the happy path when ->async_ops was not set; as this doesn't typically happen, it wasn't caught during testing.

Align both map and unmap implementations to initialize ret the same way to resolve this.

This is not a strict rule, but a trailer like the one below is usually added for Coverity fixes :

Resolves: Coverity CID 1611805

In case you resend, please do so.

Quoted 2 lines

Thanks,

C.

Quoted 35 lines
---
  hw/vfio-user/container.c | 6 +-----
  1 file changed, 1 insertion(+), 5 deletions(-)
hw/vfio-user/container.c +1 -5
index d318e6a339..d589dd90f5 100644
@@ -64,8 +64,6 @@ static int vfio_user_dma_unmap(const VFIOContainerBase *bcontainer,
                                0, &local_err)) {
              error_report_err(local_err);
              ret = -EFAULT;
-        } else {
-            ret = 0;
          }
      } else {
          if (!vfio_user_send_wait(container->proxy, &msgp->hdr, NULL,
@@ -92,7 +90,7 @@ static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                                                  bcontainer);
      int fd = memory_region_get_fd(mrp);
      Error *local_err = NULL;
-    int ret;
+    int ret = 0;
 
      VFIOUserFDs *fds = NULL;
      VFIOUserDMAMap *msgp = g_malloc0(sizeof(*msgp));
@@ -135,8 +133,6 @@ static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
                                0, &local_err)) {
              error_report_err(local_err);
              ret = -EFAULT;
-        } else {
-            ret = 0;
          }
      } else {
          VFIOUserFDs local_fds = { 1, 0, &fd };