Skip to contentSkip to conversation

libxenforeignmemory: handle partial failure correctly

PATCH In review Ian Campbell 2 participants 3 messages Feb 3, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxenforeignmemory: handle partial failure correctly

Coverity rightly points out that checking for ret == NULL and then calling osdep unmap(ret) is wrong.

The intention on this code path is to turn partial failure into total failure when the err argument is NULL, so we want to take this patch whenever ret is _non_ NULL (and err_to_free is set, indicating err was NULL).

CID: 1351219

---
 tools/libs/foreignmemory/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libs/foreignmemory/core.c +1 -1
index 6591888..a872b95 100644
@@ -79,7 +79,7 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
 
     ret = osdep_xenforeignmemory_map(fmem, dom, prot, num, arr, err);
 
-    if ( ret == 0 && err_to_free )
+    if ( ret && err_to_free )
     {
         int i;
 
Signature · 1 line
2.1.4
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Ian Campbell

Coverity rightly points out that checking for ret == NULL and then calling osdep unmap(ret) is wrong.

The intention on this code path is to turn partial failure into total failure when the err argument is NULL, so we want to take this patch whenever ret is _non_ NULL (and err_to_free is set, indicating err was NULL).

CID: 1351219

Quoted 20 lines
---
 tools/libs/foreignmemory/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libs/foreignmemory/core.c +1 -1
index 6591888..a872b95 100644
@@ -79,7 +79,7 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem,
 
     ret = osdep_xenforeignmemory_map(fmem, dom, prot, num, arr, err);
 
-    if ( ret == 0 && err_to_free )
+    if ( ret && err_to_free )
     {
         int i;
 
Signature · 1 line
2.1.4
author Applied
#2 lore raw
Quoted 9 lines · Wei Liu
Quoted 8 lines · Ian Campbell

Coverity rightly points out that checking for ret == NULL and then calling osdep unmap(ret) is wrong.

The intention on this code path is to turn partial failure into total failure when the err argument is NULL, so we want to take this patch whenever ret is _non_ NULL (and err_to_free is set, indicating err was NULL).

Quoted 5 lines
Quoted 3 lines

CID: 1351219

Applied, thanks.