[v1,1/1] malloc: handle invalid socket ID's when allocating

Message ID 02ee77dec888cd2ece830f63c5163c4ad7d3d3a5.1750067739.git.anatoly.burakov@intel.com (mailing list archive)
State Accepted
Delegated to: Thomas Monjalon
Headers
Series [v1,1/1] malloc: handle invalid socket ID's when allocating |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/github-robot: build success github build: passed
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing fail Testing issues
ci/iol-unit-arm64-testing pending Testing pending
ci/iol-abi-testing success Testing PASS
ci/aws-unit-testing success Unit Testing PASS
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-amd64-testing fail Testing issues

Commit Message

Burakov, Anatoly June 16, 2025, 9:55 a.m. UTC
This issue was reported by static analysis. It is a false positive,
because both `rte_socket_count` and `rte_socket_id_by_idx` only report
information about physical sockets (so return value of -1 cannot happen,
as we only get into this function when socket ID parameter is -1, which
excludes external memory from consideration), but to avoid future false
positives, we can fix it here.

Coverity issue: 470137

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/eal/common/malloc_heap.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Thomas Monjalon June 27, 2025, 10:44 a.m. UTC | #1
16/06/2025 11:55, Anatoly Burakov:
> This issue was reported by static analysis. It is a false positive,
> because both `rte_socket_count` and `rte_socket_id_by_idx` only report
> information about physical sockets (so return value of -1 cannot happen,
> as we only get into this function when socket ID parameter is -1, which
> excludes external memory from consideration), but to avoid future false
> positives, we can fix it here.
> 
> Coverity issue: 470137
> 
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied, thanks.
  

Patch

diff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c
index f87a947a42..13a56e490e 100644
--- a/lib/eal/common/malloc_heap.c
+++ b/lib/eal/common/malloc_heap.c
@@ -710,8 +710,9 @@  malloc_get_numa_socket(void)
 
 	/* for control threads, return first socket where memory is available */
 	for (idx = 0; idx < rte_socket_count(); idx++) {
-		socket_id = rte_socket_id_by_idx(idx);
-		if (conf->numa_mem[socket_id] != 0)
+		int ret = rte_socket_id_by_idx(idx);
+		socket_id = (unsigned int)ret;
+		if (ret != -1 && conf->numa_mem[socket_id] != 0)
 			return socket_id;
 	}
 	/* We couldn't quickly find a NUMA node where memory was available,