Whamcloud - gitweb
LU-18141 ptlrpc: don't check for NULL before free'ing 46/56046/2
authorTimothy Day <timday@amazon.com>
Wed, 14 Aug 2024 05:01:44 +0000 (01:01 -0400)
committerOleg Drokin <green@whamcloud.com>
Fri, 23 Aug 2024 22:08:17 +0000 (22:08 +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: Ia436882262a14fda2486b36999c2189f976b047a
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/56046
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: jsimmons <jsimmons@infradead.org>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/ptlrpc/lproc_ptlrpc.c
lustre/ptlrpc/nrs_tbf.c
lustre/ptlrpc/sec_plain.c

index a7d8db3..e763e50 100644 (file)
@@ -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 *
index 23bcc52..ccbcdf7 100644 (file)
@@ -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 = {
index 8b7dc45..492d795 100644 (file)
@@ -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;