From f314f0ca4f1630941332f50489a5e5c6aeae5524 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Tue, 21 Feb 2017 15:56:23 -0700 Subject: [PATCH] env/vtophys: eliminate redundant error check Change-Id: I238b02e2df154b2ac40c746f156c0746f2518764 Signed-off-by: Daniel Verkamp --- lib/env_dpdk/vtophys.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/env_dpdk/vtophys.c b/lib/env_dpdk/vtophys.c index 849242b48..9edc9942e 100644 --- a/lib/env_dpdk/vtophys.c +++ b/lib/env_dpdk/vtophys.c @@ -43,6 +43,8 @@ #include #include +#include "spdk/assert.h" + /* x86-64 userspace virtual addresses use only the low 47 bits [0..46], * which is enough to cover 128 TB. */ @@ -344,9 +346,12 @@ spdk_vtophys(void *buf) map_2mb = &map_1gb->map[idx_1gb]; paddr_2mb = map_2mb->paddr_2mb; - if (paddr_2mb == SPDK_VTOPHYS_ERROR) { - return SPDK_VTOPHYS_ERROR; - } + /* + * SPDK_VTOPHYS_ERROR has all bits set, so if the lookup returned SPDK_VTOPHYS_ERROR, + * we will still bitwise-or it with the buf offset below, but the result will still be + * SPDK_VTOPHYS_ERROR. + */ + SPDK_STATIC_ASSERT(SPDK_VTOPHYS_ERROR == UINT64_C(-1), "SPDK_VTOPHYS_ERROR should be all 1s"); return paddr_2mb | ((uint64_t)buf & MASK_2MB); }