DPDK patches and discussions
 help / color / mirror / Atom feed
From: Anatoly Burakov <anatoly.burakov@intel.com>
To: dev@dpdk.org
Subject: [PATCH v1 1/1] memory: handle invalid socket ID's when allocating
Date: Fri, 20 Jun 2025 14:30:23 +0100	[thread overview]
Message-ID: <4e785f17154922f775c56558947b2f967f25b23c.1750426216.git.anatoly.burakov@intel.com> (raw)

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, and these specific calls are made
during EAL initialization, so no other sockets (i.e. external) could have
been available, so it is pretty much impossible to get invalid return here.

Still, to avoid future false positives, we can fix it here.

Coverity issue: 470131

Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
 lib/eal/linux/eal_memory.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lib/eal/linux/eal_memory.c b/lib/eal/linux/eal_memory.c
index 59f35b415e..e433c1afee 100644
--- a/lib/eal/linux/eal_memory.c
+++ b/lib/eal/linux/eal_memory.c
@@ -1785,8 +1785,14 @@ memseg_primary_init_32(void)
 		unsigned int main_lcore_socket;
 		struct rte_config *cfg = rte_eal_get_configuration();
 		bool skip;
+		int ret;
 
-		socket_id = rte_socket_id_by_idx(i);
+		ret = rte_socket_id_by_idx(i);
+		if (ret == -1) {
+			EAL_LOG(ERR, "Cannot get socket ID for socket index %u", i);
+			return -1;
+		}
+		socket_id = (unsigned int)ret;
 
 #ifndef RTE_EAL_NUMA_AWARE_HUGEPAGES
 		/* we can still sort pages by socket in legacy mode */
-- 
2.47.1


             reply	other threads:[~2025-06-20 13:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-20 13:30 Anatoly Burakov [this message]
2025-06-20 13:37 ` Bruce Richardson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4e785f17154922f775c56558947b2f967f25b23c.1750426216.git.anatoly.burakov@intel.com \
    --to=anatoly.burakov@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).