Currently, when performing IPsec security association operations and
retrieving device capabilities, we are using rte_malloc followed by
immediate rte_free. This memory does not need to be stored in hugepage
memory and the allocation size can be pretty small, so replace with stack
allocation.

Signed-off-by: Anatoly Burakov <[email protected]>
Acked-by: Bruce Richardson <[email protected]>
---
 drivers/net/intel/iavf/iavf_ipsec_crypto.c | 122 +++++++--------------
 1 file changed, 38 insertions(+), 84 deletions(-)

diff --git a/drivers/net/intel/iavf/iavf_ipsec_crypto.c 
b/drivers/net/intel/iavf/iavf_ipsec_crypto.c
index aa4cf1d96d..98aa8b115b 100644
--- a/drivers/net/intel/iavf/iavf_ipsec_crypto.c
+++ b/drivers/net/intel/iavf/iavf_ipsec_crypto.c
@@ -3,6 +3,7 @@
  */
 
 #include <stdalign.h>
+#include <stdlib.h>
 
 #include <rte_cryptodev.h>
 #include <rte_ethdev.h>
@@ -902,29 +903,18 @@ static uint32_t
 iavf_ipsec_crypto_sa_del(struct iavf_adapter *adapter,
        struct iavf_security_session *sess)
 {
-       struct inline_ipsec_msg *request = NULL, *response = NULL;
-       size_t request_len, response_len;
+       struct {
+               struct inline_ipsec_msg msg;
+               struct virtchnl_ipsec_sa_destroy sa_destroy;
+       } req = {0};
+       struct {
+               struct inline_ipsec_msg msg;
+               struct virtchnl_ipsec_resp resp;
+       } resp = {0};
+       struct inline_ipsec_msg *request = &req.msg, *response = &resp.msg;
 
        int rc = 0;
 
-       request_len = sizeof(struct inline_ipsec_msg) +
-                       sizeof(struct virtchnl_ipsec_sa_destroy);
-
-       request = rte_malloc("iavf-sa-del-request", request_len, 0);
-       if (request == NULL) {
-               rc = -ENOMEM;
-               goto update_cleanup;
-       }
-
-       response_len = sizeof(struct inline_ipsec_msg) +
-                       sizeof(struct virtchnl_ipsec_resp);
-
-       response = rte_malloc("iavf-sa-del-response", response_len, 0);
-       if (response == NULL) {
-               rc = -ENOMEM;
-               goto update_cleanup;
-       }
-
        /* set msg header params */
        request->ipsec_opcode = INLINE_IPSEC_OP_SA_DESTROY;
        request->req_id = (uint16_t)0xDEADBEEF;
@@ -942,10 +932,10 @@ iavf_ipsec_crypto_sa_del(struct iavf_adapter *adapter,
 
        /* send virtual channel request to add SA to hardware database */
        rc = iavf_ipsec_crypto_request(adapter,
-                       (uint8_t *)request, request_len,
-                       (uint8_t *)response, response_len);
+                       (uint8_t *)request, sizeof(req),
+                       (uint8_t *)response, sizeof(resp));
        if (rc)
-               goto update_cleanup;
+               return rc;
 
        /* verify response */
        if (response->ipsec_opcode != request->ipsec_opcode ||
@@ -960,10 +950,6 @@ iavf_ipsec_crypto_sa_del(struct iavf_adapter *adapter,
                        response->ipsec_data.ipsec_status->status)
                rc = -EFAULT;
 
-update_cleanup:
-       rte_free(response);
-       rte_free(request);
-
        return rc;
 }
 
@@ -1109,51 +1095,35 @@ static int
 iavf_ipsec_crypto_device_capabilities_get(struct iavf_adapter *adapter,
                struct virtchnl_ipsec_cap *capability)
 {
+       struct {
+               struct inline_ipsec_msg msg;
+       } req = {0};
+       struct {
+               struct inline_ipsec_msg msg;
+               struct virtchnl_ipsec_cap cap;
+       } resp = {0};
        /* Perform pf-vf comms */
-       struct inline_ipsec_msg *request = NULL, *response = NULL;
-       size_t request_len, response_len;
+       struct inline_ipsec_msg *request = &req.msg, *response = &resp.msg;
        int rc;
 
-       request_len = sizeof(struct inline_ipsec_msg);
-
-       request = rte_malloc("iavf-device-capability-request", request_len, 0);
-       if (request == NULL) {
-               rc = -ENOMEM;
-               goto update_cleanup;
-       }
-
-       response_len = sizeof(struct inline_ipsec_msg) +
-                       sizeof(struct virtchnl_ipsec_cap);
-       response = rte_malloc("iavf-device-capability-response",
-                       response_len, 0);
-       if (response == NULL) {
-               rc = -ENOMEM;
-               goto update_cleanup;
-       }
-
        /* set msg header params */
        request->ipsec_opcode = INLINE_IPSEC_OP_GET_CAP;
        request->req_id = (uint16_t)0xDEADBEEF;
 
        /* send virtual channel request to add SA to hardware database */
        rc = iavf_ipsec_crypto_request(adapter,
-                       (uint8_t *)request, request_len,
-                       (uint8_t *)response, response_len);
+                       (uint8_t *)request, sizeof(req),
+                       (uint8_t *)response, sizeof(resp));
        if (rc)
-               goto update_cleanup;
+               return rc;
 
        /* verify response id */
        if (response->ipsec_opcode != request->ipsec_opcode ||
                response->req_id != request->req_id){
-               rc = -EFAULT;
-               goto update_cleanup;
+               return -EFAULT;
        }
        memcpy(capability, response->ipsec_data.ipsec_cap, sizeof(*capability));
 
-update_cleanup:
-       rte_free(response);
-       rte_free(request);
-
        return rc;
 }
 
