Whamcloud - gitweb
LU-4423 ldlm: discard varname in ldlm_pool. 73/35273/3
authorNeilBrown <neilb@suse.com>
Thu, 20 Jun 2019 03:38:40 +0000 (23:38 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 27 Jun 2019 21:34:01 +0000 (21:34 +0000)
This allocated buffer serves no purpose.
A constant string is copied into it, it is passed to some
function which copies it out again, then the buffer is freed.
Instead, we can pass the constant string to that function.

Change-Id: I83ea8fc839da3933ebc34756fc5c06b86427ce7c
Signed-off-by: NeilBrown <neilb@suse.com>
Reviewed-on: https://review.whamcloud.com/35273
Tested-by: Jenkins
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Petros Koutoupis <pkoutoupis@cray.com>
lustre/ldlm/ldlm_internal.h
lustre/ldlm/ldlm_pool.c

index 136d9f5..3fac6fd 100644 (file)
@@ -30,8 +30,6 @@
  * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
  * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
-#define MAX_STRING_SIZE 128
-
 extern int ldlm_srv_namespace_nr;
 extern int ldlm_cli_namespace_nr;
 extern struct mutex ldlm_srv_namespace_lock;
 extern int ldlm_srv_namespace_nr;
 extern int ldlm_cli_namespace_nr;
 extern struct mutex ldlm_srv_namespace_lock;
@@ -346,7 +344,7 @@ static inline void
 ldlm_add_var(struct lprocfs_vars *vars, struct dentry *debugfs_entry,
             const char *name, void *data, const struct file_operations *ops)
 {
 ldlm_add_var(struct lprocfs_vars *vars, struct dentry *debugfs_entry,
             const char *name, void *data, const struct file_operations *ops)
 {
-       snprintf((char *)vars->name, MAX_STRING_SIZE, "%s", name);
+       vars->name = name;
        vars->data = data;
        vars->fops = ops;
        ldebugfs_add_vars(debugfs_entry, vars, NULL);
        vars->data = data;
        vars->fops = ops;
        ldebugfs_add_vars(debugfs_entry, vars, NULL);
index 3e74a40..9d47ac6 100644 (file)
@@ -789,20 +789,15 @@ static int ldlm_pool_debugfs_init(struct ldlm_pool *pl)
        struct ldlm_namespace *ns = ldlm_pl2ns(pl);
        struct dentry *debugfs_ns_parent;
        struct lprocfs_vars pool_vars[2];
        struct ldlm_namespace *ns = ldlm_pl2ns(pl);
        struct dentry *debugfs_ns_parent;
        struct lprocfs_vars pool_vars[2];
-       char *var_name = NULL;
        int rc = 0;
 
        ENTRY;
 
        int rc = 0;
 
        ENTRY;
 
-       OBD_ALLOC(var_name, MAX_STRING_SIZE + 1);
-       if (!var_name)
-               RETURN(-ENOMEM);
-
        debugfs_ns_parent = ns->ns_debugfs_entry;
        if (IS_ERR_OR_NULL(debugfs_ns_parent)) {
                CERROR("%s: debugfs entry is not initialized\n",
                       ldlm_ns_name(ns));
        debugfs_ns_parent = ns->ns_debugfs_entry;
        if (IS_ERR_OR_NULL(debugfs_ns_parent)) {
                CERROR("%s: debugfs entry is not initialized\n",
                       ldlm_ns_name(ns));
-               GOTO(out_free_name, rc = -EINVAL);
+               GOTO(out, rc = -EINVAL);
        }
        pl->pl_debugfs_entry = ldebugfs_register("pool", debugfs_ns_parent,
                                                 NULL, NULL);
        }
        pl->pl_debugfs_entry = ldebugfs_register("pool", debugfs_ns_parent,
                                                 NULL, NULL);
@@ -811,12 +806,10 @@ static int ldlm_pool_debugfs_init(struct ldlm_pool *pl)
                pl->pl_debugfs_entry = NULL;
                CERROR("%s: cannot create 'pool' debugfs entry: rc = %d\n",
                       ldlm_ns_name(ns), rc);
                pl->pl_debugfs_entry = NULL;
                CERROR("%s: cannot create 'pool' debugfs entry: rc = %d\n",
                       ldlm_ns_name(ns), rc);
-               GOTO(out_free_name, rc);
+               GOTO(out, rc);
        }
 
        }
 
-       var_name[MAX_STRING_SIZE] = '\0';
        memset(pool_vars, 0, sizeof(pool_vars));
        memset(pool_vars, 0, sizeof(pool_vars));
-       pool_vars[0].name = var_name;
 
        ldlm_add_var(&pool_vars[0], pl->pl_debugfs_entry, "state", pl,
                     &lprocfs_pool_state_fops);
 
        ldlm_add_var(&pool_vars[0], pl->pl_debugfs_entry, "state", pl,
                     &lprocfs_pool_state_fops);
@@ -824,7 +817,7 @@ static int ldlm_pool_debugfs_init(struct ldlm_pool *pl)
        pl->pl_stats = lprocfs_alloc_stats(LDLM_POOL_LAST_STAT -
                                           LDLM_POOL_FIRST_STAT, 0);
        if (!pl->pl_stats)
        pl->pl_stats = lprocfs_alloc_stats(LDLM_POOL_LAST_STAT -
                                           LDLM_POOL_FIRST_STAT, 0);
        if (!pl->pl_stats)
-               GOTO(out_free_name, rc = -ENOMEM);
+               GOTO(out, rc = -ENOMEM);
 
        lprocfs_counter_init(pl->pl_stats, LDLM_POOL_GRANTED_STAT,
                             LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV,
 
        lprocfs_counter_init(pl->pl_stats, LDLM_POOL_GRANTED_STAT,
                             LPROCFS_CNTR_AVGMINMAX | LPROCFS_CNTR_STDDEV,
@@ -863,8 +856,7 @@ static int ldlm_pool_debugfs_init(struct ldlm_pool *pl)
                                     pl->pl_stats);
 
        EXIT;
                                     pl->pl_stats);
 
        EXIT;
-out_free_name:
-       OBD_FREE(var_name, MAX_STRING_SIZE + 1);
+out:
        return rc;
 }
 
        return rc;
 }