Whamcloud - gitweb
LU-18141 target: don't check for NULL before free'ing 33/56033/2
authorTimothy Day <timday@amazon.com>
Wed, 14 Aug 2024 04:54:24 +0000 (00:54 -0400)
committerOleg Drokin <green@whamcloud.com>
Fri, 23 Aug 2024 22:07:05 +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: Ifbdc95bf18855892afa4e066b654da62cdee5e13
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56033
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/target/out_handler.c
lustre/target/out_lib.c
lustre/target/tgt_lastrcvd.c
lustre/target/tgt_main.c
lustre/target/tgt_mount.c
lustre/target/update_records.c

index 7958a0d..0faff1c 100644 (file)
@@ -1232,8 +1232,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);
index 69074f8..47a259f 100644 (file)
@@ -463,8 +463,7 @@ static int tx_extend_args(struct thandle_exec_args *ta, int new_alloc_ta)
 out:
        if (rc != 0) {
                for (i = 0; i < new_alloc_ta; i++) {
-                       if (new_ta[i] != NULL)
-                               OBD_FREE_PTR(new_ta[i]);
+                       OBD_FREE_PTR(new_ta[i]);
                }
                OBD_FREE_PTR_ARRAY(new_ta, new_alloc_ta);
        }
index a4f0d71..f08abf0 100644 (file)
@@ -2311,8 +2311,7 @@ int tgt_reply_data_init(const struct lu_env *env, struct lu_target *tgt)
 out:
        if (hash != NULL)
                cfs_hash_putref(hash);
-       if (trd != NULL)
-               OBD_FREE_PTR(trd);
+       OBD_FREE_PTR(trd);
        return rc;
 }
 
index 079496d..087598f 100644 (file)
@@ -635,8 +635,7 @@ out_put:
                dt_object_put(env, lut->lut_last_rcvd);
                lut->lut_last_rcvd = NULL;
        }
-       if (lut->lut_client_bitmap != NULL)
-               OBD_FREE(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3);
+       OBD_FREE(lut->lut_client_bitmap, LR_MAX_CLIENTS >> 3);
        lut->lut_client_bitmap = NULL;
        if (lut->lut_reply_data != NULL)
                dt_object_put(env, lut->lut_reply_data);
@@ -752,8 +751,7 @@ static void tgt_key_fini(const struct lu_context *ctx,
        int                             i;
 
        for (i = 0; i < args->ta_alloc_args; i++) {
-               if (args->ta_args[i] != NULL)
-                       OBD_FREE_PTR(args->ta_args[i]);
+               OBD_FREE_PTR(args->ta_args[i]);
        }
 
        if (args->ta_args != NULL)
index 0ca65ed..beefbbf 100644 (file)
@@ -376,8 +376,7 @@ int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, u32 idx)
        GOTO(cleanup, rc = 0);
 
 cleanup:
-       if (fsname != NULL)
-               OBD_FREE(fsname, MTI_NAME_MAXLEN);
+       OBD_FREE(fsname, MTI_NAME_MAXLEN);
 
        return rc;
 }
@@ -619,10 +618,8 @@ static int lustre_lwp_connect(struct obd_device *lwp, bool is_mdt)
        GOTO(out, rc);
 
 out:
-       if (data != NULL)
-               OBD_FREE_PTR(data);
-       if (uuid != NULL)
-               OBD_FREE_PTR(uuid);
+       OBD_FREE_PTR(data);
+       OBD_FREE_PTR(uuid);
 
        lu_env_fini(&env);
        lu_context_exit(&session_ctx);
@@ -696,10 +693,8 @@ static int lustre_lwp_setup(struct lustre_cfg *lcfg, struct lustre_sb_info *lsi,
        list_add_tail(&obd->obd_lwp_list, &lsi->lsi_lwp_list);
        mutex_unlock(&lsi->lsi_lwp_mutex);
 out:
-       if (lwpname)
-               OBD_FREE(lwpname, MTI_NAME_MAXLEN);
-       if (lwpuuid)
-               OBD_FREE(lwpuuid, MTI_NAME_MAXLEN);
+       OBD_FREE(lwpname, MTI_NAME_MAXLEN);
+       OBD_FREE(lwpuuid, MTI_NAME_MAXLEN);
 
        return rc;
 }
@@ -774,15 +769,12 @@ static int lustre_lwp_add_conn(struct lustre_cfg *cfg,
        if (rc < 0)
                CERROR("%s: can't add conn: rc = %d\n", lwpname, rc);
 
-       if (lcfg)
-               OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount,
-                                             lcfg->lcfg_buflens));
+       OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount,
+                                     lcfg->lcfg_buflens));
 out_cfg:
-       if (bufs)
-               OBD_FREE_PTR(bufs);
+       OBD_FREE_PTR(bufs);
 out:
-       if (lwpname)
-               OBD_FREE(lwpname, MTI_NAME_MAXLEN);
+       OBD_FREE(lwpname, MTI_NAME_MAXLEN);
        RETURN(rc);
 }
 
@@ -1019,12 +1011,9 @@ static int lustre_disconnect_lwp(struct super_block *sb)
        GOTO(out, rc);
 
 out:
-       if (bufs)
-               OBD_FREE_PTR(bufs);
-       if (cfg)
-               OBD_FREE_PTR(cfg);
-       if (logname)
-               OBD_FREE(logname, MTI_NAME_MAXLEN);
+       OBD_FREE_PTR(bufs);
+       OBD_FREE_PTR(cfg);
+       OBD_FREE(logname, MTI_NAME_MAXLEN);
 
        return rc1 != 0 ? rc1 : rc;
 }
@@ -1101,8 +1090,7 @@ static int lustre_start_lwp(struct super_block *sb)
 
 out:
        OBD_FREE(logname, MTI_NAME_MAXLEN);
-       if (cfg)
-               OBD_FREE_PTR(cfg);
+       OBD_FREE_PTR(cfg);
 
        return rc;
 }
index 7184a9e..eddf1f1 100644 (file)
@@ -1195,8 +1195,7 @@ static void update_key_fini(const struct lu_context *ctx,
        int                       i;
 
        for (i = 0; i < args->ta_alloc_args; i++) {
-               if (args->ta_args[i] != NULL)
-                       OBD_FREE_PTR(args->ta_args[i]);
+               OBD_FREE_PTR(args->ta_args[i]);
        }
 
        if (args->ta_args != NULL)