@@ -1535,50 +1505,34 @@ iavf_ipsec_crypto_status_get(struct iavf_adapter 
*adapter,
                struct virtchnl_ipsec_status *status)
 {
        /* Perform pf-vf comms */
-       struct inline_ipsec_msg *request = NULL, *response = NULL;
-       size_t request_len, response_len;
+       struct {
+               struct inline_ipsec_msg msg;
+       } req = {0};
+       struct {
+               struct inline_ipsec_msg msg;
+               struct virtchnl_ipsec_cap cap;
+       } resp = {0};
+       struct inline_ipsec_msg *request = &req.msg, *response = &resp.msg;
        int rc;
 
-       request_len = sizeof(struct inline_ipsec_msg);
-
-       request = rte_malloc("iavf-device-status-request", request_len, 0);
-       if (request == NULL) {
-               rc = -ENOMEM;
-               goto update_cleanup;
-       }
-
-       response_len = sizeof(struct inline_ipsec_msg) +
-                       sizeof(struct virtchnl_ipsec_cap);
-       response = rte_malloc("iavf-device-status-response",
-                       response_len, 0);
-       if (response == NULL) {
-               rc = -ENOMEM;
-               goto update_cleanup;
-       }
-
        /* set msg header params */
        request->ipsec_opcode = INLINE_IPSEC_OP_GET_STATUS;
        request->req_id = (uint16_t)0xDEADBEEF;
 
        /* send virtual channel request to add SA to hardware database */
        rc = iavf_ipsec_crypto_request(adapter,
-                       (uint8_t *)request, request_len,
-                       (uint8_t *)response, response_len);
+                       (uint8_t *)request, sizeof(req),
+                       (uint8_t *)response, sizeof(resp));
        if (rc)
-               goto update_cleanup;
+               return rc;
 
        /* verify response id */
        if (response->ipsec_opcode != request->ipsec_opcode ||
-               response->req_id != request->req_id){
-               rc = -EFAULT;
-               goto update_cleanup;
+                       response->req_id != request->req_id){
+               return -EFAULT;
        }
        memcpy(status, response->ipsec_data.ipsec_status, sizeof(*status));
 
-update_cleanup:
-       rte_free(response);
-       rte_free(request);
-
        return rc;
 }
 
-- 
2.47.3

Reply via email to