From ffe9424e4274d310104bd5fe68dc5a694c3e81df Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Wed, 14 Aug 2024 00:56:29 -0400 Subject: [PATCH] LU-18141 obdclass: 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: Ie5d5567fecc1f421fb0894816c880b41ea93843b Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56042 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Arshad Hussain Reviewed-by: Andreas Dilger Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lustre/obdclass/llog_osd.c | 6 ++-- lustre/obdclass/lprocfs_status_server.c | 3 +- lustre/obdclass/lu_tgt_descs.c | 3 +- lustre/obdclass/obd_config.c | 15 ++++------ lustre/obdclass/obd_mount.c | 52 +++++++++++++-------------------- 5 files changed, 29 insertions(+), 50 deletions(-) diff --git a/lustre/obdclass/llog_osd.c b/lustre/obdclass/llog_osd.c index 4720eb6..76bd90d 100644 --- a/lustre/obdclass/llog_osd.c +++ b/lustre/obdclass/llog_osd.c @@ -1602,8 +1602,7 @@ after_open: out_put: dt_object_put(env, o); out_name: - if (handle->lgh_name != NULL) - OBD_FREE(handle->lgh_name, strlen(name) + 1); + OBD_FREE(handle->lgh_name, strlen(name) + 1); out: if (los != NULL) dt_los_put(los); @@ -1910,8 +1909,7 @@ static int llog_osd_close(const struct lu_env *env, struct llog_handle *handle) LASSERT(los); dt_los_put(los); - if (handle->lgh_name) - OBD_FREE(handle->lgh_name, strlen(handle->lgh_name) + 1); + OBD_FREE(handle->lgh_name, strlen(handle->lgh_name) + 1); RETURN(rc); } diff --git a/lustre/obdclass/lprocfs_status_server.c b/lustre/obdclass/lprocfs_status_server.c index e374e3c..c657f90 100644 --- a/lustre/obdclass/lprocfs_status_server.c +++ b/lustre/obdclass/lprocfs_status_server.c @@ -979,8 +979,7 @@ int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data) obd->obd_recovery_start)); } - if (buf != NULL) - OBD_FREE(buf, size); + OBD_FREE(buf, size); if (likely(count > 0)) goto out; diff --git a/lustre/obdclass/lu_tgt_descs.c b/lustre/obdclass/lu_tgt_descs.c index 0062ded..208d3c4 100644 --- a/lustre/obdclass/lu_tgt_descs.c +++ b/lustre/obdclass/lu_tgt_descs.c @@ -304,8 +304,7 @@ void lu_tgt_descs_fini(struct lu_tgt_descs *ltd) bitmap_free(ltd->ltd_tgt_bitmap); for (i = 0; i < ARRAY_SIZE(ltd->ltd_tgt_idx); i++) { - if (ltd->ltd_tgt_idx[i]) - OBD_FREE_PTR(ltd->ltd_tgt_idx[i]); + OBD_FREE_PTR(ltd->ltd_tgt_idx[i]); } ltd->ltd_tgts_size = 0; } diff --git a/lustre/obdclass/obd_config.c b/lustre/obdclass/obd_config.c index 74d55e2..c3379a7 100644 --- a/lustre/obdclass/obd_config.c +++ b/lustre/obdclass/obd_config.c @@ -1121,12 +1121,9 @@ static int class_add_profile(int proflen, char *prof, int osclen, char *osc, RETURN(err); out: - if (lprof->lp_md) - OBD_FREE(lprof->lp_md, mdclen); - if (lprof->lp_dt) - OBD_FREE(lprof->lp_dt, osclen); - if (lprof->lp_profile) - OBD_FREE(lprof->lp_profile, proflen); + OBD_FREE(lprof->lp_md, mdclen); + OBD_FREE(lprof->lp_dt, osclen); + OBD_FREE(lprof->lp_profile, proflen); OBD_FREE(lprof, sizeof(*lprof)); RETURN(err); } @@ -1176,8 +1173,7 @@ void class_put_profile(struct lustre_profile *lprof) LASSERT(lprof->lp_list_deleted); OBD_FREE(lprof->lp_profile, strlen(lprof->lp_profile) + 1); OBD_FREE(lprof->lp_dt, strlen(lprof->lp_dt) + 1); - if (lprof->lp_md) - OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1); + OBD_FREE(lprof->lp_md, strlen(lprof->lp_md) + 1); OBD_FREE(lprof, sizeof(*lprof)); } EXPORT_SYMBOL(class_put_profile); @@ -2020,8 +2016,7 @@ int class_config_llog_handler(const struct lu_env *env, OBD_FREE(lcfg_new, lustre_cfg_len(lcfg_new->lcfg_bufcount, lcfg_new->lcfg_buflens)); out_inst: - if (inst_name) - OBD_FREE(inst_name, inst_len); + OBD_FREE(inst_name, inst_len); break; } default: diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index 9f53c90..d117eaa 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -568,12 +568,9 @@ out: out_free: mutex_unlock(&mgc_start_lock); - if (uuid) - OBD_FREE_PTR(uuid); - if (data) - OBD_FREE_PTR(data); - if (mgcname) - OBD_FREE(mgcname, len); + OBD_FREE_PTR(uuid); + OBD_FREE_PTR(data); + OBD_FREE(mgcname, len); mgc_niduuid_destroy(&niduuid); RETURN(rc); @@ -699,36 +696,27 @@ static int lustre_free_lsi(struct lustre_sb_info *lsi) llcrypt_sb_free(lsi); if (lsi->lsi_lmd != NULL) { - if (lsi->lsi_lmd->lmd_dev != NULL) - OBD_FREE(lsi->lsi_lmd->lmd_dev, - strlen(lsi->lsi_lmd->lmd_dev) + 1); - if (lsi->lsi_lmd->lmd_profile != NULL) - OBD_FREE(lsi->lsi_lmd->lmd_profile, - strlen(lsi->lsi_lmd->lmd_profile) + 1); - if (lsi->lsi_lmd->lmd_fileset != NULL) - OBD_FREE(lsi->lsi_lmd->lmd_fileset, - strlen(lsi->lsi_lmd->lmd_fileset) + 1); - if (lsi->lsi_lmd->lmd_mgssec != NULL) - OBD_FREE(lsi->lsi_lmd->lmd_mgssec, - strlen(lsi->lsi_lmd->lmd_mgssec) + 1); - if (lsi->lsi_lmd->lmd_opts != NULL) - OBD_FREE(lsi->lsi_lmd->lmd_opts, - strlen(lsi->lsi_lmd->lmd_opts) + 1); + OBD_FREE(lsi->lsi_lmd->lmd_dev, + strlen(lsi->lsi_lmd->lmd_dev) + 1); + OBD_FREE(lsi->lsi_lmd->lmd_profile, + strlen(lsi->lsi_lmd->lmd_profile) + 1); + OBD_FREE(lsi->lsi_lmd->lmd_fileset, + strlen(lsi->lsi_lmd->lmd_fileset) + 1); + OBD_FREE(lsi->lsi_lmd->lmd_mgssec, + strlen(lsi->lsi_lmd->lmd_mgssec) + 1); + OBD_FREE(lsi->lsi_lmd->lmd_opts, + strlen(lsi->lsi_lmd->lmd_opts) + 1); if (lsi->lsi_lmd->lmd_exclude_count) OBD_FREE(lsi->lsi_lmd->lmd_exclude, sizeof(lsi->lsi_lmd->lmd_exclude[0]) * lsi->lsi_lmd->lmd_exclude_count); - if (lsi->lsi_lmd->lmd_mgs != NULL) - OBD_FREE(lsi->lsi_lmd->lmd_mgs, - strlen(lsi->lsi_lmd->lmd_mgs) + 1); - if (lsi->lsi_lmd->lmd_osd_type != NULL) - OBD_FREE(lsi->lsi_lmd->lmd_osd_type, - strlen(lsi->lsi_lmd->lmd_osd_type) + 1); - if (lsi->lsi_lmd->lmd_params != NULL) - OBD_FREE(lsi->lsi_lmd->lmd_params, 4096); - if (lsi->lsi_lmd->lmd_nidnet != NULL) - OBD_FREE(lsi->lsi_lmd->lmd_nidnet, - strlen(lsi->lsi_lmd->lmd_nidnet) + 1); + OBD_FREE(lsi->lsi_lmd->lmd_mgs, + strlen(lsi->lsi_lmd->lmd_mgs) + 1); + OBD_FREE(lsi->lsi_lmd->lmd_osd_type, + strlen(lsi->lsi_lmd->lmd_osd_type) + 1); + OBD_FREE(lsi->lsi_lmd->lmd_params, 4096); + OBD_FREE(lsi->lsi_lmd->lmd_nidnet, + strlen(lsi->lsi_lmd->lmd_nidnet) + 1); OBD_FREE_PTR(lsi->lsi_lmd); } -- 1.8.3.1