unnecessary checks for null
cover unnecessary checks for null
Found by running nullfree.cocci on 24.11-rc2
Stephen Hemminger (3):
bus/fslmc: remove unnecessary null check net/dpaa2: remove unnecessary check for null before rte_free net/ntnic: remove unnecessary check for null before free
drivers/bus/fslmc/fslmc_vfio.c | 3 +-- drivers/net/dpaa2/dpaa2_ethdev.c | 3 +-- drivers/net/dpaa2/dpaa2_flow.c | 27 +++++++------------ drivers/net/dpaa2/dpaa2_mux.c | 6 ++--- drivers/net/ntnic/nthw/flow_api/flow_api.c | 6 ++--- .../flow_api/profile_inline/flm_age_queue.c | 3 +-- .../flow_api/profile_inline/flm_evt_queue.c | 3 +-- .../flow_api/profile_inline/flm_lrn_queue.c | 3 +-- drivers/net/ntnic/nthw/stat/nthw_stat.c | 3 +-- 9 files changed, 19 insertions(+), 38 deletions(-)
Signature · 1 line
2.45.2
PATCH 1/3 bus/fslmc: remove unnecessary null check
No need for check for null before calling free().
Caught by nullfree.cocci script.
--- drivers/bus/fslmc/fslmc_vfio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/bus/fslmc/fslmc_vfio.c +1 -2
@@ -557,8 +557,7 @@ fslmc_vfio_open_container_fd(void)return vfio_container_fd; err_exit: -if (mp_reply.msgs) -free (mp_reply.msgs); +free (mp_reply.msgs);DPAA2_BUS_ERR ("Open container fd err(%d)" , ret);return ret; }
Signature · 1 line
2.45.2
Re: [PATCH 1/3] bus/fslmc: remove unnecessary null check
Quoted 25 lines · Stephen Hemminger
No need for check for null before calling
free().
Caught bynullfree.cocciscript.Fixes 57cb02edf122 ("bus/fslmc: enhance MC VFIO multi-process support")Signed-off-by Stephen Hemminger <[email protected]>--- drivers/bus/fslmc/fslmc_vfio.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/bus/fslmc/fslmc_vfio.c +1
-2@@ -557,8 +557,7 @@ fslmc_vfio_open_container_fd(void)return vfio_container_fd; err_exit: -if (mp_reply.msgs) -free (mp_reply.msgs); +free (mp_reply.msgs);DPAA2_BUS_ERR ("Open container fd err(%d)" , ret);return ret; }
PATCH 2/3 net/dpaa2: remove unnecessary check for null before rte_free
In reply to Stephen HemmingerCalling rte_free() with NULL parameter is allowed. Found by nullfree.cocci
--- drivers/net/dpaa2/dpaa2_ethdev.c | 3 +-- drivers/net/dpaa2/dpaa2_flow.c | 27 +++++++++------------------ drivers/net/dpaa2/dpaa2_mux.c | 6 ++---- 3 files changed, 12 insertions(+), 24 deletions(-)
drivers/net/dpaa2/dpaa2_ethdev.c +1 -2
@@ -1401,8 +1401,7 @@ dpaa2_dev_close(struct rte_eth_dev *dev)for (i =0 ; i <MAX_TCS ; i++)rte_free (priv->extract.tc_extract_param[i]); -if (priv->extract.qos_extract_param) -rte_free (priv->extract.qos_extract_param); +rte_free (priv->extract.qos_extract_param);DPAA2_PMD_INFO ("%s: netdev deleted" , dev->data->name);return 0 ;
drivers/net/dpaa2/dpaa2_flow.c +9 -18
@@ -4784,8 +4784,7 @@ dpaa2_generic_flow_set(struct dpaa2_dev_flow *flow, } } -if (dpaa2_pattern) -rte_free (dpaa2_pattern); +rte_free (dpaa2_pattern);return ret; }
@@ -5057,14 +5056,10 @@ dpaa2_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, creation_error:if (flow) { -if (flow->qos_key_addr) -rte_free (flow->qos_key_addr); -if (flow->qos_mask_addr) -rte_free (flow->qos_mask_addr); -if (flow->fs_key_addr) -rte_free (flow->fs_key_addr); -if (flow->fs_mask_addr) -rte_free (flow->fs_mask_addr); +rte_free (flow->qos_key_addr); +rte_free (flow->qos_mask_addr); +rte_free (flow->fs_key_addr); +rte_free (flow->fs_mask_addr);rte_free (flow); } priv->curr =NULL ;
@@ -5128,14 +5123,10 @@ dpaa2_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *_flow, }LIST_REMOVE (flow, next); -if (flow->qos_key_addr) -rte_free (flow->qos_key_addr); -if (flow->qos_mask_addr) -rte_free (flow->qos_mask_addr); -if (flow->fs_key_addr) -rte_free (flow->fs_key_addr); -if (flow->fs_mask_addr) -rte_free (flow->fs_mask_addr); +rte_free (flow->qos_key_addr); +rte_free (flow->qos_mask_addr); +rte_free (flow->fs_key_addr); +rte_free (flow->fs_mask_addr);/* Now free the flow */ rte_free (flow);
drivers/net/dpaa2/dpaa2_mux.c +2 -4
@@ -329,10 +329,8 @@ rte_pmd_dpaa2_mux_flow_create(uint32_t dpdmux_id, } creation_error: -if (key_cfg_va) -rte_free (key_cfg_va); -if (key_va) -rte_free (key_va); +rte_free (key_cfg_va); +rte_free (key_va);return ret; }
Signature · 1 line
2.45.2
Re: [PATCH 2/3] net/dpaa2: remove unnecessary check for null before rte_free
Quoted 96 lines · Stephen Hemminger
Calling
rte_free()with NULL parameter is allowed. Found bynullfree.cocciFixes 5964d36a2904 ("net/dpaa2: release port upon close")Signed-off-by Stephen Hemminger <[email protected]>--- drivers/net/dpaa2/dpaa2_ethdev.c | 3 +-- drivers/net/dpaa2/dpaa2_flow.c | 27 +++++++++------------------ drivers/net/dpaa2/dpaa2_mux.c | 6 ++---- 3 files changed, 12 insertions(+), 24 deletions(-)drivers/net/dpaa2/dpaa2_ethdev.c +1
-2@@ -1401,8 +1401,7 @@ dpaa2_dev_close(struct rte_eth_dev *dev)for (i =0 ; i <MAX_TCS ; i++)rte_free (priv->extract.tc_extract_param[i]); -if (priv->extract.qos_extract_param) -rte_free (priv->extract.qos_extract_param); +rte_free (priv->extract.qos_extract_param);DPAA2_PMD_INFO ("%s: netdev deleted" , dev->data->name);return 0 ;drivers/net/dpaa2/dpaa2_flow.c +9
-18@@ -4784,8 +4784,7 @@ dpaa2_generic_flow_set(struct dpaa2_dev_flow *flow, } } -if (dpaa2_pattern) -rte_free (dpaa2_pattern); +rte_free (dpaa2_pattern);return ret; }@@ -5057,14 +5056,10 @@ dpaa2_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr, creation_error:if (flow) { -if (flow->qos_key_addr) -rte_free (flow->qos_key_addr); -if (flow->qos_mask_addr) -rte_free (flow->qos_mask_addr); -if (flow->fs_key_addr) -rte_free (flow->fs_key_addr); -if (flow->fs_mask_addr) -rte_free (flow->fs_mask_addr); +rte_free (flow->qos_key_addr); +rte_free (flow->qos_mask_addr); +rte_free (flow->fs_key_addr); +rte_free (flow->fs_mask_addr);rte_free (flow); } priv->curr =NULL ;@@ -5128,14 +5123,10 @@ dpaa2_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *_flow, }LIST_REMOVE (flow, next); -if (flow->qos_key_addr) -rte_free (flow->qos_key_addr); -if (flow->qos_mask_addr) -rte_free (flow->qos_mask_addr); -if (flow->fs_key_addr) -rte_free (flow->fs_key_addr); -if (flow->fs_mask_addr) -rte_free (flow->fs_mask_addr); +rte_free (flow->qos_key_addr); +rte_free (flow->qos_mask_addr); +rte_free (flow->fs_key_addr); +rte_free (flow->fs_mask_addr);/* Now free the flow */ rte_free (flow);drivers/net/dpaa2/dpaa2_mux.c +2
-4@@ -329,10 +329,8 @@ rte_pmd_dpaa2_mux_flow_create(uint32_t dpdmux_id, } creation_error: -if (key_cfg_va) -rte_free (key_cfg_va); -if (key_va) -rte_free (key_va); +rte_free (key_cfg_va); +rte_free (key_va);return ret; }
PATCH 3/3 net/ntnic: remove unnecessary check for null before free
In reply to Stephen HemmingerIt is unnecessary to check for NULL pointer before calling free. Found by nullfree.cocci
--- drivers/net/ntnic/nthw/flow_api/flow_api.c | 6 ++---- .../net/ntnic/nthw/flow_api/profile_inline/flm_age_queue.c | 3 +-- .../net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.c | 3 +-- .../net/ntnic/nthw/flow_api/profile_inline/flm_lrn_queue.c | 3 +-- drivers/net/ntnic/nthw/stat/nthw_stat.c | 3 +-- 5 files changed, 6 insertions(+), 12 deletions(-)
drivers/net/ntnic/nthw/flow_api/flow_api.c +2 -4
@@ -473,8 +473,7 @@ static void done_resource_elements(struct flow_nic_dev *ndev, enum res_type_e re {assert (ndev); -if (ndev->res[res_type].alloc_bm) -free (ndev->res[res_type].alloc_bm); +free (ndev->res[res_type].alloc_bm); }static void list_insert_flow_nic (struct flow_nic_dev *ndev)
@@ -653,8 +652,7 @@ static struct flow_eth_dev *flow_get_eth_dev(uint8_t adapter_no, uint8_t port_norte_spinlock_unlock (&ndev->mtx);rte_spinlock_unlock (&base_mtx); -if (eth_dev) -free (eth_dev); +free (eth_dev);#ifdef FLOW_DEBUG ndev->be.iface->set_debug_mode (ndev->be.be_dev,FLOW_BACKEND_DEBUG_MODE_NONE );
drivers/net/ntnic/nthw/flow_api/profile_inline/flm_age_queue.c +1 -2
@@ -40,8 +40,7 @@ void flm_age_queue_free(uint8_t port, uint16_t caller_id) age_queue[caller_id] =NULL ; } -if (q !=NULL ) -rte_ring_free (q); +rte_ring_free (q); }void flm_age_queue_free_all (void )
drivers/net/ntnic/nthw/flow_api/profile_inline/flm_evt_queue.c +1 -2
@@ -68,8 +68,7 @@ static void flm_inf_sta_queue_free(uint8_t port, uint8_t caller)break ; } -if (q) -rte_ring_free (q); +rte_ring_free (q); }void flm_inf_sta_queue_free_all (uint8_t caller)
drivers/net/ntnic/nthw/flow_api/profile_inline/flm_lrn_queue.c +1 -2
@@ -31,8 +31,7 @@ void *flm_lrn_queue_create(void)void flm_lrn_queue_free (void *q) { -if (q) -rte_ring_free (q); +rte_ring_free (q); }uint32_t *flm_lrn_queue_get_write_buffer (void *q)
drivers/net/ntnic/nthw/stat/nthw_stat.c +1 -2
@@ -25,8 +25,7 @@ nthw_stat_t *nthw_stat_new(void)void nthw_stat_delete (nthw_stat_t *p) { -if (p) -free (p); +free (p); }int nthw_stat_init (nthw_stat_t *p,nthw_fpga_t *p_fpga,int n_instance)
Signature · 1 line
2.45.2
Quoted 7 lines · Stephen Hemminger
Found by running
nullfree.coccion 24.11-rc2Stephen Hemminger (3):
bus/fslmc: remove unnecessary null check net/dpaa2: remove unnecessary check for null beforerte_freenet/ntnic: remove unnecessary check for null before free
For series,
Btw, script catches 'rte_openssl_pmd.c' for 'EVP_PKEY_free()' call, which seems ignoring the NULL value, it can be separate patch for crypto tree.
Series applied to dpdk-next-net/main, thanks.
Quoted 9 lines · On Wed, 13 Nov 2024 01:25:37 +0000 Ferruh Yigit <[email protected]> wrote:
Quoted 7 lines · Stephen Hemminger
Found by running
nullfree.coccion 24.11-rc2Stephen Hemminger (3):
bus/fslmc: remove unnecessary null check net/dpaa2: remove unnecessary check for null beforerte_freenet/ntnic: remove unnecessary check for null before free
Quoted 6 lines
For series,
Acked-by Ferruh Yigit <[email protected]>Btw, script catches '
rte_openssl_pmd.c' for 'EVP_PKEY_free()' call, which seems ignoring the NULL value, it can be separate patch for crypto tree.
Right I wanted to check that one more carefully.