Whamcloud - gitweb
LU-18141 obdclass: don't check for NULL before free'ing 42/56042/3
authorTimothy Day <timday@amazon.com>
Wed, 14 Aug 2024 04:56:29 +0000 (00:56 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 12 Sep 2024 05:52:59 +0000 (05:52 +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: Ie5d5567fecc1f421fb0894816c880b41ea93843b
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56042
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/obdclass/llog_osd.c
lustre/obdclass/lprocfs_status_server.c
lustre/obdclass/lu_tgt_descs.c
lustre/obdclass/obd_config.c
lustre/obdclass/obd_mount.c

index 4720eb6..76bd90d 100644 (file)
@@ -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);
 }
index e374e3c..c657f90 100644 (file)
@@ -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;
index 0062ded..208d3c4 100644 (file)
@@ -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;
 }
index 74d55e2..c3379a7 100644 (file)
@@ -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:
index 9f53c90..d117eaa 100644 (file)
@@ -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);
        }