DPDK patches and discussions
 help / color / mirror / Atom feed
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 23/25] net/ntnic: add null verification
Date: Wed, 30 Apr 2025 15:48:35 +0200	[thread overview]
Message-ID: <20250430134840.402553-24-okl-plv@napatech.com> (raw)
In-Reply-To: <20250430134840.402553-1-okl-plv@napatech.com>

From: Danylo Vodopianov <dvo-plv@napatech.com>

Add verification on NULL for variables before use it in the memset.

Signed-off-by: Danylo Vodopianov <dvo-plv@napatech.com>
---
 drivers/net/ntnic/dbsconfig/ntnic_dbsconfig.c  |  3 +++
 .../link_mgmt/link_100g/nt4ga_link_100g.c      |  2 ++
 .../net/ntnic/nthw/flow_api/flow_id_table.c    |  3 ++-
 .../nthw/flow_api/hw_mod/hw_mod_backend.c      |  3 ++-
 .../profile_inline/flow_api_profile_inline.c   | 18 ++++++++++++------
 drivers/net/ntnic/nthw/model/nthw_fpga_model.c |  6 ++++--
 .../net/ntnic/nthw/ntnic_meter/ntnic_meter.c   |  6 ++++++
 drivers/net/ntnic/ntnic_filter/ntnic_filter.c  |  5 +++++
 8 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ntnic/dbsconfig/ntnic_dbsconfig.c b/drivers/net/ntnic/dbsconfig/ntnic_dbsconfig.c
