[1/2] eal: fix wake a incorrect lcore

Message ID 20250321040316.104126-2-huangdengdui@huawei.com (mailing list archive)
State Changes Requested
Delegated to: Thomas Monjalon
Headers
Series fix the problem of dma-perf infinite loop |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Dengdui Huang March 21, 2025, 4:03 a.m. UTC
If the core is not used in the rte, we can't wake it up to work.
The worker_id may come from user input. So it is necessary to
verify it.

Fixes: a95d70547c57 ("eal: factorize lcore main loop")
Cc: stable@dpdk.org

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
---
 lib/eal/unix/eal_unix_thread.c | 3 +++
 lib/eal/windows/eal_thread.c   | 3 +++
 2 files changed, 6 insertions(+)
  

Patch

diff --git a/lib/eal/unix/eal_unix_thread.c b/lib/eal/unix/eal_unix_thread.c
index ef6cbff0ee..103571cabf 100644
--- a/lib/eal/unix/eal_unix_thread.c
+++ b/lib/eal/unix/eal_unix_thread.c
@@ -17,6 +17,9 @@  eal_thread_wake_worker(unsigned int worker_id)
 	char c = 0;
 	int n;
 
+	if (m2w == 0 || w2m == 0)
+		return -EINVAL;
+
 	do {
 		n = write(m2w, &c, 1);
 	} while (n == 0 || (n < 0 && errno == EINTR));
diff --git a/lib/eal/windows/eal_thread.c b/lib/eal/windows/eal_thread.c
index 9e3df200b9..82bb974868 100644
--- a/lib/eal/windows/eal_thread.c
+++ b/lib/eal/windows/eal_thread.c
@@ -24,6 +24,9 @@  eal_thread_wake_worker(unsigned int worker_id)
 	char c = 0;
 	int n;
 
+	if (m2w == 0 || w2m == 0)
+		return -EINVAL;
+
 	do {
 		n = _write(m2w, &c, 1);
 	} while (n == 0 || (n < 0 && errno == EINTR));