From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id C57AD20BD for ; Thu, 3 May 2018 15:03:31 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 May 2018 06:03:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,358,1520924400"; d="scan'208";a="36574182" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga007.fm.intel.com with ESMTP; 03 May 2018 06:03:20 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id w43D3Jcx001112; Thu, 3 May 2018 14:03:19 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id w43D3JBS015054; Thu, 3 May 2018 14:03:19 +0100 Received: (from aburakov@localhost) by sivswdev01.ir.intel.com with LOCAL id w43D3Jp0015050; Thu, 3 May 2018 14:03:19 +0100 From: Anatoly Burakov To: dev@dpdk.org Cc: anatoly.burakov@intel.com Date: Thu, 3 May 2018 14:03:19 +0100 Message-Id: <6b44bd0289f777e181eb4007005ad3b466beafde.1525352308.git.anatoly.burakov@intel.com> X-Mailer: git-send-email 1.7.0.7 Subject: [dpdk-dev] [PATCH] memalloc: fix potential underflow on mem size calculation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 May 2018 13:03:33 -0000 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") Cc: anatoly.burakov@intel.com Signed-off-by: Anatoly Burakov --- lib/librte_eal/common/eal_common_memory.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/librte_eal/common/eal_common_memory.c b/lib/librte_eal/common/eal_common_memory.c index 4c943b0..a1e07d8 100644 --- a/lib/librte_eal/common/eal_common_memory.c +++ b/lib/librte_eal/common/eal_common_memory.c @@ -429,6 +429,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; -- 2.7.4