From: Stephen Hemminger Date: Thu, 16 Jul 2015 23:47:23 +0000 (-0700) Subject: ethdev: fix crash if malloc of user callback fails X-Git-Tag: spdx-start~8658 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=ac2f69c;p=dpdk.git ethdev: fix crash if malloc of user callback fails 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 Acked-by: Thomas Monjalon [Thomas: restore pointer comparison style] --- diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 94104ceba9..8751801c30 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -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;