diff options
author | Michael S. Tsirkin <mst@redhat.com> | 2017-12-08 17:31:37 +0200 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2017-12-08 17:48:38 +0200 |
commit | 5790eabc6e7c3ce2d6ca2e3bbf4de467ce2b64b3 (patch) | |
tree | 77e1e4e07d54194dfb71cbb4604b6985c99978a9 /tools/virtio | |
parent | 03e9f8a05bce7330bcd9c5cc54c8e42d0fcbf993 (diff) | |
download | linux-5790eabc6e7c3ce2d6ca2e3bbf4de467ce2b64b3.tar.gz linux-5790eabc6e7c3ce2d6ca2e3bbf4de467ce2b64b3.tar.bz2 linux-5790eabc6e7c3ce2d6ca2e3bbf4de467ce2b64b3.zip |
ptr_ring: fix up after recent ptr_ring changes
Add more stubs to make it build.
Fixes: 81fbfe8a ("ptr_ring: use kmalloc_array()")
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Diffstat (limited to 'tools/virtio')
-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) |