Skip to content

Commit

Permalink
dynamic_debug: don't duplicate modname in ddebug_add_module
Browse files Browse the repository at this point in the history
For built-in modules, we're already reusing the passed-in string via
kstrdup_const().  But for actual modules (i.e.  when we're called from
dynamic_debug_setup in module.c), the passed-in string (which points at
the name[] array inside struct module) is also guaranteed to live at
least as long as the struct ddebug_table, since free_module() calls
ddebug_remove_module().

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Rasmus Villemoes <[email protected]>
Acked-by: Jason Baron <[email protected]>
Cc: David Sterba <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Petr Mladek <[email protected]>
Cc: "Rafael J . Wysocki" <[email protected]>
Cc: Steven Rostedt <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Villemoes authored and torvalds committed Mar 8, 2019
1 parent 2bdde67 commit cdf6d00
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/dynamic_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,17 +847,17 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
const char *name)
{
struct ddebug_table *dt;
const char *new_name;

dt = kzalloc(sizeof(*dt), GFP_KERNEL);
if (dt == NULL)
return -ENOMEM;
new_name = kstrdup_const(name, GFP_KERNEL);
if (new_name == NULL) {
kfree(dt);
return -ENOMEM;
}
dt->mod_name = new_name;
/*
* For built-in modules, name lives in .rodata and is
* immortal. For loaded modules, name points at the name[]
* member of struct module, which lives at least as long as
* this struct ddebug_table.
*/
dt->mod_name = name;
dt->num_ddebugs = n;
dt->ddebugs = tab;

Expand Down Expand Up @@ -913,7 +913,6 @@ int ddebug_dyndbg_module_param_cb(char *param, char *val, const char *module)
static void ddebug_table_free(struct ddebug_table *dt)
{
list_del_init(&dt->link);
kfree_const(dt->mod_name);
kfree(dt);
}

Expand Down

0 comments on commit cdf6d00

Please sign in to comment.