From 307f98e21fdcb376585f8db76e4d3727f1fa7a1a Mon Sep 17 00:00:00 2001 From: Timothy Day Date: Wed, 14 Aug 2024 01:01:44 -0400 Subject: [PATCH] LU-18141 ptlrpc: 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: Ia436882262a14fda2486b36999c2189f976b047a Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56046 Tested-by: jenkins Tested-by: Maloo Reviewed-by: jsimmons Reviewed-by: Arshad Hussain Reviewed-by: Oleg Drokin --- lustre/ptlrpc/lproc_ptlrpc.c | 6 ++---- lustre/ptlrpc/nrs_tbf.c | 28 +++++++++++----------------- lustre/ptlrpc/sec_plain.c | 3 +-- 3 files changed, 14 insertions(+), 23 deletions(-) diff --git a/lustre/ptlrpc/lproc_ptlrpc.c b/lustre/ptlrpc/lproc_ptlrpc.c index a7d8db3..e763e50 100644 --- a/lustre/ptlrpc/lproc_ptlrpc.c +++ b/lustre/ptlrpc/lproc_ptlrpc.c @@ -800,8 +800,7 @@ default_queue: mutex_unlock(&nrs_core.nrs_mutex); out: - if (cmd_copy) - OBD_FREE(cmd_copy, LPROCFS_NRS_WR_MAX_CMD); + OBD_FREE(cmd_copy, LPROCFS_NRS_WR_MAX_CMD); RETURN(rc < 0 ? rc : count); } @@ -948,8 +947,7 @@ ptlrpc_lprocfs_svc_req_history_stop(struct seq_file *s, void *iter) { struct ptlrpc_srh_iterator *srhi = iter; - if (srhi != NULL) - OBD_FREE(srhi, sizeof(*srhi)); + OBD_FREE(srhi, sizeof(*srhi)); } static void * diff --git a/lustre/ptlrpc/nrs_tbf.c b/lustre/ptlrpc/nrs_tbf.c index 23bcc52..ccbcdf7 100644 --- a/lustre/ptlrpc/nrs_tbf.c +++ b/lustre/ptlrpc/nrs_tbf.c @@ -926,9 +926,8 @@ static void nrs_tbf_jobid_cmd_fini(struct nrs_tbf_cmd *cmd) { if (!list_empty(&cmd->u.tc_start.ts_jobids)) nrs_tbf_jobid_list_free(&cmd->u.tc_start.ts_jobids); - if (cmd->u.tc_start.ts_jobids_str) - OBD_FREE(cmd->u.tc_start.ts_jobids_str, - strlen(cmd->u.tc_start.ts_jobids_str) + 1); + OBD_FREE(cmd->u.tc_start.ts_jobids_str, + strlen(cmd->u.tc_start.ts_jobids_str) + 1); } static int nrs_tbf_check_id_value(char **strp, char *key) @@ -1248,9 +1247,8 @@ static void nrs_tbf_nid_cmd_fini(struct nrs_tbf_cmd *cmd) { if (!list_empty(&cmd->u.tc_start.ts_nids)) cfs_free_nidlist(&cmd->u.tc_start.ts_nids); - if (cmd->u.tc_start.ts_nids_str) - OBD_FREE(cmd->u.tc_start.ts_nids_str, - strlen(cmd->u.tc_start.ts_nids_str) + 1); + OBD_FREE(cmd->u.tc_start.ts_nids_str, + strlen(cmd->u.tc_start.ts_nids_str) + 1); } static int nrs_tbf_nid_parse(struct nrs_tbf_cmd *cmd, char *id) @@ -1827,9 +1825,8 @@ nrs_tbf_generic_cmd_fini(struct nrs_tbf_cmd *cmd) { if (!list_empty(&cmd->u.tc_start.ts_conds)) nrs_tbf_conds_free(&cmd->u.tc_start.ts_conds); - if (cmd->u.tc_start.ts_conds_str) - OBD_FREE(cmd->u.tc_start.ts_conds_str, - strlen(cmd->u.tc_start.ts_conds_str) + 1); + OBD_FREE(cmd->u.tc_start.ts_conds_str, + strlen(cmd->u.tc_start.ts_conds_str) + 1); } #define NRS_TBF_DISJUNCTION_DELIM (",") @@ -2280,9 +2277,8 @@ nrs_tbf_opcode_list_parse(char *orig, unsigned long **bitmaptr) static void nrs_tbf_opcode_cmd_fini(struct nrs_tbf_cmd *cmd) { - if (cmd->u.tc_start.ts_opcodes_str) - OBD_FREE(cmd->u.tc_start.ts_opcodes_str, - strlen(cmd->u.tc_start.ts_opcodes_str) + 1); + OBD_FREE(cmd->u.tc_start.ts_opcodes_str, + strlen(cmd->u.tc_start.ts_opcodes_str) + 1); } @@ -2543,9 +2539,8 @@ static void nrs_tbf_id_cmd_fini(struct nrs_tbf_cmd *cmd) { nrs_tbf_id_list_free(&cmd->u.tc_start.ts_ids); - if (cmd->u.tc_start.ts_ids_str) - OBD_FREE(cmd->u.tc_start.ts_ids_str, - strlen(cmd->u.tc_start.ts_ids_str) + 1); + OBD_FREE(cmd->u.tc_start.ts_ids_str, + strlen(cmd->u.tc_start.ts_ids_str) + 1); } static int @@ -2676,8 +2671,7 @@ nrs_tbf_id_rule_dump(struct nrs_tbf_rule *rule, struct seq_file *m) static void nrs_tbf_id_rule_fini(struct nrs_tbf_rule *rule) { nrs_tbf_id_list_free(&rule->tr_ids); - if (rule->tr_ids_str != NULL) - OBD_FREE(rule->tr_ids_str, strlen(rule->tr_ids_str) + 1); + OBD_FREE(rule->tr_ids_str, strlen(rule->tr_ids_str) + 1); } struct nrs_tbf_ops nrs_tbf_uid_ops = { diff --git a/lustre/ptlrpc/sec_plain.c b/lustre/ptlrpc/sec_plain.c index 8b7dc45..492d795 100644 --- a/lustre/ptlrpc/sec_plain.c +++ b/lustre/ptlrpc/sec_plain.c @@ -382,8 +382,7 @@ struct ptlrpc_cli_ctx *plain_sec_install_ctx(struct plain_sec *plsec) if (ctx) { atomic_inc(&ctx->cc_refcount); - if (ctx_new) - OBD_FREE_PTR(ctx_new); + OBD_FREE_PTR(ctx_new); } else if (ctx_new) { ctx = ctx_new; -- 1.8.3.1