From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH 27.03 5/6] net/cpfl: use stack storage for function-local buffers
Date: Mon, 16 Nov 2026 16:09:31 +0000 [thread overview]
Message-ID: <20261116160932.1006354-6-bruce.richardson@intel.com> (raw)
In-Reply-To: <20261116160932.1006354-1-bruce.richardson@intel.com>
Rather than using malloc and free for virtchnl and control queue buffers
used only within a single function, define them on the stack, using
RTE_DEFINE_FLEX for those structures ending in a variable-length array.
This removes the allocation failure and cleanup paths.
Where the number of elements used depends on runtime values, add checks
that those values do not exceed the buffer sizes.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
drivers/net/intel/cpfl/cpfl_fxp_rule.c | 20 ++++-------
drivers/net/intel/cpfl/cpfl_representor.c | 15 +++++----
drivers/net/intel/cpfl/cpfl_vchnl.c | 41 +++++++++--------------
3 files changed, 32 insertions(+), 44 deletions(-)
diff --git a/drivers/net/intel/cpfl/cpfl_fxp_rule.c b/drivers/net/intel/cpfl/cpfl_fxp_rule.c
index d1c992dfe4..c522dde6d8 100644
--- a/drivers/net/intel/cpfl/cpfl_fxp_rule.c
+++ b/drivers/net/intel/cpfl/cpfl_fxp_rule.c
@@ -13,23 +13,21 @@ int
cpfl_send_ctlq_msg(struct idpf_hw *hw, struct idpf_ctlq_info *cq, u16 num_q_msg,
struct idpf_ctlq_msg q_msg[])
{
- struct idpf_ctlq_msg **msg_ptr_list;
+ struct idpf_ctlq_msg *msg_ptr_list[CPFL_FLOW_BATCH_SIZE] = {0};
u16 clean_count = 0;
int num_cleaned = 0;
int retries = 0;
int ret = 0;
- msg_ptr_list = calloc(num_q_msg, sizeof(struct idpf_ctlq_msg *));
- if (!msg_ptr_list) {
- PMD_INIT_LOG(ERR, "no memory for cleaning ctlq");
- ret = -ENOMEM;
- goto err;
+ if (num_q_msg > RTE_DIM(msg_ptr_list)) {
+ PMD_INIT_LOG(ERR, "too many messages for ctlq: %u", num_q_msg);
+ return -EINVAL;
}
ret = cpfl_vport_ctlq_send(hw, cq, num_q_msg, q_msg);
if (ret) {
PMD_INIT_LOG(ERR, "cpfl_vport_ctlq_send() failed with error: 0x%4x", ret);
- goto send_err;
+ return ret;
}
while (retries <= CTLQ_SEND_RETRIES) {
@@ -38,7 +36,7 @@ cpfl_send_ctlq_msg(struct idpf_hw *hw, struct idpf_ctlq_info *cq, u16 num_q_msg,
&msg_ptr_list[num_cleaned]);
if (ret) {
PMD_INIT_LOG(ERR, "clean ctlq failed: 0x%4x", ret);
- goto send_err;
+ return ret;
}
num_cleaned += clean_count;
@@ -50,13 +48,9 @@ cpfl_send_ctlq_msg(struct idpf_hw *hw, struct idpf_ctlq_info *cq, u16 num_q_msg,
if (retries > CTLQ_SEND_RETRIES) {
PMD_INIT_LOG(ERR, "timed out while polling for completions");
- ret = -1;
- goto send_err;
+ return -1;
}
-send_err:
- free(msg_ptr_list);
-err:
return ret;
}
diff --git a/drivers/net/intel/cpfl/cpfl_representor.c b/drivers/net/intel/cpfl/cpfl_representor.c
index bb28c0b989..91bbb3af48 100644
--- a/drivers/net/intel/cpfl/cpfl_representor.c
+++ b/drivers/net/intel/cpfl/cpfl_representor.c
@@ -558,14 +558,11 @@ cpfl_repr_create(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *adapte
uint32_t iter = 0;
const struct cpfl_repr_id *repr_id;
const struct cpfl_vport_id *vp_id;
- struct cpchnl2_get_vport_list_response *vlist_resp;
+ RTE_DEFINE_FLEX_BYTES(struct cpchnl2_get_vport_list_response, vlist_resp,
+ IDPF_DFLT_MBX_BUF_SIZE);
struct cpchnl2_get_vport_info_response vinfo_resp;
int ret;
- vlist_resp = rte_zmalloc(NULL, IDPF_DFLT_MBX_BUF_SIZE, 0);
- if (vlist_resp == NULL)
- return -ENOMEM;
-
rte_spinlock_lock(&adapter->repr_lock);
while (rte_hash_iterate(adapter->repr_allowlist_hash,
@@ -603,6 +600,13 @@ cpfl_repr_create(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *adapte
PMD_INIT_LOG(WARNING, "No matched vport for representor %s", name);
continue;
}
+ if (vlist_resp->nof_vports > (IDPF_DFLT_MBX_BUF_SIZE - sizeof(*vlist_resp)) /
+ sizeof(vlist_resp->vports[0])) {
+ PMD_INIT_LOG(ERR, "Invalid vport count %u for representor %s",
+ vlist_resp->nof_vports, name);
+ ret = -EINVAL;
+ goto err;
+ }
/* get all vport info for the port representor */
for (i = 0; i < vlist_resp->nof_vports; i++) {
@@ -657,6 +661,5 @@ cpfl_repr_create(struct rte_pci_device *pci_dev, struct cpfl_adapter_ext *adapte
err:
rte_spinlock_unlock(&adapter->repr_lock);
- rte_free(vlist_resp);
return ret;
}
diff --git a/drivers/net/intel/cpfl/cpfl_vchnl.c b/drivers/net/intel/cpfl/cpfl_vchnl.c
index 593516f700..6a4e4dac1b 100644
--- a/drivers/net/intel/cpfl/cpfl_vchnl.c
+++ b/drivers/net/intel/cpfl/cpfl_vchnl.c
@@ -147,18 +147,16 @@ vcpf_add_queues(struct cpfl_adapter_ext *adapter)
int
vcpf_del_queues(struct cpfl_adapter_ext *adapter)
{
- struct virtchnl2_del_ena_dis_queues *del_cfgq;
+ RTE_DEFINE_FLEX(struct virtchnl2_del_ena_dis_queues, del_cfgq, chunks.chunks,
+ VCPF_CFGQ_NUM - 1);
u16 num_chunks;
struct idpf_cmd_info args;
- int i, err, size;
+ int i, err;
num_chunks = adapter->cfgq_in.cfgq_add->chunks.num_chunks;
- size = idpf_struct_size(del_cfgq, chunks.chunks, (num_chunks - 1));
- del_cfgq = rte_zmalloc("del_cfgq", size, 0);
- if (!del_cfgq) {
- PMD_DRV_LOG(ERR, "Failed to allocate virtchnl2_del_ena_dis_queues");
- err = -ENOMEM;
- return err;
+ if (num_chunks > VCPF_CFGQ_NUM) {
+ PMD_DRV_LOG(ERR, "Too many config queue chunks: %u", num_chunks);
+ return -EINVAL;
}
del_cfgq->vport_id = rte_cpu_to_le_32(VCPF_CFGQ_VPORT_ID);
@@ -183,7 +181,6 @@ vcpf_del_queues(struct cpfl_adapter_ext *adapter)
args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
err = idpf_vc_cmd_execute(&adapter->base, &args);
- rte_free(del_cfgq);
if (err) {
PMD_DRV_LOG(ERR,
"Failed to execute command VIRTCHNL2_OP_DEL_QUEUES");
@@ -210,7 +207,7 @@ int
cpfl_config_ctlq_rx(struct cpfl_adapter_ext *adapter)
{
struct cpfl_vport *vport = &adapter->ctrl_vport;
- struct virtchnl2_config_rx_queues *vc_rxqs = NULL;
+ RTE_DEFINE_FLEX(struct virtchnl2_config_rx_queues, vc_rxqs, qinfo, CPFL_RX_CFGQ_NUM - 1);
struct virtchnl2_rxq_info *rxq_info;
struct idpf_cmd_info args;
uint16_t num_qs;
@@ -225,15 +222,13 @@ cpfl_config_ctlq_rx(struct cpfl_adapter_ext *adapter)
}
num_qs = adapter->num_rx_cfgq;
+ if (num_qs > CPFL_RX_CFGQ_NUM) {
+ PMD_DRV_LOG(ERR, "Too many Rx config queues: %u", num_qs);
+ return -EINVAL;
+ }
size = sizeof(*vc_rxqs) + (num_qs - 1) *
sizeof(struct virtchnl2_rxq_info);
- vc_rxqs = rte_zmalloc("cfg_rxqs", size, 0);
- if (!vc_rxqs) {
- PMD_DRV_LOG(ERR, "Failed to allocate virtchnl2_config_rx_queues");
- err = -ENOMEM;
- return err;
- }
if (idpf_is_vf_device(&adapter->base.hw))
vc_rxqs->vport_id = rte_cpu_to_le_32(VCPF_CFGQ_VPORT_ID);
@@ -264,7 +259,6 @@ cpfl_config_ctlq_rx(struct cpfl_adapter_ext *adapter)
args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
err = idpf_vc_cmd_execute(&adapter->base, &args);
- rte_free(vc_rxqs);
if (err)
PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_CONFIG_RX_QUEUES");
@@ -275,7 +269,7 @@ int
cpfl_config_ctlq_tx(struct cpfl_adapter_ext *adapter)
{
struct cpfl_vport *vport = &adapter->ctrl_vport;
- struct virtchnl2_config_tx_queues *vc_txqs = NULL;
+ RTE_DEFINE_FLEX(struct virtchnl2_config_tx_queues, vc_txqs, qinfo, CPFL_TX_CFGQ_NUM - 1);
struct virtchnl2_txq_info *txq_info;
struct idpf_cmd_info args;
uint16_t num_qs;
@@ -290,15 +284,13 @@ cpfl_config_ctlq_tx(struct cpfl_adapter_ext *adapter)
}
num_qs = adapter->num_tx_cfgq;
+ if (num_qs > CPFL_TX_CFGQ_NUM) {
+ PMD_DRV_LOG(ERR, "Too many Tx config queues: %u", num_qs);
+ return -EINVAL;
+ }
size = sizeof(*vc_txqs) + (num_qs - 1) *
sizeof(struct virtchnl2_txq_info);
- vc_txqs = rte_zmalloc("cfg_txqs", size, 0);
- if (!vc_txqs) {
- PMD_DRV_LOG(ERR, "Failed to allocate virtchnl2_config_tx_queues");
- err = -ENOMEM;
- return err;
- }
if (idpf_is_vf_device(&adapter->base.hw))
vc_txqs->vport_id = rte_cpu_to_le_32(VCPF_CFGQ_VPORT_ID);
@@ -325,7 +317,6 @@ cpfl_config_ctlq_tx(struct cpfl_adapter_ext *adapter)
args.out_size = IDPF_DFLT_MBX_BUF_SIZE;
err = idpf_vc_cmd_execute(&adapter->base, &args);
- rte_free(vc_txqs);
if (err)
PMD_DRV_LOG(ERR, "Failed to execute command of VIRTCHNL2_OP_CONFIG_TX_QUEUES");
--
2.55.0
next prev parent reply other threads:[~2026-11-16 16:10 UTC|newest]
Thread overview: 7+ 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 ` Bruce Richardson [this message]
2026-11-16 16:09 ` [PATCH 27.03 6/6] net/i40e: use stack storage for function-local buffers Bruce Richardson
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=20261116160932.1006354-6-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox