From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH v2 6/6] net/i40e: use stack storage for function-local buffers
Date: Tue, 1 Dec 2026 18:22:49 +0000 [thread overview]
Message-ID: <20261201182249.2520829-7-bruce.richardson@intel.com> (raw)
In-Reply-To: <20261201182249.2520829-1-bruce.richardson@intel.com>
Rather than using malloc and free for adminq response buffers, and for
the DDP profile list buffer in testpmd commands, define them on the
stack, using RTE_DEFINE_FLEX_BYTES for those structures ending in a
variable-length array. This removes the allocation failure and cleanup
paths.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
drivers/net/intel/i40e/i40e_ethdev.c | 27 +++++----------------------
drivers/net/intel/i40e/i40e_testpmd.c | 10 ++--------
2 files changed, 7 insertions(+), 30 deletions(-)
diff --git a/drivers/net/intel/i40e/i40e_ethdev.c b/drivers/net/intel/i40e/i40e_ethdev.c
index 498c5c7ec4..dde1867345 100644
--- a/drivers/net/intel/i40e/i40e_ethdev.c
+++ b/drivers/net/intel/i40e/i40e_ethdev.c
@@ -4549,18 +4549,13 @@ i40e_free_virt_mem_d(__rte_unused struct i40e_hw *hw,
static int
i40e_get_cap(struct i40e_hw *hw)
{
- struct i40e_aqc_list_capabilities_element_resp *buf;
+ struct i40e_aqc_list_capabilities_element_resp buf[I40E_MAX_CAP_ELE_NUM] = {0};
uint16_t len, size = 0;
int ret;
/* Calculate a huge enough buff for saving response data temporarily */
len = sizeof(struct i40e_aqc_list_capabilities_element_resp) *
I40E_MAX_CAP_ELE_NUM;
- buf = rte_zmalloc("i40e", len, 0);
- if (!buf) {
- PMD_DRV_LOG(ERR, "Failed to allocate memory");
- return I40E_ERR_NO_MEMORY;
- }
/* Get, parse the capabilities and save it to hw */
ret = i40e_aq_discover_capabilities(hw, buf, len, &size,
@@ -4568,9 +4563,6 @@ i40e_get_cap(struct i40e_hw *hw)
if (ret != I40E_SUCCESS)
PMD_DRV_LOG(ERR, "Failed to discover capabilities");
- /* Free the temporary buffer after being used */
- rte_free(buf);
-
return ret;
}
@@ -4775,29 +4767,23 @@ static int
i40e_pf_get_switch_config(struct i40e_pf *pf)
{
struct i40e_hw *hw = I40E_PF_TO_HW(pf);
- struct i40e_aqc_get_switch_config_resp *switch_config;
+ RTE_DEFINE_FLEX_BYTES(struct i40e_aqc_get_switch_config_resp, switch_config,
+ I40E_AQ_LARGE_BUF);
struct i40e_aqc_switch_config_element_resp *element;
uint16_t start_seid = 0, num_reported;
int ret;
- switch_config = (struct i40e_aqc_get_switch_config_resp *)\
- rte_zmalloc("i40e", I40E_AQ_LARGE_BUF, 0);
- if (!switch_config) {
- PMD_DRV_LOG(ERR, "Failed to allocated memory");
- return -ENOMEM;
- }
-
/* Get the switch configurations */
ret = i40e_aq_get_switch_config(hw, switch_config,
I40E_AQ_LARGE_BUF, &start_seid, NULL);
if (ret != I40E_SUCCESS) {
PMD_DRV_LOG(ERR, "Failed to get switch configurations");
- goto fail;
+ return ret;
}
num_reported = rte_le_to_cpu_16(switch_config->header.num_reported);
if (num_reported != 1) { /* The number should be 1 */
PMD_DRV_LOG(ERR, "Wrong number of switch config reported");
- goto fail;
+ return ret;
}
/* Parse the switch configuration elements */
@@ -4808,9 +4794,6 @@ i40e_pf_get_switch_config(struct i40e_pf *pf)
} else
PMD_DRV_LOG(INFO, "Unknown element type");
-fail:
- rte_free(switch_config);
-
return ret;
}
diff --git a/drivers/net/intel/i40e/i40e_testpmd.c b/drivers/net/intel/i40e/i40e_testpmd.c
index 21f596297b..30ae57336e 100644
--- a/drivers/net/intel/i40e/i40e_testpmd.c
+++ b/drivers/net/intel/i40e/i40e_testpmd.c
@@ -1616,7 +1616,8 @@ cmd_ddp_get_list_parsed(__rte_unused void *parsed_result,
__rte_unused void *data)
{
struct cmd_ddp_get_list_result *res = parsed_result;
- struct rte_pmd_i40e_profile_list *p_list;
+ RTE_DEFINE_FLEX_BYTES(struct rte_pmd_i40e_profile_list, p_list,
+ PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4);
struct rte_pmd_i40e_profile_info *p_info;
uint32_t p_num;
uint32_t size;
@@ -1624,11 +1625,6 @@ cmd_ddp_get_list_parsed(__rte_unused void *parsed_result,
int ret = -ENOTSUP;
size = PROFILE_INFO_SIZE * MAX_PROFILE_NUM + 4;
- p_list = (struct rte_pmd_i40e_profile_list *)malloc(size);
- if (!p_list) {
- fprintf(stderr, "%s: Failed to malloc buffer\n", __func__);
- return;
- }
if (ret == -ENOTSUP)
ret = rte_pmd_i40e_get_ddp_list(res->port_id,
@@ -1651,8 +1647,6 @@ cmd_ddp_get_list_parsed(__rte_unused void *parsed_result,
}
}
- free(p_list);
-
if (ret < 0)
fprintf(stderr, "Failed to get ddp list\n");
}
--
2.55.0
prev parent reply other threads:[~2026-12-01 18:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 16:09 [PATCH 27.03 0/6] eliminate unnecessary dynamic allocation Bruce Richardson
2026-11-16 16:09 ` [PATCH 27.03 1/6] eal: add macros for local variable-length structure buffers Bruce Richardson
2026-11-16 16:09 ` [PATCH 27.03 2/6] net/iavf: use stack storage for virtchnl messages Bruce Richardson
2026-11-16 16:09 ` [PATCH 27.03 3/6] net/ice: use stack storage for function-local buffers Bruce Richardson
2026-11-16 16:09 ` [PATCH 27.03 4/6] net/idpf: use stack storage for virtchnl messages Bruce Richardson
2026-11-16 16:09 ` [PATCH 27.03 5/6] net/cpfl: use stack storage for function-local buffers Bruce Richardson
2026-11-16 16:09 ` [PATCH 27.03 6/6] net/i40e: " Bruce Richardson
2026-12-01 18:22 ` [PATCH v2 0/6] eliminate unnecessary dynamic allocation Bruce Richardson
2026-12-01 18:22 ` [PATCH v2 1/6] eal: add macros for local variable-length structure buffers Bruce Richardson
2026-12-01 19:29 ` Morten Brørup
2026-12-01 19:36 ` Stephen Hemminger
2026-12-01 19:37 ` Stephen Hemminger
2026-12-01 18:22 ` [PATCH v2 2/6] net/iavf: use stack storage for virtchnl messages Bruce Richardson
2026-12-01 18:22 ` [PATCH v2 3/6] net/ice: use stack storage for function-local buffers Bruce Richardson
2026-12-01 18:22 ` [PATCH v2 4/6] net/idpf: use stack storage for virtchnl messages Bruce Richardson
2026-12-01 18:22 ` [PATCH v2 5/6] net/cpfl: use stack storage for function-local buffers Bruce Richardson
2026-12-01 18:22 ` Bruce Richardson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201182249.2520829-7-bruce.richardson@intel.com \
--to=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.