From d12a9b80de078296b6d39a5fde05752796d966b0 Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Wed, 14 Aug 2024 00:57:25 -0400 Subject: [PATCH] LU-18141 lnet: don't check for NULL before free'ing The common free'ing macros already check for NULL, so we don't need to explicitly check this beforehand. The patch has been generated with the coccinelle script below. @@ expression E; @@ - if (E != NULL) ( OBD_FREE_PTR(E); | OBD_FREE(E, ...); | LIBCFS_FREE(E, ...); | CFS_FREE_PTR(E); | CFS_FREE_PTR_ARRAY(E, ...); ) Test-Parameters: trivial Signed-off-by: Timothy Day Change-Id: Ia3a61ad54803ebfccf70afde1bba5c168f7e051e Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56043 Reviewed-by: Andreas Dilger Reviewed-by: jsimmons Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- lnet/lnet/api-ni.c | 3 +-- lnet/lnet/config.c | 3 +-- lnet/lnet/lib-cpt.c | 32 +++++++++++--------------------- lnet/lnet/lnet_debugfs.c | 6 ++---- lnet/lnet/peer.c | 9 +++------ lnet/lnet/router.c | 6 ++---- 6 files changed, 20 insertions(+), 39 deletions(-) diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index d1fce1b..91f993f 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -6345,8 +6345,7 @@ lnet_genl_parse_local_ni(struct nlattr *entry, struct genl_info *info, } } out: - if (tun) - LIBCFS_FREE(tun, sizeof(struct lnet_ioctl_config_lnd_tunables)); + LIBCFS_FREE(tun, sizeof(struct lnet_ioctl_config_lnd_tunables)); return rc; } diff --git a/lnet/lnet/config.c b/lnet/lnet/config.c index 2c60a74..f166755 100644 --- a/lnet/lnet/config.c +++ b/lnet/lnet/config.c @@ -128,8 +128,7 @@ lnet_net_append_cpts(__u32 *cpts, __u32 ncpts, struct lnet_net *net) if (cpts == NULL) { /* there is an NI which will exist on all CPTs */ - if (net->net_cpts != NULL) - CFS_FREE_PTR_ARRAY(net->net_cpts, net->net_ncpts); + CFS_FREE_PTR_ARRAY(net->net_cpts, net->net_ncpts); net->net_cpts = NULL; net->net_ncpts = LNET_CPT_NUMBER; return 0; diff --git a/lnet/lnet/lib-cpt.c b/lnet/lnet/lib-cpt.c index 6d026c7..4724b65 100644 --- a/lnet/lnet/lib-cpt.c +++ b/lnet/lnet/lib-cpt.c @@ -161,20 +161,16 @@ failed_setting_ctb_parts: } } - if (cptab->ctb_parts) - CFS_FREE_PTR_ARRAY(cptab->ctb_parts, cptab->ctb_nparts); + CFS_FREE_PTR_ARRAY(cptab->ctb_parts, cptab->ctb_nparts); failed_alloc_ctb_parts: - if (cptab->ctb_node2cpt) - CFS_FREE_PTR_ARRAY(cptab->ctb_node2cpt, nr_node_ids); + CFS_FREE_PTR_ARRAY(cptab->ctb_node2cpt, nr_node_ids); failed_alloc_node2cpt: - if (cptab->ctb_cpu2cpt) - CFS_FREE_PTR_ARRAY(cptab->ctb_cpu2cpt, nr_cpu_ids); + CFS_FREE_PTR_ARRAY(cptab->ctb_cpu2cpt, nr_cpu_ids); failed_alloc_cpu2cpt: - if (cptab->ctb_nodemask) - LIBCFS_FREE(cptab->ctb_nodemask, sizeof(*cptab->ctb_nodemask)); + LIBCFS_FREE(cptab->ctb_nodemask, sizeof(*cptab->ctb_nodemask)); failed_alloc_nodemask: free_cpumask_var(cptab->ctb_cpumask); failed_alloc_cpumask: @@ -187,11 +183,9 @@ void cfs_cpt_table_free(struct cfs_cpt_table *cptab) { int i; - if (cptab->ctb_cpu2cpt) - CFS_FREE_PTR_ARRAY(cptab->ctb_cpu2cpt, nr_cpu_ids); + CFS_FREE_PTR_ARRAY(cptab->ctb_cpu2cpt, nr_cpu_ids); - if (cptab->ctb_node2cpt) - CFS_FREE_PTR_ARRAY(cptab->ctb_node2cpt, nr_node_ids); + CFS_FREE_PTR_ARRAY(cptab->ctb_node2cpt, nr_node_ids); for (i = 0; cptab->ctb_parts && i < cptab->ctb_nparts; i++) { struct cfs_cpu_partition *part = &cptab->ctb_parts[i]; @@ -203,16 +197,13 @@ void cfs_cpt_table_free(struct cfs_cpt_table *cptab) free_cpumask_var(part->cpt_cpumask); - if (part->cpt_distance) - CFS_FREE_PTR_ARRAY(part->cpt_distance, - cptab->ctb_nparts); + CFS_FREE_PTR_ARRAY(part->cpt_distance, + cptab->ctb_nparts); } - if (cptab->ctb_parts) - CFS_FREE_PTR_ARRAY(cptab->ctb_parts, cptab->ctb_nparts); + CFS_FREE_PTR_ARRAY(cptab->ctb_parts, cptab->ctb_nparts); - if (cptab->ctb_nodemask) - LIBCFS_FREE(cptab->ctb_nodemask, sizeof(*cptab->ctb_nodemask)); + LIBCFS_FREE(cptab->ctb_nodemask, sizeof(*cptab->ctb_nodemask)); free_cpumask_var(cptab->ctb_cpumask); LIBCFS_FREE(cptab, sizeof(*cptab)); @@ -1127,8 +1118,7 @@ cfs_percpt_free(void *vars) arr = container_of(vars, struct cfs_var_array, va_ptrs[0]); for (i = 0; i < arr->va_count; i++) { - if (arr->va_ptrs[i]) - LIBCFS_FREE(arr->va_ptrs[i], arr->va_size); + LIBCFS_FREE(arr->va_ptrs[i], arr->va_size); } LIBCFS_FREE(arr, offsetof(struct cfs_var_array, diff --git a/lnet/lnet/lnet_debugfs.c b/lnet/lnet/lnet_debugfs.c index 79b3456..4e53afa 100644 --- a/lnet/lnet/lnet_debugfs.c +++ b/lnet/lnet/lnet_debugfs.c @@ -96,8 +96,7 @@ static int proc_cpt_table(struct ctl_table *table, int write, rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL); out: - if (buf) - LIBCFS_FREE(buf, len); + LIBCFS_FREE(buf, len); return rc; } @@ -137,8 +136,7 @@ static int proc_cpt_distance(struct ctl_table *table, int write, rc = cfs_trace_copyout_string(buffer, nob, buf + pos, NULL); out: - if (buf) - LIBCFS_FREE(buf, len); + LIBCFS_FREE(buf, len); return rc; } diff --git a/lnet/lnet/peer.c b/lnet/lnet/peer.c index 398fb76..b6bfefc 100644 --- a/lnet/lnet/peer.c +++ b/lnet/lnet/peer.c @@ -1259,8 +1259,7 @@ remove_nid_entry: spin_unlock(&lpni->lpni_lock); lnet_net_unlock(LNET_LOCK_EX); - if (ne) - LIBCFS_FREE(ne, sizeof(*ne)); + LIBCFS_FREE(ne, sizeof(*ne)); out: CDEBUG(D_NET, "peer %s nid %s: %d\n", libcfs_nidstr(&lp->lp_primary_nid), libcfs_nidstr(nid), rc); @@ -1997,10 +1996,8 @@ __must_hold(&the_lnet.ln_api_mutex) out_err: if (rc) { - if (lpn) - LIBCFS_FREE(lpn, sizeof(*lpn)); - if (lp) - LIBCFS_FREE(lp, sizeof(*lp)); + LIBCFS_FREE(lpn, sizeof(*lpn)); + LIBCFS_FREE(lp, sizeof(*lp)); lpni = ERR_PTR(rc); } out: diff --git a/lnet/lnet/router.c b/lnet/lnet/router.c index 9b43823..7bcb1be 100644 --- a/lnet/lnet/router.c +++ b/lnet/lnet/router.c @@ -639,10 +639,8 @@ __must_hold(&the_lnet.ln_api_mutex) if (route == NULL || rnet == NULL) { CERROR("Out of memory creating route %s %d %s\n", libcfs_net2str(net), hops, libcfs_nidstr(gateway)); - if (route != NULL) - LIBCFS_FREE(route, sizeof(*route)); - if (rnet != NULL) - LIBCFS_FREE(rnet, sizeof(*rnet)); + LIBCFS_FREE(route, sizeof(*route)); + LIBCFS_FREE(rnet, sizeof(*rnet)); return -ENOMEM; } -- 1.8.3.1