From mboxrd@z Thu Jan 1 00:00:00 1970 From: Wei Liu Subject: Re: [PATCH XEN v6 20/32] tools/libs/foreignmemory: Support err == NULL to map. Date: Wed, 9 Dec 2015 12:22:19 +0000 Message-ID: <20151209122219.GH23818@citrix.com> References: <1449141675.4424.125.camel@citrix.com> <1449141749-14940-1-git-send-email-ian.campbell@citrix.com> <1449141749-14940-21-git-send-email-ian.campbell@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <1449141749-14940-21-git-send-email-ian.campbell@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Campbell Cc: wei.liu2@citrix.com, ian.jackson@eu.citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Thu, Dec 03, 2015 at 11:22:17AM +0000, Ian Campbell wrote: > The existing xc_map_foreign_bulk-like interface encourages callers to > miss error checking for partial failure (by forgetting to scan the err > array). > > Add support for passing err==NULL which behaves in a > xc_map_foreign_pages-like manner and returns a global error for any > failure. > > While documenting this also clarify the overall behaviour and the > behaviour with err!=NULL. > > With this the compat wrapper of xc_map_foreign_pages() can be > simplified. > > Signed-off-by: Ian Campbell > --- > v6: New > --- > tools/libs/foreignmemory/core.c | 30 +++++++++++++++++++++- > .../libs/foreignmemory/include/xenforeignmemory.h | 24 ++++++++++++++--- > tools/libxc/xc_foreign_memory.c | 22 +--------------- > 3 files changed, 51 insertions(+), 25 deletions(-) > > diff --git a/tools/libs/foreignmemory/core.c b/tools/libs/foreignmemory/core.c > index 21dc7ee..91bea55 100644 > --- a/tools/libs/foreignmemory/core.c > +++ b/tools/libs/foreignmemory/core.c > @@ -14,6 +14,8 @@ > */ > > #include > +#include > +#include > > #include "private.h" > > @@ -64,7 +66,33 @@ void *xenforeignmemory_map(xenforeignmemory_handle *fmem, > uint32_t dom, int prot, > const xen_pfn_t *arr, int *err, size_t num) > { > - return osdep_xenforeignmemory_map(fmem, dom, prot, arr, err, num); > + void *ret; > + int *err_to_free = NULL; > + > + if ( err == NULL ) > + err = err_to_free = malloc(num * sizeof(int)); > + malloc can fail, which means when user passes in err==NULL there is two possible behaviours of this function? Wei.