eal: check peer allocation in multi-process request
authorGao Feng <davidfgao@tencent.com>
Wed, 5 Dec 2018 06:19:24 +0000 (14:19 +0800)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 19 Dec 2018 23:01:28 +0000 (00:01 +0100)
Add the check for null peer pointer like the bundle pointer in the mp request
handler. They should follow same style. And add some logs for nomem cases.

Signed-off-by: Gao Feng <davidfgao@tencent.com>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
lib/librte_eal/common/hotplug_mp.c

index 9d610a8..4052a5c 100644 (file)
@@ -200,6 +200,11 @@ handle_secondary_request(const struct rte_mp_msg *msg, const void *peer)
         * when it is ready.
         */
        bundle->peer = strdup(peer);
+       if (bundle->peer == NULL) {
+               free(bundle);
+               RTE_LOG(ERR, EAL, "not enough memory\n");
+               return send_response_to_secondary(req, -ENOMEM, peer);
+       }
 
        /**
         * We are at IPC callback thread, sync IPC is not allowed due to
@@ -313,6 +318,7 @@ handle_primary_request(const struct rte_mp_msg *msg, const void *peer)
 
        bundle = calloc(1, sizeof(*bundle));
        if (bundle == NULL) {
+               RTE_LOG(ERR, EAL, "not enough memory\n");
                resp->result = -ENOMEM;
                ret = rte_mp_reply(&mp_resp, peer);
                if (ret)
@@ -327,6 +333,15 @@ handle_primary_request(const struct rte_mp_msg *msg, const void *peer)
         * when it is ready.
         */
        bundle->peer = (void *)strdup(peer);
+       if (bundle->peer == NULL) {
+               RTE_LOG(ERR, EAL, "not enough memory\n");
+               free(bundle);
+               resp->result = -ENOMEM;
+               ret = rte_mp_reply(&mp_resp, peer);
+               if (ret)
+                       RTE_LOG(ERR, EAL, "failed to send reply to primary request\n");
+               return ret;
+       }
 
        /**
         * We are at IPC callback thread, sync IPC is not allowed due to