eal: fix device unregister for event registered with device_name NULL

Message ID 1721331448-9225-1-git-send-email-longli@linuxonhyperv.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series eal: fix device unregister for event registered with device_name NULL |

Checks

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

Commit Message

Long Li July 18, 2024, 7:37 p.m. UTC
From: Malcolm Bumgardner <mbumgard@cisco.com>

In the device event unregister code, it unconditionally remove all
callbacks which are registered with device_name set to NULL. This results
in many callbacks uncorrectly removed.

Fix this by only removing callbacks with matching cb_fn and cb_arg.

Signed-off-by: Malcolm Bumgardner <mbumgard@cisco.com>

Fixes: a753e53d517b ("eal: add device event monitor framework")
Cc: stable@dpdk.org
Signed-off-by: Long Li <longli@microsoft.com>
---
 lib/eal/common/eal_common_dev.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
  

Patch

diff --git a/lib/eal/common/eal_common_dev.c b/lib/eal/common/eal_common_dev.c
index a99252b02f..70aa04dcd9 100644
--- a/lib/eal/common/eal_common_dev.c
+++ b/lib/eal/common/eal_common_dev.c
@@ -550,16 +550,17 @@  rte_dev_event_callback_unregister(const char *device_name,
 		next = TAILQ_NEXT(event_cb, next);
 
 		if (device_name != NULL && event_cb->dev_name != NULL) {
-			if (!strcmp(event_cb->dev_name, device_name)) {
-				if (event_cb->cb_fn != cb_fn ||
-				    (cb_arg != (void *)-1 &&
-				    event_cb->cb_arg != cb_arg))
-					continue;
-			}
+			if (strcmp(event_cb->dev_name, device_name))
+				continue;
 		} else if (device_name != NULL) {
 			continue;
 		}
 
+		/* Remove only matching callback with arg */
+		if (event_cb->cb_fn != cb_fn ||
+		    (cb_arg != (void *)-1 && event_cb->cb_arg != cb_arg))
+			continue;
+
 		/*
 		 * if this callback is not executing right now,
 		 * then remove it.