From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 01CBBA04A2 for ; Thu, 3 Mar 2022 10:43:35 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BEF3E40141; Thu, 3 Mar 2022 10:43:35 +0100 (CET) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by mails.dpdk.org (Postfix) with ESMTP id 0404740141 for ; Thu, 3 Mar 2022 10:43:33 +0100 (CET) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4K8Qsk48J2z1GC9L; Thu, 3 Mar 2022 17:38:50 +0800 (CST) Received: from dggpemm500008.china.huawei.com (7.185.36.136) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 3 Mar 2022 17:43:31 +0800 Received: from localhost (10.174.242.157) by dggpemm500008.china.huawei.com (7.185.36.136) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Thu, 3 Mar 2022 17:43:31 +0800 From: Yunjian Wang To: CC: , , Yunjian Wang Subject: [PATCH 19.11] mem: check allocation in dynamic hugepage init Date: Thu, 3 Mar 2022 17:43:26 +0800 Message-ID: <505cb50dee6a782d2e1b5ebca4c6431267f65cef.1646117028.git.wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.242.157] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500008.china.huawei.com (7.185.36.136) X-CFilter-Loop: Reflected X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org [ upstream commit 5f69ebbd85300a197bbe9e6a630642352f5aba39 ] The function malloc() could return NULL, the return value need to be checked. Fixes: 6f63858e55e6 ("mem: prevent preallocated pages from being freed") Signed-off-by: Yunjian Wang Reviewed-by: David Marchand --- lib/librte_eal/linux/eal/eal_memory.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/librte_eal/linux/eal/eal_memory.c b/lib/librte_eal/linux/eal/eal_memory.c index c93d9bb2b8..dc0cdcbe25 100644 --- a/lib/librte_eal/linux/eal/eal_memory.c +++ b/lib/librte_eal/linux/eal/eal_memory.c @@ -1818,6 +1818,10 @@ eal_hugepage_init(void) needed = num_pages - num_pages_alloc; pages = malloc(sizeof(*pages) * needed); + if (pages == NULL) { + RTE_LOG(ERR, EAL, "Failed to malloc pages\n"); + return -1; + } /* do not request exact number of pages */ cur_pages = eal_memalloc_alloc_seg_bulk(pages, -- 2.27.0