From eb9d77a910ab3e6d9b94e4750a7f4138ad02e443 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 27 Jun 2016 09:35:05 -0700 Subject: [PATCH] test/nvme: allocate aligned memory in unit tests Match the expected alignment for nvme_alloc_request() and nvme_malloc() to allow optimized memory copy code to work even in the unit tests. Change-Id: I546692a6df9615a12a8209618fb6159a9c9e426b Signed-off-by: Daniel Verkamp --- test/lib/nvme/unit/nvme_impl.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/lib/nvme/unit/nvme_impl.h b/test/lib/nvme/unit/nvme_impl.h index 05c0f973d..0ba92b122 100644 --- a/test/lib/nvme/unit/nvme_impl.h +++ b/test/lib/nvme/unit/nvme_impl.h @@ -47,7 +47,10 @@ struct spdk_pci_device; static inline void * nvme_malloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr) { - void *buf = calloc(1, size); + void *buf = NULL; + if (posix_memalign(&buf, align, size)) { + return NULL; + } *phys_addr = (uint64_t)buf; return buf; } @@ -74,7 +77,9 @@ uint64_t nvme_vtophys(void *buf); #define nvme_alloc_request(bufp) \ do \ { \ - *bufp = malloc(sizeof(struct nvme_request)); \ + if (posix_memalign((void **)(bufp), 64, sizeof(struct nvme_request))) { \ + *(bufp) = NULL; \ + } \ } \ while (0)