[PATCH v1 4/6] net/ixgbe: get rid of unnecessary malloc in IPsec
Anatoly Burakov
anatoly.burakov at intel.com
Tue Aug 18 15:19:30 CEST 2026
Currently, when writing SA key to HW, a temporary buffer is allocated, to
which the key is written. The allocation does not have to happen on the
heap, so change the allocation to be on the stack, as key size is known at
compile time and is pretty tiny.
Signed-off-by: Anatoly Burakov <anatoly.burakov at intel.com>
---
drivers/net/intel/ixgbe/ixgbe_ipsec.c | 22 +++-------------------
1 file changed, 3 insertions(+), 19 deletions(-)
diff --git a/drivers/net/intel/ixgbe/ixgbe_ipsec.c b/drivers/net/intel/ixgbe/ixgbe_ipsec.c
index 41fc7551ff..1d001b955b 100644
--- a/drivers/net/intel/ixgbe/ixgbe_ipsec.c
+++ b/drivers/net/intel/ixgbe/ixgbe_ipsec.c
@@ -94,10 +94,12 @@ ixgbe_crypto_add_sa(struct ixgbe_crypto_session *ic_session)
dev_data->dev_private);
uint32_t reg_val;
int sa_index = -1;
+ uint8_t key[16] = {0};
+
+ memcpy(key, ic_session->key, ic_session->key_len);
if (ic_session->op == IXGBE_OP_AUTHENTICATED_DECRYPTION) {
int i, ip_index = -1;
- uint8_t *key;
/* Find a match in the IP table*/
for (i = 0; i < IPSEC_MAX_RX_IP_COUNT; i++) {
@@ -191,13 +193,6 @@ ixgbe_crypto_add_sa(struct ixgbe_crypto_session *ic_session)
priv->rx_sa_tbl[sa_index].ip_index);
IXGBE_WAIT_RWRITE;
- /* write Key table entry*/
- key = malloc(ic_session->key_len);
- if (!key)
- return -ENOMEM;
-
- memcpy(key, ic_session->key, ic_session->key_len);
-
reg_val = IPSRXIDX_RX_EN | IPSRXIDX_WRITE |
IPSRXIDX_TABLE_KEY | (sa_index << 3);
IXGBE_WRITE_REG(hw, IXGBE_IPSRXKEY(0),
@@ -214,10 +209,7 @@ ixgbe_crypto_add_sa(struct ixgbe_crypto_session *ic_session)
priv->rx_sa_tbl[sa_index].mode);
IXGBE_WAIT_RWRITE;
- free(key);
-
} else { /* sess->dir == RTE_CRYPTO_OUTBOUND */
- uint8_t *key;
int i;
/* Find a free entry in the SA table*/
@@ -238,12 +230,6 @@ ixgbe_crypto_add_sa(struct ixgbe_crypto_session *ic_session)
priv->tx_sa_tbl[i].used = 1;
ic_session->sa_index = sa_index;
- key = malloc(ic_session->key_len);
- if (!key)
- return -ENOMEM;
-
- memcpy(key, ic_session->key, ic_session->key_len);
-
/* write Key table entry*/
reg_val = IPSRXIDX_RX_EN | IPSRXIDX_WRITE | (sa_index << 3);
IXGBE_WRITE_REG(hw, IXGBE_IPSTXKEY(0),
@@ -257,8 +243,6 @@ ixgbe_crypto_add_sa(struct ixgbe_crypto_session *ic_session)
IXGBE_WRITE_REG(hw, IXGBE_IPSTXSALT,
rte_cpu_to_be_32(ic_session->salt));
IXGBE_WAIT_TWRITE;
-
- free(key);
}
return 0;
--
2.52.0
More information about the dev
mailing list