[dpdk-dev,v2] lib/ether: prevent duplicate callback on list

Message ID 1476970481-21034-1-git-send-email-daniels@research.att.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Scott Daniels Oct. 20, 2016, 1:34 p.m. UTC
  This change prevents the attempt to add a structure which is
already on the callback list. If a struct with matching
parameters is found on the list, then no action is taken. If
a struct with matching parameters is found on the list, then
no action is taken.

Fixes: ac2f69c ("ethdev: fix crash if malloc of user callback fails")

Signed-off-by: E. Scott Daniels <daniels@research.att.com>
---

V2:
* Correct the component name; changed from net/ixgbe.
* Add Fixes tag.
* Acked-by: Wenzhuo Lu <Wenzhuo.lu@intel.com>

 lib/librte_ether/rte_ethdev.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
  

Comments

Thomas Monjalon Oct. 25, 2016, 9:35 p.m. UTC | #1
2016-10-20 09:34, E. Scott Daniels:
> This change prevents the attempt to add a structure which is
> already on the callback list. If a struct with matching
> parameters is found on the list, then no action is taken. If
> a struct with matching parameters is found on the list, then
> no action is taken.

Callback is not duplicate anymore but the last sentence is duplicate :)

> Fixes: ac2f69c ("ethdev: fix crash if malloc of user callback fails")
> 
> Signed-off-by: E. Scott Daniels <daniels@research.att.com>
> ---
> 
> V2:
> * Correct the component name; changed from net/ixgbe.
> * Add Fixes tag.
> * Acked-by: Wenzhuo Lu <Wenzhuo.lu@intel.com>

The Acked-by tag must be added below your Signed-off-by.

Applied with above nits fixed, thanks
  

Patch

diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c
index 0d9d9c1..fde8112 100644
--- a/lib/librte_ether/rte_ethdev.c
+++ b/lib/librte_ether/rte_ethdev.c
@@ -2449,14 +2449,15 @@  rte_eth_dev_callback_register(uint8_t port_id,
 	}
 
 	/* create a new callback. */
-	if (user_cb == NULL)
+	if (user_cb == NULL) {
 		user_cb = rte_zmalloc("INTR_USER_CALLBACK",
 					sizeof(struct rte_eth_dev_callback), 0);
-	if (user_cb != NULL) {
-		user_cb->cb_fn = cb_fn;
-		user_cb->cb_arg = cb_arg;
-		user_cb->event = event;
-		TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
+		if (user_cb != NULL) {
+			user_cb->cb_fn = cb_fn;
+			user_cb->cb_arg = cb_arg;
+			user_cb->event = event;
+			TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), user_cb, next);
+		}
 	}
 
 	rte_spinlock_unlock(&rte_eth_dev_cb_lock);