From 8fb94c0a644a0f78e980d520a03d4b6fd95d07c2 Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Wed, 14 Aug 2024 00:58:56 -0400 Subject: [PATCH] LU-18141 mdt: 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: Id08fd059dbc4fcb3508497bdd04c6b00035ff91e Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56045 Tested-by: jenkins Tested-by: Maloo Reviewed-by: jsimmons Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin --- lustre/mdt/mdt_batch.c | 3 +-- lustre/mdt/mdt_coordinator.c | 3 +-- lustre/mdt/mdt_handler.c | 32 +++++++++++--------------------- lustre/mdt/mdt_hsm_cdt_actions.c | 3 +-- lustre/mdt/mdt_hsm_cdt_agent.c | 3 +-- lustre/mdt/mdt_lproc.c | 3 +-- lustre/mdt/mdt_lvb.c | 3 +-- 7 files changed, 17 insertions(+), 33 deletions(-) diff --git a/lustre/mdt/mdt_batch.c b/lustre/mdt/mdt_batch.c index 27b17ef..b7c1dc9 100644 --- a/lustre/mdt/mdt_batch.c +++ b/lustre/mdt/mdt_batch.c @@ -371,8 +371,7 @@ out_free: OBD_FREE_PTR_ARRAY(update_bufs, update_buf_count); } - if (trd) - OBD_FREE_PTR(trd); + OBD_FREE_PTR(trd); if (desc != NULL) ptlrpc_free_bulk(desc); diff --git a/lustre/mdt/mdt_coordinator.c b/lustre/mdt/mdt_coordinator.c index b7bf445..5794e95 100644 --- a/lustre/mdt/mdt_coordinator.c +++ b/lustre/mdt/mdt_coordinator.c @@ -1960,8 +1960,7 @@ static int hsm_cancel_all_actions(struct mdt_device *mdt) } up_read(&cdt->cdt_request_lock); - if (hal != NULL) - OBD_FREE(hal, hal_sz); + OBD_FREE(hal, hal_sz); /* cancel all on-disk records */ rc = cdt_llog_process(mti->mti_env, mti->mti_mdt, mdt_cancel_all_cb, diff --git a/lustre/mdt/mdt_handler.c b/lustre/mdt/mdt_handler.c index 0e7b51b..5a1d40b 100644 --- a/lustre/mdt/mdt_handler.c +++ b/lustre/mdt/mdt_handler.c @@ -476,8 +476,7 @@ static int mdt_get_root(struct tgt_session_info *tsi) EXIT; out: mdt_thread_info_fini(info); - if (buffer) - OBD_FREE(buffer, PATH_MAX+1); + OBD_FREE(buffer, PATH_MAX+1); return rc; } @@ -5500,8 +5499,7 @@ static int mdt_register_seq_exp(struct mdt_device *mdt) GOTO(out_free, rc); } out_free: - if (lwp_name != NULL) - OBD_FREE(lwp_name, MAX_OBD_NAME); + OBD_FREE(lwp_name, MAX_OBD_NAME); return rc; } @@ -5750,8 +5748,7 @@ static int mdt_connect_to_next(const struct lu_env *env, struct mdt_device *m, } out: - if (data) - OBD_FREE_PTR(data); + OBD_FREE_PTR(data); RETURN(rc); } @@ -5897,10 +5894,8 @@ put_profile: free_bufs: OBD_FREE_PTR(bufs); cleanup_mem: - if (name) - OBD_FREE(name, name_size); - if (uuid) - OBD_FREE(uuid, uuid_size); + OBD_FREE(name, name_size); + OBD_FREE(uuid, uuid_size); RETURN(rc); } @@ -6037,14 +6032,10 @@ lcfg_cleanup: put_profile: class_put_profile(lprof); cleanup_mem: - if (bufs) - OBD_FREE_PTR(bufs); - if (qmtname) - OBD_FREE(qmtname, MAX_OBD_NAME); - if (uuid) - OBD_FREE(uuid, UUID_MAX); - if (data) - OBD_FREE_PTR(data); + OBD_FREE_PTR(bufs); + OBD_FREE(qmtname, MAX_OBD_NAME); + OBD_FREE(uuid, UUID_MAX); + OBD_FREE_PTR(data); return rc; } @@ -7400,9 +7391,8 @@ static int mdt_destroy_export(struct obd_export *exp) ENTRY; target_destroy_export(exp); - if (exp->exp_used_slots) - OBD_FREE(exp->exp_used_slots, - BITS_TO_LONGS(OBD_MAX_RIF_MAX) * sizeof(long)); + OBD_FREE(exp->exp_used_slots, + BITS_TO_LONGS(OBD_MAX_RIF_MAX) * sizeof(long)); /* destroy can be called from failed obd_setup, so * checking uuid is safer than obd_self_export diff --git a/lustre/mdt/mdt_hsm_cdt_actions.c b/lustre/mdt/mdt_hsm_cdt_actions.c index c50ccee..44f6cb7 100644 --- a/lustre/mdt/mdt_hsm_cdt_actions.c +++ b/lustre/mdt/mdt_hsm_cdt_actions.c @@ -690,8 +690,7 @@ err: seq_release(inode, file); if (aai && aai->aai_env.le_ses) OBD_FREE_PTR(aai->aai_env.le_ses); - if (aai) - OBD_FREE_PTR(aai); + OBD_FREE_PTR(aai); out: return rc; } diff --git a/lustre/mdt/mdt_hsm_cdt_agent.c b/lustre/mdt/mdt_hsm_cdt_agent.c index 379730b..d70e5ea 100644 --- a/lustre/mdt/mdt_hsm_cdt_agent.c +++ b/lustre/mdt/mdt_hsm_cdt_agent.c @@ -137,8 +137,7 @@ out_free: if (ha != NULL && ha->ha_archive_id != NULL) OBD_FREE_PTR_ARRAY(ha->ha_archive_id, ha->ha_archive_cnt); - if (ha != NULL) - OBD_FREE_PTR(ha); + OBD_FREE_PTR(ha); out: /* wake the coordinator to potentially schedule requests */ if (rc == -EEXIST || rc == 0) diff --git a/lustre/mdt/mdt_lproc.c b/lustre/mdt/mdt_lproc.c index e848540..f94fd4c 100644 --- a/lustre/mdt/mdt_lproc.c +++ b/lustre/mdt/mdt_lproc.c @@ -400,8 +400,7 @@ again: param->idd_uid, param); out: - if (param != NULL) - OBD_FREE(param, size); + OBD_FREE(param, size); return rc ? rc : count; } diff --git a/lustre/mdt/mdt_lvb.c b/lustre/mdt/mdt_lvb.c index 729cb8e..cf5e6a9 100644 --- a/lustre/mdt/mdt_lvb.c +++ b/lustre/mdt/mdt_lvb.c @@ -456,8 +456,7 @@ static int mdt_lvbo_free(struct ldlm_resource *res) } /* Data-on-MDT lvbo free */ - if (res->lr_lvb_data != NULL) - OBD_FREE(res->lr_lvb_data, res->lr_lvb_len); + OBD_FREE(res->lr_lvb_data, res->lr_lvb_len); return 0; } -- 1.8.3.1