From e0aeb99bbf8806fabd29e14de0131266ad440320 Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Wed, 14 Aug 2024 01:07:59 -0400 Subject: [PATCH] LU-18141 misc: (for [mf]*) don't check 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: I027db689261e507a3f297a31643baf2ed61bcc7c Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56048 Reviewed-by: Andreas Dilger Reviewed-by: jsimmons Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- lustre/fid/lproc_fid.c | 3 +-- lustre/fld/fld_index.c | 3 +-- lustre/fld/lproc_fld.c | 3 +-- lustre/mdc/mdc_changelog.c | 3 +-- lustre/mdd/mdd_device.c | 3 +-- lustre/mdd/mdd_orphans.c | 6 ++---- lustre/mgs/mgs_llog.c | 15 +++++---------- 7 files changed, 12 insertions(+), 24 deletions(-) diff --git a/lustre/fid/lproc_fid.c b/lustre/fid/lproc_fid.c index e6809a5..62a4f75 100644 --- a/lustre/fid/lproc_fid.c +++ b/lustre/fid/lproc_fid.c @@ -362,8 +362,7 @@ out: if (rc != 0) { if (env_init == 1) lu_env_fini(¶m->fsp_env); - if (param != NULL) - OBD_FREE_PTR(param); + OBD_FREE_PTR(param); } return rc; } diff --git a/lustre/fld/fld_index.c b/lustre/fld/fld_index.c index a098441..2407a85 100644 --- a/lustre/fld/fld_index.c +++ b/lustre/fld/fld_index.c @@ -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) diff --git a/lustre/fld/lproc_fld.c b/lustre/fld/lproc_fld.c index 5ef9605..854cf1d 100644 --- a/lustre/fld/lproc_fld.c +++ b/lustre/fld/lproc_fld.c @@ -292,8 +292,7 @@ out: if (rc != 0) { if (env_init == 1) lu_env_fini(¶m->fsp_env); - if (param != NULL) - OBD_FREE_PTR(param); + OBD_FREE_PTR(param); } return rc; } diff --git a/lustre/mdc/mdc_changelog.c b/lustre/mdc/mdc_changelog.c index 9edf5e6..9594d25 100644 --- a/lustre/mdc/mdc_changelog.c +++ b/lustre/mdc/mdc_changelog.c @@ -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); } diff --git a/lustre/mdd/mdd_device.c b/lustre/mdd/mdd_device.c index 9e9434d..a6e9395 100644 --- a/lustre/mdd/mdd_device.c +++ b/lustre/mdd/mdd_device.c @@ -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); } diff --git a/lustre/mdd/mdd_orphans.c b/lustre/mdd/mdd_orphans.c index 624502b..cf1c035 100644 --- a/lustre/mdd/mdd_orphans.c +++ b/lustre/mdd/mdd_orphans.c @@ -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; } diff --git a/lustre/mgs/mgs_llog.c b/lustre/mgs/mgs_llog.c index 6c7be7a..b930532 100644 --- a/lustre/mgs/mgs_llog.c +++ b/lustre/mgs/mgs_llog.c @@ -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: -- 1.8.3.1