xcp-1.6-updates/xen-4.1.hg

changeset 23261:0bbaff574126

introduce xzalloc() & Co

Rather than having to match a call to one of the xmalloc() flavors
with a subsequent memset(), introduce a zeroing variant of each of
those flavors.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
xen-unstable changeset: 23900:e09ebf7a31f5
xen-unstable date: Tue Oct 04 14:15:26 2011 +0200
author Jan Beulich <jbeulich@suse.com>
date Thu Mar 08 10:03:35 2012 +0000 (2012-03-08)
parents 8a2e167905d3
children 7c0d02aa4742
files xen/common/xmalloc_tlsf.c xen/include/acpi/platform/aclinux.h xen/include/xen/xmalloc.h
line diff
     1.1 --- a/xen/common/xmalloc_tlsf.c	Thu Mar 08 08:58:26 2012 +0000
     1.2 +++ b/xen/common/xmalloc_tlsf.c	Thu Mar 08 10:03:35 2012 +0000
     1.3 @@ -585,6 +585,13 @@ void *_xmalloc(unsigned long size, unsig
     1.4      return p;
     1.5  }
     1.6  
     1.7 +void *_xzalloc(unsigned long size, unsigned long align)
     1.8 +{
     1.9 +    void *p = _xmalloc(size, align);
    1.10 +
    1.11 +    return p ? memset(p, 0, size) : p;
    1.12 +}
    1.13 +
    1.14  void xfree(void *p)
    1.15  {
    1.16      struct bhdr *b;
     2.1 --- a/xen/include/acpi/platform/aclinux.h	Thu Mar 08 08:58:26 2012 +0000
     2.2 +++ b/xen/include/acpi/platform/aclinux.h	Thu Mar 08 10:03:35 2012 +0000
     2.3 @@ -77,10 +77,7 @@
     2.4  #define acpi_thread_id struct vcpu *
     2.5  
     2.6  #define ACPI_ALLOCATE(a)	xmalloc_bytes(a)
     2.7 -#define ACPI_ALLOCATE_ZEROED(a)	({              \
     2.8 -    void *p = xmalloc_bytes(a);                 \
     2.9 -    if ( p ) memset(p, 0, a);                   \
    2.10 -    p; })
    2.11 +#define ACPI_ALLOCATE_ZEROED(a)	xzalloc_bytes(a)
    2.12  #define ACPI_FREE(a)		xfree(a)
    2.13  
    2.14  #endif				/* __ACLINUX_H__ */
     3.1 --- a/xen/include/xen/xmalloc.h	Thu Mar 08 08:58:26 2012 +0000
     3.2 +++ b/xen/include/xen/xmalloc.h	Thu Mar 08 10:03:35 2012 +0000
     3.3 @@ -8,19 +8,25 @@
     3.4  
     3.5  /* Allocate space for typed object. */
     3.6  #define xmalloc(_type) ((_type *)_xmalloc(sizeof(_type), __alignof__(_type)))
     3.7 +#define xzalloc(_type) ((_type *)_xzalloc(sizeof(_type), __alignof__(_type)))
     3.8  
     3.9  /* Allocate space for array of typed objects. */
    3.10  #define xmalloc_array(_type, _num) \
    3.11      ((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num))
    3.12 +#define xzalloc_array(_type, _num) \
    3.13 +    ((_type *)_xzalloc_array(sizeof(_type), __alignof__(_type), _num))
    3.14  
    3.15  /* Allocate untyped storage. */
    3.16 -#define xmalloc_bytes(_bytes) (_xmalloc(_bytes, SMP_CACHE_BYTES))
    3.17 +#define xmalloc_bytes(_bytes) _xmalloc(_bytes, SMP_CACHE_BYTES)
    3.18 +#define xzalloc_bytes(_bytes) _xzalloc(_bytes, SMP_CACHE_BYTES)
    3.19  
    3.20  /* Free any of the above. */
    3.21  extern void xfree(void *);
    3.22  
    3.23  /* Underlying functions */
    3.24  extern void *_xmalloc(unsigned long size, unsigned long align);
    3.25 +extern void *_xzalloc(unsigned long size, unsigned long align);
    3.26 +
    3.27  static inline void *_xmalloc_array(
    3.28      unsigned long size, unsigned long align, unsigned long num)
    3.29  {
    3.30 @@ -30,6 +36,15 @@ static inline void *_xmalloc_array(
    3.31   	return _xmalloc(size * num, align);
    3.32  }
    3.33  
    3.34 +static inline void *_xzalloc_array(
    3.35 +    unsigned long size, unsigned long align, unsigned long num)
    3.36 +{
    3.37 +    /* Check for overflow. */
    3.38 +    if (size && num > UINT_MAX / size)
    3.39 +        return NULL;
    3.40 +    return _xzalloc(size * num, align);
    3.41 +}
    3.42 +
    3.43  /*
    3.44   * Pooled allocator interface.
    3.45   */