Whamcloud - gitweb
LU-18141 misc: (for [mf]*) don't check NULL before free'ing 48/56048/2
authorTimothy Day <timday@amazon.com>
Wed, 14 Aug 2024 05:07:59 +0000 (01:07 -0400)
committerOleg Drokin <green@whamcloud.com>
Fri, 23 Aug 2024 22:08:39 +0000 (22:08 +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: I027db689261e507a3f297a31643baf2ed61bcc7c
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56048
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>
lustre/fid/lproc_fid.c
lustre/fld/fld_index.c
lustre/fld/lproc_fld.c
lustre/mdc/mdc_changelog.c
lustre/mdd/mdd_device.c
lustre/mdd/mdd_orphans.c
lustre/mgs/mgs_llog.c

index e6809a5..62a4f75 100644 (file)
@@ -362,8 +362,7 @@ out:
        if (rc != 0) {
                if (env_init == 1)
                        lu_env_fini(&param->fsp_env);
-               if (param != NULL)
-                       OBD_FREE_PTR(param);
+               OBD_FREE_PTR(param);
        }
        return rc;
 }
index a098441..2407a85 100644 (file)
@@ -431,8 +431,7 @@ out_it_put:
 out_it_fini:
        iops->fini(env, it);
 out:
-       if (attr)
-               OBD_FREE_PTR(attr);
+       OBD_FREE_PTR(attr);
 
        if (rc < 0) {
                if (dt_obj)
index 5ef9605..854cf1d 100644 (file)
@@ -292,8 +292,7 @@ out:
        if (rc != 0) {
                if (env_init == 1)
                        lu_env_fini(&param->fsp_env);
-               if (param != NULL)
-                       OBD_FREE_PTR(param);
+               OBD_FREE_PTR(param);
        }
        return rc;
 }
index 9edf5e6..9594d25 100644 (file)
@@ -850,8 +850,7 @@ out_listrm:
 
 out_unlock:
        mutex_unlock(&chlg_registered_dev_lock);
-       if (entry)
-               OBD_FREE_PTR(entry);
+       OBD_FREE_PTR(entry);
        RETURN(rc);
 }
 
index 9e9434d..a6e9395 100644 (file)
@@ -130,8 +130,7 @@ static int mdd_connect_to_next(const struct lu_env *env, struct mdd_device *m,
        lu_dev_add_linkage(lud->ld_site, lud);
 
 out:
-       if (data)
-               OBD_FREE(data, sizeof(*data));
+       OBD_FREE(data, sizeof(*data));
        RETURN(rc);
 }
 
index 624502b..cf1c035 100644 (file)
@@ -549,8 +549,7 @@ static int mdd_orphan_cleanup_thread(void *args)
        lu_env_fini(env);
        GOTO(out, rc);
 out:
-       if (env)
-               OBD_FREE_PTR(env);
+       OBD_FREE_PTR(env);
        complete(&thread->mgt_finished);
        return rc;
 }
@@ -576,8 +575,7 @@ out:
        if (rc)
                CERROR("%s: start orphan cleanup thread failed: rc = %d\n",
                       mdd2obd_dev(d)->obd_name, rc);
-       if (name)
-               OBD_FREE(name, MTI_NAME_MAXLEN);
+       OBD_FREE(name, MTI_NAME_MAXLEN);
 
        return rc;
 }
index 6c7be7a..b930532 100644 (file)
@@ -146,8 +146,7 @@ static inline int name_create(char **newname, char *prefix, char *suffix)
 
 static inline void name_destroy(char **name)
 {
-       if (*name)
-               OBD_FREE(*name, strlen(*name) + 1);
+       OBD_FREE(*name, strlen(*name) + 1);
        *name = NULL;
 }
 
@@ -552,10 +551,8 @@ static void mgs_free_fsdb(struct mgs_device *mgs, struct fs_db *fsdb)
        if (fsdb->fsdb_mgs)
                mgs_ir_fini_fs(mgs, fsdb);
 
-       if (fsdb->fsdb_ost_index_map)
-               OBD_FREE(fsdb->fsdb_ost_index_map, INDEX_MAP_SIZE);
-       if (fsdb->fsdb_mdt_index_map)
-               OBD_FREE(fsdb->fsdb_mdt_index_map, INDEX_MAP_SIZE);
+       OBD_FREE(fsdb->fsdb_ost_index_map, INDEX_MAP_SIZE);
+       OBD_FREE(fsdb->fsdb_mdt_index_map, INDEX_MAP_SIZE);
        name_destroy(&fsdb->fsdb_clilov);
        name_destroy(&fsdb->fsdb_clilmv);
        mgs_free_fsdb_srpc(fsdb);
@@ -5285,8 +5282,7 @@ out:
                llog_close(env, old_llh);
        if (new_llh)
                llog_close(env, new_llh);
-       if (name_buf)
-               OBD_FREE(name_buf, name_buflen);
+       OBD_FREE(name_buf, name_buflen);
        if (ctxt)
                llog_ctxt_put(ctxt);
 
@@ -6067,8 +6063,7 @@ out_unlock:
 out_mti:
        OBD_FREE_PTR(mti);
 out_cancel:
-       if (canceled_label)
-               OBD_FREE(canceled_label, label_sz);
+       OBD_FREE(canceled_label, label_sz);
 out_label:
        OBD_FREE(label, label_sz);
 out_fsdb: