From 116907709054af605a473c9f0231d3151a8cb69f Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Wed, 14 Aug 2024 00:55:45 -0400 Subject: [PATCH] LU-18141 llite: 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: I0a476b17986b9346f07c2f854bb6b60f0f251c87 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56041 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: jsimmons Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin --- lustre/llite/crypto.c | 3 +-- lustre/llite/dir.c | 3 +-- lustre/llite/file.c | 15 +++++---------- lustre/llite/llite_foreign_symlink.c | 3 +-- lustre/llite/llite_lib.c | 27 +++++++++------------------ lustre/llite/namei.c | 9 +++------ lustre/llite/pcc.c | 5 ++--- 7 files changed, 22 insertions(+), 43 deletions(-) diff --git a/lustre/llite/crypto.c b/lustre/llite/crypto.c index 3b295ce..1bb45ce 100644 --- a/lustre/llite/crypto.c +++ b/lustre/llite/crypto.c @@ -148,8 +148,7 @@ int ll_file_open_encrypt(struct inode *inode, struct file *filp) void llcrypt_free_ctx(void *encctx, __u32 size) { - if (encctx) - OBD_FREE(encctx, size); + OBD_FREE(encctx, size); } #ifdef HAVE_FSCRYPT_DUMMY_CONTEXT_ENABLED diff --git a/lustre/llite/dir.c b/lustre/llite/dir.c index a851d11..5155f59 100644 --- a/lustre/llite/dir.c +++ b/lustre/llite/dir.c @@ -2113,8 +2113,7 @@ lmv_out_free: /* in v1 and v3 cases lumv1 points to data */ rc = ll_dir_setstripe(inode, lumv1_ptr, set_default); out: - if (lumv3) - OBD_FREE(lumv3, lum_size); + OBD_FREE(lumv3, lum_size); RETURN(rc); } case LL_IOC_LMV_GETSTRIPE: { diff --git a/lustre/llite/file.c b/lustre/llite/file.c index 7ede81f..ca8e86a 100644 --- a/lustre/llite/file.c +++ b/lustre/llite/file.c @@ -1311,8 +1311,7 @@ out_close: out_release_it: ll_intent_release(&it); out: - if (och != NULL) - OBD_FREE_PTR(och); + OBD_FREE_PTR(och); RETURN(ERR_PTR(rc)); } @@ -1377,8 +1376,7 @@ static int ll_swap_layouts_close(struct obd_client_handle *och, och = NULL; /* freed in ll_close_inode_openhandle() */ out_free_och: - if (och != NULL) - OBD_FREE_PTR(och); + OBD_FREE_PTR(och); RETURN(rc); } @@ -3639,8 +3637,7 @@ putgl: } free: - if (llss != NULL) - OBD_FREE_PTR(llss); + OBD_FREE_PTR(llss); RETURN(rc); } @@ -3733,11 +3730,9 @@ static int ll_hsm_import(struct inode *inode, struct file *file, inode_unlock(inode); out: - if (hss != NULL) - OBD_FREE_PTR(hss); + OBD_FREE_PTR(hss); - if (attr != NULL) - OBD_FREE_PTR(attr); + OBD_FREE_PTR(attr); RETURN(rc); } diff --git a/lustre/llite/llite_foreign_symlink.c b/lustre/llite/llite_foreign_symlink.c index e5d28cf..66377ad 100644 --- a/lustre/llite/llite_foreign_symlink.c +++ b/lustre/llite/llite_foreign_symlink.c @@ -544,8 +544,7 @@ ssize_t foreign_symlink_prefix_store(struct kobject *kobj, sbi->ll_foreign_symlink_prefix_size = new_len + 1; up_write(&sbi->ll_foreign_symlink_sem); - if (old) - OBD_FREE(old, old_len); + OBD_FREE(old, old_len); return new_len; } diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index e6e2851..403354b 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -236,8 +236,7 @@ static struct ll_sb_info *ll_init_sbi(struct lustre_sb_info *lsi) INIT_LIST_HEAD(&sbi->ll_all_quota_list); RETURN(sbi); out_destroy_ra: - if (sbi->ll_foreign_symlink_prefix) - OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/")); + OBD_FREE(sbi->ll_foreign_symlink_prefix, sizeof("/mnt/")); if (sbi->ll_cache) { cl_cache_decref(sbi->ll_cache); sbi->ll_cache = NULL; @@ -826,10 +825,8 @@ retry_connect: if (uuid != NULL) sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid)); - if (data != NULL) - OBD_FREE_PTR(data); - if (osfs != NULL) - OBD_FREE_PTR(osfs); + OBD_FREE_PTR(data); + OBD_FREE_PTR(osfs); if (sbi->ll_dt_obd) { err = sysfs_create_link(&sbi->ll_kset.kobj, @@ -869,10 +866,8 @@ out_md: sbi->ll_md_exp = NULL; sbi->ll_md_obd = NULL; out: - if (data != NULL) - OBD_FREE_PTR(data); - if (osfs != NULL) - OBD_FREE_PTR(osfs); + OBD_FREE_PTR(data); + OBD_FREE_PTR(osfs); return err; } @@ -1234,8 +1229,7 @@ static int ll_options(char *options, struct super_block *sb) OBD_ALLOC_POST(sbi->ll_foreign_symlink_prefix, sbi->ll_foreign_symlink_prefix_size, "kmalloced"); - if (old) - OBD_FREE(old, old_len); + OBD_FREE(old, old_len); /* enable foreign symlink support */ set_bit(token, sbi->ll_flags); @@ -1497,11 +1491,9 @@ int ll_fill_super(struct super_block *sb) sbi->ll_client_common_fill_super_succeeded = 1; out_free_md: - if (md) - OBD_FREE(md, md_len); + OBD_FREE(md, md_len); out_free_dt: - if (dt) - OBD_FREE(dt, dt_len); + OBD_FREE(dt, dt_len); out_profile: if (lprof) class_put_profile(lprof); @@ -1509,8 +1501,7 @@ out_debugfs: if (err < 0) ll_debugfs_unregister_super(sb); out_free_cfg: - if (cfg) - OBD_FREE_PTR(cfg); + OBD_FREE_PTR(cfg); if (err) ll_put_super(sb); diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index 4d74d5a..1724909 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -1103,8 +1103,7 @@ out: ll_finish_md_op_data(op_data); } - if (lum != NULL) - OBD_FREE_PTR(lum); + OBD_FREE_PTR(lum); ptlrpc_req_put(req); return retval; @@ -1894,8 +1893,7 @@ err_exit: ptlrpc_req_put(request); if (!IS_ERR_OR_NULL(op_data)) ll_finish_md_op_data(op_data); - if (lum) - OBD_FREE_PTR(lum); + OBD_FREE_PTR(lum); RETURN(err); } @@ -2133,8 +2131,7 @@ out_fini: ll_finish_md_op_data(op_data); ll_intent_release(&mkdir_it); ptlrpc_req_put(request); - if (lum) - OBD_FREE_PTR(lum); + OBD_FREE_PTR(lum); out_tally: if (rc == 0) diff --git a/lustre/llite/pcc.c b/lustre/llite/pcc.c index 32cfd90..64e28ba 100644 --- a/lustre/llite/pcc.c +++ b/lustre/llite/pcc.c @@ -225,9 +225,8 @@ static void pcc_cmd_fini(struct pcc_cmd *cmd) if (cmd->pccc_cmd == PCC_ADD_DATASET) { if (!list_empty(&cmd->u.pccc_add.pccc_conds)) pcc_rule_conds_free(&cmd->u.pccc_add.pccc_conds); - if (cmd->u.pccc_add.pccc_conds_str) - OBD_FREE(cmd->u.pccc_add.pccc_conds_str, - strlen(cmd->u.pccc_add.pccc_conds_str) + 1); + OBD_FREE(cmd->u.pccc_add.pccc_conds_str, + strlen(cmd->u.pccc_add.pccc_conds_str) + 1); } } -- 1.8.3.1