[1/1] mem: check allocation in dynamic hugepage init

Message ID 3d5cb5cba8ee4ae1d1de5eba1d009eaffbb49062.1639488393.git.wangyunjian@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [1/1] mem: check allocation in dynamic hugepage init |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS

Commit Message

Yunjian Wang Dec. 14, 2021, 1:30 p.m. UTC
  The function malloc() could return NULL, the return value
need to be checked.

Fixes: 694161b7e065 ("mem: extract common dynamic memory allocation")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 lib/eal/common/eal_common_dynmem.c | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

David Marchand Feb. 5, 2022, 5:29 p.m. UTC | #1
On Tue, Dec 14, 2021 at 2:30 PM Yunjian Wang <wangyunjian@huawei.com> wrote:
>
> The function malloc() could return NULL, the return value
> need to be checked.
>
> Fixes: 694161b7e065 ("mem: extract common dynamic memory allocation")
> Cc: stable@dpdk.org
>
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
  
David Marchand Feb. 11, 2022, 7:55 a.m. UTC | #2
On Sat, Feb 5, 2022 at 6:29 PM David Marchand <david.marchand@redhat.com> wrote:
>
> On Tue, Dec 14, 2021 at 2:30 PM Yunjian Wang <wangyunjian@huawei.com> wrote:
> >
> > The function malloc() could return NULL, the return value
> > need to be checked.
> >
> > Fixes: 694161b7e065 ("mem: extract common dynamic memory allocation")

That's actually introduced with:
Fixes: 6f63858e55e6 ("mem: prevent preallocated pages from being freed")

> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> Reviewed-by: David Marchand <david.marchand@redhat.com>

Applied, thanks.
  

Patch

diff --git a/lib/eal/common/eal_common_dynmem.c b/lib/eal/common/eal_common_dynmem.c
index 7c5437ddfa..c1e1889f5c 100644
--- a/lib/eal/common/eal_common_dynmem.c
+++ b/lib/eal/common/eal_common_dynmem.c
@@ -304,6 +304,10 @@  eal_dynmem_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,