ethdev: fix crash if malloc of user callback fails
authorStephen Hemminger <stephen@networkplumber.org>
Thu, 16 Jul 2015 23:47:23 +0000 (16:47 -0700)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 22 Jul 2015 13:57:57 +0000 (15:57 +0200)
Found by coccinelle script.
If rte_zmalloc() failed in rte_eth_dev_callback_register
then NULL pointer would be dereferenced.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Thomas Monjalon <thomas.monjalon@6wind.com>
[Thomas: restore pointer comparison style]

lib/librte_ether/rte_ethdev.c

index 94104ce..8751801 100644 (file)
@@ -2954,9 +2954,10 @@ rte_eth_dev_callback_register(uint8_t port_id,
        }
 
        /* create a new callback. */
-       if (user_cb == NULL &&
-           (user_cb = rte_zmalloc("INTR_USER_CALLBACK",
-                                  sizeof(struct rte_eth_dev_callback), 0))) {
+       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;