From 4effc77c193dd15b9c440227838fbf3271456a72 Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Wed, 14 Aug 2024 01:07:11 -0400 Subject: [PATCH] LU-18141 misc: (for o*) 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: I6bc5893f9cdbe27eb25507cb214f1dac39f1feec Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56047 Reviewed-by: Andreas Dilger Reviewed-by: jsimmons Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- lustre/obdecho/echo_client.c | 9 +++------ lustre/ofd/ofd_dev.c | 3 +-- lustre/ofd/ofd_fs.c | 3 +-- lustre/ofd/ofd_lvb.c | 3 +-- lustre/osp/lwp_dev.c | 11 ++++------- lustre/osp/osp_dev.c | 6 ++---- lustre/osp/osp_precreate.c | 3 +-- lustre/osp/osp_sync.c | 3 +-- 8 files changed, 14 insertions(+), 27 deletions(-) diff --git a/lustre/obdecho/echo_client.c b/lustre/obdecho/echo_client.c index 6674409..b8aec12 100644 --- a/lustre/obdecho/echo_client.c +++ b/lustre/obdecho/echo_client.c @@ -305,8 +305,7 @@ static void echo_object_delete(const struct lu_env *env, struct lu_object *obj) list_del_init(&eco->eo_obj_chain); spin_unlock(&ec->ec_lock); - if (eco->eo_oinfo) - OBD_FREE_PTR(eco->eo_oinfo); + OBD_FREE_PTR(eco->eo_oinfo); } static void echo_object_free_rcu(struct rcu_head *head) @@ -958,8 +957,7 @@ cl_echo_object_find(struct echo_device *d, const struct ost_id *oi) } out: - if (oinfo) - OBD_FREE_PTR(oinfo); + OBD_FREE_PTR(oinfo); cl_env_put(env, &refcheck); RETURN(eco); @@ -1954,8 +1952,7 @@ static int echo_md_handler(struct echo_device *ed, int command, echo_ucred_fini(env); out_name: - if (name) - OBD_FREE(name, namelen + 1); + OBD_FREE(name, namelen + 1); out_put: lu_object_put(env, parent); out_free: diff --git a/lustre/ofd/ofd_dev.c b/lustre/ofd/ofd_dev.c index b8a43ac..1ed08f2 100644 --- a/lustre/ofd/ofd_dev.c +++ b/lustre/ofd/ofd_dev.c @@ -143,8 +143,7 @@ static int ofd_connect_to_next(const struct lu_env *env, struct ofd_device *m, m->ofd_dt_dev.dd_lu_dev.ld_site->ls_top_dev = &m->ofd_dt_dev.dd_lu_dev; out: - if (data) - OBD_FREE_PTR(data); + OBD_FREE_PTR(data); RETURN(rc); } diff --git a/lustre/ofd/ofd_fs.c b/lustre/ofd/ofd_fs.c index 2c2bea9..01c58b0 100644 --- a/lustre/ofd/ofd_fs.c +++ b/lustre/ofd/ofd_fs.c @@ -574,8 +574,7 @@ static int ofd_register_seq_exp(struct ofd_device *ofd) GOTO(out_free, rc); } out_free: - if (lwp_name != NULL) - OBD_FREE(lwp_name, MAX_OBD_NAME); + OBD_FREE(lwp_name, MAX_OBD_NAME); return rc; } diff --git a/lustre/ofd/ofd_lvb.c b/lustre/ofd/ofd_lvb.c index f220ded..d9237b9 100644 --- a/lustre/ofd/ofd_lvb.c +++ b/lustre/ofd/ofd_lvb.c @@ -60,8 +60,7 @@ */ static int ofd_lvbo_free(struct ldlm_resource *res) { - if (res->lr_lvb_data) - OBD_FREE(res->lr_lvb_data, res->lr_lvb_len); + OBD_FREE(res->lr_lvb_data, res->lr_lvb_len); return 0; } diff --git a/lustre/osp/lwp_dev.c b/lustre/osp/lwp_dev.c index 2101718..9cad19b 100644 --- a/lustre/osp/lwp_dev.c +++ b/lustre/osp/lwp_dev.c @@ -129,13 +129,10 @@ static int lwp_setup(const struct lu_env *env, struct lwp_device *lwp, imp = lwp->lpd_obd->u.cli.cl_import; rc = ptlrpc_init_import(imp); out: - if (bufs != NULL) - OBD_FREE_PTR(bufs); - if (server_uuid != NULL) - OBD_FREE(server_uuid, len); - if (lcfg) - OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, - lcfg->lcfg_buflens)); + OBD_FREE_PTR(bufs); + OBD_FREE(server_uuid, len); + OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, + lcfg->lcfg_buflens)); if (rc) client_obd_cleanup(lwp->lpd_obd); diff --git a/lustre/osp/osp_dev.c b/lustre/osp/osp_dev.c index f36f015..e6d4679 100644 --- a/lustre/osp/osp_dev.c +++ b/lustre/osp/osp_dev.c @@ -1281,8 +1281,7 @@ static int osp_init0(const struct lu_env *env, struct osp_device *osp, rc = ptlrpc_init_import(imp); if (rc) GOTO(out, rc); - if (osdname) - OBD_FREE(osdname, MAX_OBD_NAME); + OBD_FREE(osdname, MAX_OBD_NAME); init_waitqueue_head(&osp->opd_out_waitq); RETURN(0); @@ -1309,8 +1308,7 @@ out_ref: out_disconnect: obd_disconnect(osp->opd_storage_exp); out_fini: - if (osdname) - OBD_FREE(osdname, MAX_OBD_NAME); + OBD_FREE(osdname, MAX_OBD_NAME); RETURN(rc); } diff --git a/lustre/osp/osp_precreate.c b/lustre/osp/osp_precreate.c index 3c8b035..3ec180f 100644 --- a/lustre/osp/osp_precreate.c +++ b/lustre/osp/osp_precreate.c @@ -1757,8 +1757,7 @@ int osp_object_truncate(const struct lu_env *env, struct dt_object *dt, } out: ptlrpc_req_put(req); - if (oa) - OBD_FREE_PTR(oa); + OBD_FREE_PTR(oa); RETURN(rc); } diff --git a/lustre/osp/osp_sync.c b/lustre/osp/osp_sync.c index b941fea..d80c4c6 100644 --- a/lustre/osp/osp_sync.c +++ b/lustre/osp/osp_sync.c @@ -1721,8 +1721,7 @@ int osp_sync_init(const struct lu_env *env, struct osp_device *d) err_llog: osp_sync_llog_fini(env, d); err_id: - if (args) - OBD_FREE_PTR(args); + OBD_FREE_PTR(args); return rc; } -- 1.8.3.1