diff mbox

libxenforeignmemory: handle partial failure correctly

Message ID 1454494201-14910-1-git-send-email-ian.campbell@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ian Campbell Feb. 3, 2016, 10:10 a.m. UTC
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

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
---
 tools/libs/foreignmemory/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Wei Liu Feb. 3, 2016, 10:17 a.m. UTC | #1
On Wed, Feb 03, 2016 at 10:10:01AM +0000, Ian Campbell wrote:
> 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
> 
> Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

Acked-by: Wei Liu <wei.liu2@citrix.com>

> ---
>  tools/libs/foreignmemory/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/libs/foreignmemory/core.c b/tools/libs/foreignmemory/core.c
> index 6591888..a872b95 100644
> --- a/tools/libs/foreignmemory/core.c
> +++ b/tools/libs/foreignmemory/core.c
> @@ -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;
>  
> -- 
> 2.1.4
>
Ian Campbell Feb. 3, 2016, 11:49 a.m. UTC | #2
On Wed, 2016-02-03 at 10:17 +0000, Wei Liu wrote:
> On Wed, Feb 03, 2016 at 10:10:01AM +0000, Ian Campbell wrote:
> > 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
> > 
> > Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
> 
> Acked-by: Wei Liu <wei.liu2@citrix.com>

Applied, thanks.
diff mbox

Patch

diff --git a/tools/libs/foreignmemory/core.c b/tools/libs/foreignmemory/core.c
index 6591888..a872b95 100644
--- a/tools/libs/foreignmemory/core.c
+++ b/tools/libs/foreignmemory/core.c
@@ -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;