From: Anatoly Burakov Date: Thu, 3 May 2018 13:03:19 +0000 (+0100) Subject: mem: fix potential underflow on mem size calculation X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=d2bd796d7bd45f6a14eeb68cd4b5faee244f11ec;p=dpdk.git mem: fix potential underflow on mem size calculation If total memory is already bigger than max memory, an underflow will occur on subtraction. Fix it by simply stopping whenever we already have amount of memory that is bigger than maximum. Fixes: 66cc45e293ed ("mem: replace memseg with memseg lists") Signed-off-by: Anatoly Burakov --- diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c index 4f13b58534..4f0688f9d5 100644 --- a/lib/librte_eal/common/eal_common_memory.c +++ b/lib/librte_eal/common/eal_common_memory.c @@ -458,6 +458,9 @@ memseg_primary_init(void) break; #endif + if (total_mem >= max_mem) + break; + max_type_mem = RTE_MIN(max_mem - total_mem, (uint64_t)RTE_MAX_MEM_MB_PER_TYPE << 20); max_segs = RTE_MAX_MEMSEG_PER_TYPE;