From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Egger, Christoph" Subject: Re: [PATCH XEN v6 20/32] tools/libs/foreignmemory: Support err == NULL to map. Date: Wed, 9 Dec 2015 13:31:41 +0100 Message-ID: <56681F2D.5080702@amazon.de> 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> <20151209122219.GH23818@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20151209122219.GH23818@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: xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On 2015/12/09 13:22, Wei Liu wrote: > 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? I recommend calloc(num, sizeof(int)) Christoph Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger Ust-ID: DE289237879 Eingetragen am Amtsgericht Charlottenburg HRB 149173 B