Whamcloud - gitweb
LU-18141 lnet: don't check for NULL before free'ing 43/56043/3
authorTimothy Day <timday@amazon.com>
Wed, 14 Aug 2024 04:57:25 +0000 (00:57 -0400)
committerOleg Drokin <green@whamcloud.com>
Fri, 23 Aug 2024 22:07:40 +0000 (22:07 +0000)
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 <timday@amazon.com>
Change-Id: Ia3a61ad54803ebfccf70afde1bba5c168f7e051e
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56043
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: jsimmons <jsimmons@infradead.org>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lnet/lnet/api-ni.c
lnet/lnet/config.c
lnet/lnet/lib-cpt.c
lnet/lnet/lnet_debugfs.c
lnet/lnet/peer.c
lnet/lnet/router.c

index d1fce1b..91f993f 100644 (file)
@@ -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;
 }
index 2c60a74..f166755 100644 (file)
@@ -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;
index 6d026c7..4724b65 100644 (file)
@@ -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,
index 79b3456..4e53afa 100644 (file)
@@ -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;
 }
 
index 398fb76..b6bfefc 100644 (file)
@@ -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:
index 9b43823..7bcb1be 100644 (file)
@@ -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;
        }