diff options
author | Mark Brown <broonie@kernel.org> | 2018-01-12 21:59:19 +0300 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2018-01-12 21:59:19 +0300 |
commit | 9d66a875ecc7d6dd414121e4508340d6c08f51b0 (patch) | |
tree | d446bb455780d9058efe1760745bfb63207090de /tools/virtio/ringtest/ptr_ring.c | |
parent | 987da3fe175933c28aab2293505c3597052ff0e2 (diff) | |
parent | dd1dbf94d2826a045fbbe2649d84b27d48620d56 (diff) | |
download | linux-9d66a875ecc7d6dd414121e4508340d6c08f51b0.tar.xz |
Merge branch 'acpi-gpio' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm into asoc-intel
Diffstat (limited to 'tools/virtio/ringtest/ptr_ring.c')
-rw-r--r-- | tools/virtio/ringtest/ptr_ring.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/tools/virtio/ringtest/ptr_ring.c b/tools/virtio/ringtest/ptr_ring.c index 38bb171aceba..e6e81305ef46 100644 --- a/tools/virtio/ringtest/ptr_ring.c +++ b/tools/virtio/ringtest/ptr_ring.c @@ -16,24 +16,41 @@ #define unlikely(x) (__builtin_expect(!!(x), 0)) #define likely(x) (__builtin_expect(!!(x), 1)) #define ALIGN(x, a) (((x) + (a) - 1) / (a) * (a)) +#define SIZE_MAX (~(size_t)0) + typedef pthread_spinlock_t spinlock_t; typedef int gfp_t; -static void *kmalloc(unsigned size, gfp_t gfp) -{ - return memalign(64, size); -} +#define __GFP_ZERO 0x1 -static void *kzalloc(unsigned size, gfp_t gfp) +static void *kmalloc(unsigned size, gfp_t gfp) { void *p = memalign(64, size); if (!p) return p; - memset(p, 0, size); + if (gfp & __GFP_ZERO) + memset(p, 0, size); return p; } +static inline void *kzalloc(unsigned size, gfp_t flags) +{ + return kmalloc(size, flags | __GFP_ZERO); +} + +static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) +{ + if (size != 0 && n > SIZE_MAX / size) + return NULL; + return kmalloc(n * size, flags); +} + +static inline void *kcalloc(size_t n, size_t size, gfp_t flags) +{ + return kmalloc_array(n, size, flags | __GFP_ZERO); +} + static void kfree(void *p) { if (p) |