Whamcloud - gitweb
LU-18141 llite: don't check for NULL before free'ing 41/56041/2
authorTimothy Day <timday@amazon.com>
Wed, 14 Aug 2024 04:55:45 +0000 (00:55 -0400)
committerOleg Drokin <green@whamcloud.com>
Fri, 23 Aug 2024 22:07:23 +0000 (22:07 +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: I0a476b17986b9346f07c2f854bb6b60f0f251c87
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56041
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
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>
lustre/llite/crypto.c
lustre/llite/dir.c
lustre/llite/file.c
lustre/llite/llite_foreign_symlink.c
lustre/llite/llite_lib.c
lustre/llite/namei.c
lustre/llite/pcc.c

index 3b295ce..1bb45ce 100644 (file)
@@ -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
index a851d11..5155f59 100644 (file)
@@ -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: {
index 7ede81f..ca8e86a 100644 (file)
@@ -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);
 }
index e5d28cf..66377ad 100644 (file)
@@ -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;
 }
index e6e2851..403354b 100644 (file)
@@ -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);
index 4d74d5a..1724909 100644 (file)
@@ -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)
index 32cfd90..64e28ba 100644 (file)
@@ -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);
        }
 }