From: Oleksandr Kolomeiets <okl-plv@napatech.com>
To: dev@dpdk.org
Cc: mko-plv@napatech.com, sil-plv@napatech.com, ckm@napatech.com,
stephen@networkplumber.org, thomas@monjalon.net,
Danylo Vodopianov <dvo-plv@napatech.com>
Subject: [PATCH v1 14/25] net/ntnic: add handle memory allocation failures
Date: Wed, 30 Apr 2025 15:48:26 +0200 [thread overview]
Message-ID: <20250430134840.402553-15-okl-plv@napatech.com> (raw)
In-Reply-To: <20250430134840.402553-1-okl-plv@napatech.com>
From: Danylo Vodopianov <dvo-plv@napatech.com>
Added checks for `calloc` return values to handle memory
allocation failures.
Check for null in rpp_lr_nthw_init
Signed-off-by: Danylo Vodopianov <dvo-plv@napatech.com>
---
drivers/net/ntnic/nthw/flow_api/flow_group.c | 17 ++++++++++--
drivers/net/ntnic/nthw/flow_api/flow_km.c | 4 +++
.../profile_inline/flow_api_profile_inline.c | 26 +++++++++++++++++++
.../ntnic/nthw/flow_filter/flow_nthw_rpp_lr.c | 3 ++-
4 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ntnic/nthw/flow_api/flow_group.c b/drivers/net/ntnic/nthw/flow_api/flow_group.c
index 6e010c1b9e..f2c9bcaaa5 100644
--- a/drivers/net/ntnic/nthw/flow_api/flow_group.c
+++ b/drivers/net/ntnic/nthw/flow_api/flow_group.c
@@ -30,14 +30,27 @@ int nthw_flow_group_handle_create(void **handle, uint32_t group_count)
struct group_handle_s *group_handle;
*handle = calloc(1, sizeof(struct group_handle_s));
+ if (*handle == NULL)
+ return -1;
+
group_handle = *handle;
- group_handle->group_count = group_count;
group_handle->translation_table =
calloc((uint32_t)(group_count * PORT_COUNT * OWNER_ID_COUNT), sizeof(uint32_t));
group_handle->lookup_entries = calloc(group_count, sizeof(struct group_lookup_entry_s));
- return *handle != NULL ? 0 : -1;
+ if (group_handle->lookup_entries == NULL ||
+ group_handle->translation_table == NULL) {
+ free(group_handle->lookup_entries);
+ free(group_handle->translation_table);
+ free(*handle);
+ *handle = NULL;
+ return -1;
+ }
+
+ group_handle->group_count = group_count;
+
+ return 0;
}
int nthw_flow_group_handle_destroy(void **handle)
diff --git a/drivers/net/ntnic/nthw/flow_api/flow_km.c b/drivers/net/ntnic/nthw/flow_api/flow_km.c
index 7b0fdddeea..9c76e8639c 100644
--- a/drivers/net/ntnic/nthw/flow_api/flow_km.c
+++ b/drivers/net/ntnic/nthw/flow_api/flow_km.c
@@ -84,6 +84,10 @@ void km_attach_ndev_resource_management(struct km_flow_def_s *km, void **handle)
*handle = calloc(1,
(size_t)CAM_ENTRIES + sizeof(uint32_t) + (size_t)TCAM_ENTRIES +
sizeof(struct hasher_s));
+ if (!*handle) {
+ NT_LOG(ERR, FILTER, "Failed to allocate CAM and TCAM record manager");
+ return;
+ }
NT_LOG(DBG, FILTER, "Allocate NIC DEV CAM and TCAM record manager");
}
diff --git a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c
index 3fb867c993..5bf8a9a3ea 100644
--- a/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c
+++ b/drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c
@@ -3476,6 +3476,12 @@ static struct flow_handle *create_flow_filter(struct flow_eth_dev *dev, struct n
{
struct flow_handle *fh = calloc(1, sizeof(struct flow_handle));
+ if (fh == NULL) {
+ error->type = RTE_FLOW_ERROR_TYPE_UNSPECIFIED;
+ error->message = "Failed to allocate flow_handle";
+ goto error_out;
+ }
+
fh->type = FLOW_HANDLE_TYPE_FLOW;
fh->port_id = port_id;
fh->dev = dev;
@@ -4929,6 +4935,13 @@ struct flow_pattern_template *flow_pattern_template_create_profile_inline(struct
struct flow_pattern_template *template = calloc(1, sizeof(struct flow_pattern_template));
+ if (template == NULL) {
+ error->type = RTE_FLOW_ERROR_TYPE_UNSPECIFIED;
+ error->message = "Failed to allocate actions_template";
+ free(fd);
+ return NULL;
+ }
+
template->fd = fd;
return template;
@@ -4994,6 +5007,13 @@ flow_actions_template_create_profile_inline(struct flow_eth_dev *dev,
struct flow_actions_template *template = calloc(1, sizeof(struct flow_actions_template));
+ if (template == NULL) {
+ error->type = RTE_FLOW_ERROR_TYPE_UNSPECIFIED;
+ error->message = "Failed to allocate actions_template";
+ free(fd);
+ return NULL;
+ }
+
template->fd = fd;
template->num_dest_port = num_dest_port;
template->num_queues = num_queues;
@@ -5266,6 +5286,12 @@ struct flow_handle *flow_async_create_profile_inline(struct flow_eth_dev *dev,
if (fh == NULL && status == CELL_STATUS_INITIALIZED_TYPE_FLM) {
fh = calloc(1, sizeof(struct flow_handle));
+ if (fh == NULL) {
+ error->type = RTE_FLOW_ERROR_TYPE_UNSPECIFIED;
+ error->message = "Failed to allocate flow_handle";
+ goto err_exit;
+ }
+
fh->type = FLOW_HANDLE_TYPE_FLM;
fh->dev = dev;
fh->caller_id = template_table->caller_id;
diff --git a/drivers/net/ntnic/nthw/flow_filter/flow_nthw_rpp_lr.c b/drivers/net/ntnic/nthw/flow_filter/flow_nthw_rpp_lr.c
index 12d9f27e20..99245bddaf 100644
--- a/drivers/net/ntnic/nthw/flow_filter/flow_nthw_rpp_lr.c
+++ b/drivers/net/ntnic/nthw/flow_filter/flow_nthw_rpp_lr.c
@@ -62,7 +62,8 @@ int rpp_lr_nthw_init(struct rpp_lr_nthw *p, nthw_fpga_t *p_fpga, int n_instance)
p->mp_rcp_data = nthw_module_get_register(p->m_rpp_lr, RPP_LR_RCP_DATA);
p->mp_rcp_data_exp = nthw_register_get_field(p->mp_rcp_data, RPP_LR_RCP_DATA_EXP);
- p->mp_ifr_rcp_ctrl = nthw_module_query_register(p->m_rpp_lr, RPP_LR_IFR_RCP_CTRL);
+ if (p->m_rpp_lr)
+ p->mp_ifr_rcp_ctrl = nthw_module_query_register(p->m_rpp_lr, RPP_LR_IFR_RCP_CTRL);
p->mp_ifr_rcp_addr =
nthw_register_query_field(p->mp_ifr_rcp_ctrl, RPP_LR_IFR_RCP_CTRL_ADR);
p->mp_ifr_rcp_cnt = nthw_register_query_field(p->mp_ifr_rcp_ctrl, RPP_LR_IFR_RCP_CTRL_CNT);
--
2.47.1
next prev parent reply other threads:[~2025-04-30 13:50 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-30 13:48 [PATCH v1 00/25] net/ntnic: fixes and improvements Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 01/25] net/ntnic: remove usage of the variable-length arrays Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 02/25] net/ntnic: handle string truncations when using strlcpy Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 03/25] net/ntnic: replace pragma pack with DPDK defined macros Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 04/25] net/ntnic: remove extra memset Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 05/25] net/ntnic: include all queues into statistics Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 06/25] net/ntnic: avoid misleading variable names Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 07/25] net/ntnic: apply packing to the structure Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 08/25] net/ntnic: improve logging format specifiers Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 09/25] net/ntnic: remove usless expressions Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 10/25] net/ntnic: remove unused code Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 11/25] net/ntnic: remove usless part of conditional expression Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 12/25] net/ntnic: add error logging for hsh Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 13/25] net/ntnic: add explicitly specificator Oleksandr Kolomeiets
2025-04-30 13:48 ` Oleksandr Kolomeiets [this message]
2025-04-30 13:48 ` [PATCH v1 15/25] net/ntnic: remove redundant initialization Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 16/25] net/ntnic: enhance null checks and assertions Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 17/25] net/ntnic: add return value check Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 18/25] net/ntnic: remove redundant assignments and branching Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 19/25] net/ntnic: rework array usage Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 20/25] net/ntnic: avoid divide by zero Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 21/25] net/ntnic: remove unnecessary void cast Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 22/25] net/ntnic: remove unnecessary memset Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 23/25] net/ntnic: add null verification Oleksandr Kolomeiets
2025-04-30 13:48 ` [PATCH v1 24/25] net/ntnic: avoid possible deadlock Oleksandr Kolomeiets
2025-04-30 14:05 ` Stephen Hemminger
2025-04-30 13:48 ` [PATCH v1 25/25] net/ntnic: fix operation with rte ring queue Oleksandr Kolomeiets
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=20250430134840.402553-15-okl-plv@napatech.com \
--to=okl-plv@napatech.com \
--cc=ckm@napatech.com \
--cc=dev@dpdk.org \
--cc=dvo-plv@napatech.com \
--cc=mko-plv@napatech.com \
--cc=sil-plv@napatech.com \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
/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;
as well as URLs for NNTP newsgroup(s).