Commit 79ac6ef5 authored by Rasmus Villemoes's avatar Rasmus Villemoes Committed by Steven Rostedt

tracing: Use kstrdup_const instead of private implementation

The kernel now has kstrdup_const/kfree_const for reusing .rodata
(typically string literals) when possible; there's no reason to
duplicate that logic in the tracing system. Moreover, as the comment
above core_kernel_data states, it may not always return true for
.rodata - that is for example the case on x86_64, where we thus end up
kstrdup'ing all the passed-in strings.

Arguably, testing for .rodata explicitly (as kstrdup_const does) is
also more correct: I don't think one is supposed to be able to change
the name after creating the event_subsystem by passing the address of
a static char (but non-const) array.

Link: http://lkml.kernel.org/r/1441833841-12955-1-git-send-email-linux@rasmusvillemoes.dkSigned-off-by: default avatarRasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: default avatarSteven Rostedt <rostedt@goodmis.org>
parent 37aea98b
...@@ -38,21 +38,19 @@ static LIST_HEAD(ftrace_common_fields); ...@@ -38,21 +38,19 @@ static LIST_HEAD(ftrace_common_fields);
static struct kmem_cache *field_cachep; static struct kmem_cache *field_cachep;
static struct kmem_cache *file_cachep; static struct kmem_cache *file_cachep;
#define SYSTEM_FL_FREE_NAME (1 << 31)
static inline int system_refcount(struct event_subsystem *system) static inline int system_refcount(struct event_subsystem *system)
{ {
return system->ref_count & ~SYSTEM_FL_FREE_NAME; return system->ref_count;
} }
static int system_refcount_inc(struct event_subsystem *system) static int system_refcount_inc(struct event_subsystem *system)
{ {
return (system->ref_count++) & ~SYSTEM_FL_FREE_NAME; return system->ref_count++;
} }
static int system_refcount_dec(struct event_subsystem *system) static int system_refcount_dec(struct event_subsystem *system)
{ {
return (--system->ref_count) & ~SYSTEM_FL_FREE_NAME; return --system->ref_count;
} }
/* Double loops, do not use break, only goto's work */ /* Double loops, do not use break, only goto's work */
...@@ -461,8 +459,7 @@ static void __put_system(struct event_subsystem *system) ...@@ -461,8 +459,7 @@ static void __put_system(struct event_subsystem *system)
kfree(filter->filter_string); kfree(filter->filter_string);
kfree(filter); kfree(filter);
} }
if (system->ref_count & SYSTEM_FL_FREE_NAME) kfree_const(system->name);
kfree(system->name);
kfree(system); kfree(system);
} }
...@@ -1493,13 +1490,9 @@ create_new_subsystem(const char *name) ...@@ -1493,13 +1490,9 @@ create_new_subsystem(const char *name)
system->ref_count = 1; system->ref_count = 1;
/* Only allocate if dynamic (kprobes and modules) */ /* Only allocate if dynamic (kprobes and modules) */
if (!core_kernel_data((unsigned long)name)) { system->name = kstrdup_const(name, GFP_KERNEL);
system->ref_count |= SYSTEM_FL_FREE_NAME;
system->name = kstrdup(name, GFP_KERNEL);
if (!system->name) if (!system->name)
goto out_free; goto out_free;
} else
system->name = name;
system->filter = NULL; system->filter = NULL;
...@@ -1512,8 +1505,7 @@ create_new_subsystem(const char *name) ...@@ -1512,8 +1505,7 @@ create_new_subsystem(const char *name)
return system; return system;
out_free: out_free:
if (system->ref_count & SYSTEM_FL_FREE_NAME) kfree_const(system->name);
kfree(system->name);
kfree(system); kfree(system);
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment