From: Danylo Vodopianov <dvo-plv@napatech.com>
Avoid usage before check
Signed-off-by: Danylo Vodopianov <dvo-plv@napatech.com>
---
drivers/net/ntnic/adapter/nt4ga_stat/nt4ga_stat.c | 4 ++--
drivers/net/ntnic/dbsconfig/ntnic_dbsconfig.c | 4 ++--
.../net/ntnic/link_mgmt/link_100g/nt4ga_link_100g.c | 2 +-
.../link_mgmt/link_agx_100g/nt4ga_agx_link_100g.c | 3 ++-
.../nthw/core/nt400dxx/reset/nthw_fpga_rst_nt400dxx.c | 4 ++--
drivers/net/ntnic/nthw/core/nthw_fpga.c | 3 +--
drivers/net/ntnic/ntnic_ethdev.c | 5 +++++
drivers/net/ntnic/ntnic_filter/ntnic_filter.c | 11 ++++++-----
8 files changed, 21 insertions(+), 15 deletions(-)
@@ -246,7 +246,7 @@ static int nt4ga_stat_collect_cap_v1_stats(struct adapter_info_s *p_adapter_info
(void)p_adapter_info;
const struct flow_filter_ops *flow_filter_ops = get_flow_filter_ops();
- if (flow_filter_ops == NULL)
+ if (flow_filter_ops == NULL || p_nt4ga_stat == NULL)
return -1;
nthw_stat_t *p_nthw_stat = p_nt4ga_stat->mp_nthw_stat;
@@ -256,7 +256,7 @@ static int nt4ga_stat_collect_cap_v1_stats(struct adapter_info_s *p_adapter_info
const int n_tx_ports = p_nt4ga_stat->mn_tx_ports;
int c, h, p;
- if (!p_nthw_stat || !p_nt4ga_stat)
+ if (p_nthw_stat == NULL)
return -1;
if (p_nthw_stat->mn_stat_layout_version < 6) {
@@ -592,11 +592,11 @@ static int nthw_release_mngd_rx_virt_queue(struct nthw_virt_queue *rxvq)
static int dbs_internal_release_tx_virt_queue(struct nthw_virt_queue *txvq)
{
- nthw_dbs_t *p_nthw_dbs = txvq->mp_nthw_dbs;
-
if (txvq == NULL)
return -1;
+ nthw_dbs_t *p_nthw_dbs = txvq->mp_nthw_dbs;
+
/* Clear UW */
txvq->used_struct_phys_addr = NULL;
@@ -256,11 +256,11 @@ static int _create_nim(adapter_info_t *drv, int port, bool enable)
nim_i2c_ctx_t *nim_ctx;
sfp_nim_state_t nim;
nt4ga_link_t *link_info = &drv->nt4ga_link;
- nthw_mac_pcs_t *mac_pcs = &link_info->u.var100g.mac_pcs100g[port];
RTE_ASSERT(port >= 0 && port < NUM_ADAPTER_PORTS_MAX);
RTE_ASSERT(link_info->variables_initialized);
+ nthw_mac_pcs_t *mac_pcs = &link_info->u.var100g.mac_pcs100g[port];
gpio_phy = &link_info->u.var100g.gpio_phy[port];
nim_ctx = &link_info->u.var100g.nim_ctx[port];
@@ -519,11 +519,12 @@ static int create_nim(adapter_info_t *drv, int port, bool enable)
const uint8_t valid_nim_id = NT_NIM_QSFP28;
sfp_nim_state_t nim;
nt4ga_link_t *link_info = &drv->nt4ga_link;
- nim_i2c_ctx_t *nim_ctx = &link_info->u.nim_ctx[port];
RTE_ASSERT(port >= 0 && port < NUM_ADAPTER_PORTS_MAX);
RTE_ASSERT(link_info->variables_initialized);
+ nim_i2c_ctx_t *nim_ctx = &link_info->u.nim_ctx[port];
+
if (!enable) {
phy_reset_rx(drv, port);
phy_reset_tx(drv, port);
@@ -182,6 +182,8 @@ static int nthw_fpga_rst_nt400dxx_init(struct fpga_info_s *p_fpga_info)
static int nthw_fpga_rst_nt400dxx_reset(struct fpga_info_s *p_fpga_info)
{
+ RTE_ASSERT(p_fpga_info);
+
const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str;
nthw_fpga_t *p_fpga = NULL;
int res = -1;
@@ -191,8 +193,6 @@ static int nthw_fpga_rst_nt400dxx_reset(struct fpga_info_s *p_fpga_info)
nthw_pcm_nt400dxx_t *p_pcm = p_fpga_info->mp_nthw_agx.p_pcm;
nthw_prm_nt400dxx_t *p_prm = p_fpga_info->mp_nthw_agx.p_prm;
- RTE_ASSERT(p_fpga_info);
-
NT_LOG(DBG, NTHW, "%s: %s: BEGIN", p_adapter_id_str, __PRETTY_FUNCTION__);
/* Create Phy Tile module */
@@ -343,6 +343,7 @@ int nthw_fpga_si5340_clock_synth_init_fmt2(nthw_fpga_t *p_fpga, const uint8_t n_
int nthw_fpga_init(struct fpga_info_s *p_fpga_info)
{
+ RTE_ASSERT(p_fpga_info);
const char *const p_adapter_id_str = p_fpga_info->mp_adapter_id_str;
nthw_hif_t *p_nthw_hif = NULL;
@@ -359,8 +360,6 @@ int nthw_fpga_init(struct fpga_info_s *p_fpga_info)
int res = 0;
- RTE_ASSERT(p_fpga_info);
-
{
const uint64_t n_fpga_ident = nthw_fpga_read_ident(p_fpga_info);
const uint32_t n_fpga_build_time = nthw_fpga_read_buildtime(p_fpga_info);
@@ -332,6 +332,11 @@ eth_dev_infos_get(struct rte_eth_dev *eth_dev, struct rte_eth_dev_info *dev_info
struct pmd_internals *internals = eth_dev->data->dev_private;
+ if (internals == NULL) {
+ NT_LOG(ERR, NTNIC, "PMD-specific private data not initialized");
+ return -1;
+ }
+
const int n_intf_no = internals->n_intf_no;
struct adapter_info_s *p_adapter_info = &internals->p_drv->ntdrv.adapter_info;
@@ -478,11 +478,6 @@ static int convert_flow(struct rte_eth_dev *eth_dev,
struct rte_flow_error *error)
{
struct pmd_internals *internals = eth_dev->data->dev_private;
- struct fpga_info_s *fpga_info = &internals->p_drv->ntdrv.adapter_info.fpga_info;
-
- error->type = RTE_FLOW_ERROR_TYPE_NONE;
- error->message = "none";
- uint32_t queue_offset = 0;
if (!internals) {
rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
@@ -490,6 +485,12 @@ static int convert_flow(struct rte_eth_dev *eth_dev,
return -1;
}
+ struct fpga_info_s *fpga_info = &internals->p_drv->ntdrv.adapter_info.fpga_info;
+
+ error->type = RTE_FLOW_ERROR_TYPE_NONE;
+ error->message = "none";
+ uint32_t queue_offset = 0;
+
if (internals->type == PORT_TYPE_OVERRIDE && internals->vpq_nb_vq > 0) {
/*
* The queues coming from the main PMD will always start from 0