index bb775c052c..94b0c97d27 100644
--- a/drivers/net/ntnic/dbsconfig/ntnic_dbsconfig.c
+++ b/drivers/net/ntnic/dbsconfig/ntnic_dbsconfig.c
@@ -911,6 +911,9 @@ static int nthw_setup_managed_virt_queue_packed(struct nthw_virt_queue *vq,
 	RTE_ASSERT(p_packet_buffers);
 
 	/* clean canvas */
+	if (p_virt_struct_area->virt_addr == NULL)
+		return -1;
+
 	memset(p_virt_struct_area->virt_addr, 0,
 		sizeof(struct pvirtq_desc) * vq->queue_size +
 		sizeof(struct pvirtq_event_suppress) * 2 + sizeof(int) * vq->queue_size);
diff --git a/drivers/net/ntnic/link_mgmt/link_100g/nt4ga_link_100g.c b/drivers/net/ntnic/link_mgmt/link_100g/nt4ga_link_100g.c
index ed9dabe27c..adb187d322 100644
--- a/drivers/net/ntnic/link_mgmt/link_100g/nt4ga_link_100g.c
+++ b/drivers/net/ntnic/link_mgmt/link_100g/nt4ga_link_100g.c
@@ -137,6 +137,8 @@ static int _link_state_build(adapter_info_t *drv, nthw_mac_pcs_t *mac_pcs,
 	uint32_t lh_internal_local_fault;
 	uint32_t lh_received_local_fault;
 
+	RTE_ASSERT(state);
+
 	memset(state, 0, sizeof(*state));
 	state->link_disabled = is_port_disabled;
 	nthw_mac_pcs_get_link_summary(mac_pcs, &abs, &phy_link_state, &lh_abs, &ll_phy_link_state,
diff --git a/drivers/net/ntnic/nthw/flow_api/flow_id_table.c b/drivers/net/ntnic/nthw/flow_api/flow_id_table.c
index a63f5542d1..c33308b5f7 100644
--- a/drivers/net/ntnic/nthw/flow_api/flow_id_table.c
+++ b/drivers/net/ntnic/nthw/flow_api/flow_id_table.c
@@ -114,7 +114,8 @@ void ntnic_id_table_free_id(void *id_table, uint32_t id)
 
 	struct ntnic_id_table_element *current_element =
 		ntnic_id_table_array_find_element(handle, id);
-	memset(current_element, 0, sizeof(struct ntnic_id_table_element));
+	if (current_element)
+		memset(current_element, 0, sizeof(struct ntnic_id_table_element));
 
 	struct ntnic_id_table_element *element =
 		ntnic_id_table_array_find_element(handle, handle->free_head);
diff --git a/drivers/net/ntnic/nthw/flow_api/hw_mod/hw_mod_backend.c b/drivers/net/ntnic/nthw/flow_api/hw_mod/hw_mod_backend.c
index 299b9b913a..2e2ecfe253 100644
--- a/drivers/net/ntnic/nthw/flow_api/hw_mod/hw_mod_backend.c
+++ b/drivers/net/ntnic/nthw/flow_api/hw_mod/hw_mod_backend.c
@@ -86,7 +86,8 @@ void *nthw_callocate_mod(struct common_func_s *mod, int sets, ...)
 
 void nthw_zero_module_cache(struct common_func_s *mod)
 {
-	memset(mod->base, 0, mod->alloced_size);
+	if (mod)
+		memset(mod->base, 0, mod->alloced_size);
 }
 
 int nthw_flow_api_backend_init(struct flow_api_backend_s *dev,
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 5bf8a9a3ea..3133464675 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
@@ -1714,15 +1714,14 @@ static int interpret_flow_elements(const struct flow_eth_dev *dev,
 
 	*in_port_id = UINT32_MAX;
 
-	memset(packet_data, 0x0, sizeof(uint32_t) * 10);
-	memset(packet_mask, 0x0, sizeof(uint32_t) * 10);
-	memset(key_def, 0x0, sizeof(struct flm_flow_key_def_s));
-
-	if (elem == NULL) {
+	if (packet_data == NULL || packet_mask == NULL || key_def == NULL || elem == NULL) {
 		nthw_flow_nic_set_error(ERR_FAILED, error);
 		NT_LOG(ERR, FILTER, "Flow items missing");
 		return -1;
 	}
+	memset(packet_data, 0x0, sizeof(uint32_t) * 10);
+	memset(packet_mask, 0x0, sizeof(uint32_t) * 10);
+	memset(key_def, 0x0, sizeof(struct flm_flow_key_def_s));
 
 	if (implicit_vlan_vid > 0) {
 		uint32_t *sw_data = &packet_data[1 - sw_counter];
@@ -3192,6 +3191,9 @@ static int convert_fh_to_fh_flm(struct flow_handle *fh, const uint32_t *packet_d
 static void setup_db_qsl_data(struct nic_flow_def *fd, struct hw_db_inline_qsl_data *qsl_data,
 	uint32_t num_dest_port, uint32_t num_queues)
 {
+	if (qsl_data == NULL)
+		return;
+
 	memset(qsl_data, 0x0, sizeof(struct hw_db_inline_qsl_data));
 
 	if (fd->dst_num_avail <= 0) {
@@ -3236,6 +3238,9 @@ static void setup_db_qsl_data(struct nic_flow_def *fd, struct hw_db_inline_qsl_d
 
 static void setup_db_hsh_data(struct nic_flow_def *fd, struct hw_db_inline_hsh_data *hsh_data)
 {
+	if (hsh_data == NULL)
+		return;
+
 	memset(hsh_data, 0x0, sizeof(struct hw_db_inline_hsh_data));
 
 	hsh_data->func = fd->hsh.func;
@@ -4816,7 +4821,8 @@ int flow_info_get_profile_inline(struct flow_eth_dev *dev, uint8_t caller_id,
 	int res = 0;
 
 	nthw_flow_nic_set_error(ERR_SUCCESS, error);
-	memset(port_info, 0, sizeof(struct rte_flow_port_info));
+	if (port_info)
+		memset(port_info, 0, sizeof(struct rte_flow_port_info));
 
 	port_info->max_nb_aging_objects = dev->nb_aging_objects;
 
diff --git a/drivers/net/ntnic/nthw/model/nthw_fpga_model.c b/drivers/net/ntnic/nthw/model/nthw_fpga_model.c
index 0838527716..5256adc648 100644
--- a/drivers/net/ntnic/nthw/model/nthw_fpga_model.c
+++ b/drivers/net/ntnic/nthw/model/nthw_fpga_model.c
@@ -854,8 +854,10 @@ void nthw_register_flush(const nthw_register_t *p, uint32_t cnt)
 
 void nthw_register_clr(nthw_register_t *p)
 {
-	memset(p->mp_shadow, 0, p->mn_len * sizeof(uint32_t));
-	nthw_register_make_dirty(p);
+	if (p->mp_shadow) {
+		memset(p->mp_shadow, 0, p->mn_len * sizeof(uint32_t));
+		nthw_register_make_dirty(p);
+	}
 }
 
 /*
diff --git a/drivers/net/ntnic/nthw/ntnic_meter/ntnic_meter.c b/drivers/net/ntnic/nthw/ntnic_meter/ntnic_meter.c
index 66cc02a865..303c2cd51a 100644
--- a/drivers/net/ntnic/nthw/ntnic_meter/ntnic_meter.c
+++ b/drivers/net/ntnic/nthw/ntnic_meter/ntnic_meter.c
@@ -51,6 +51,9 @@ static int eth_mtr_capabilities_get_inline(struct rte_eth_dev *eth_dev,
 				"Ethernet device does not support metering");
 	}
 
+	if (cap == NULL)
+		return -1;
+
 	memset(cap, 0x0, sizeof(struct rte_mtr_capabilities));
 
 	/* MBR records use 28-bit integers */
@@ -419,6 +422,9 @@ static int eth_mtr_stats_read_inline(struct rte_eth_dev *eth_dev,
 				"MTR id is out of range");
 	}
 
+	if (stats == NULL)
+		return -1;
+
 	memset(stats, 0x0, sizeof(struct rte_mtr_stats));
 	profile_inline_ops->flm_mtr_read_stats(internals->flw_dev, caller_id, mtr_id, stats_mask,
 		&stats->n_pkts[RTE_COLOR_GREEN],
diff --git a/drivers/net/ntnic/ntnic_filter/ntnic_filter.c b/drivers/net/ntnic/ntnic_filter/ntnic_filter.c
index 5757c7c13c..fc06cf12c3 100644
--- a/drivers/net/ntnic/ntnic_filter/ntnic_filter.c
+++ b/drivers/net/ntnic/ntnic_filter/ntnic_filter.c
@@ -248,6 +248,11 @@ int nthw_interpret_raw_data(uint8_t *data, uint8_t *preserve, int size, struct r
 
 int nthw_create_attr(struct cnv_attr_s *attribute, const struct rte_flow_attr *attr)
 {
+	if (!attribute) {
+		NT_LOG(ERR, FILTER, "ERROR no attribute to iterate!");
+		return -1;
+	}
+
 	memset(&attribute->attr, 0x0, sizeof(struct rte_flow_attr));
 
 	if (attr) {
-- 
2.47.1


  parent reply	other threads:[~2025-04-30 13:52 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 ` [PATCH v1 14/25] net/ntnic: add handle memory allocation failures Oleksandr Kolomeiets
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 ` Oleksandr Kolomeiets [this message]
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-24-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).