[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH XEN v6 20/32] tools/libs/foreignmemory: Support err == NULL to map.


  • To: <xen-devel@xxxxxxxxxxxxx>
  • From: "Egger, Christoph" <chegger@xxxxxxxxx>
  • Date: Wed, 9 Dec 2015 13:31:41 +0100
  • Delivery-date: Wed, 09 Dec 2015 12:32:29 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xen.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 <ian.campbell@xxxxxxxxxx>
>> ---
>> 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 <stdlib.h>
>> +#include <assert.h>
>> +#include <errno.h>
>>  
>>  #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


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.