Skip to content

Commit

Permalink
init/main.c: simplify initcall_blacklisted()
Browse files Browse the repository at this point in the history
Using kasprintf to get the function name makes us look up the name
twice, along with all the vsnprintf overhead of parsing the format
string etc.  It also means there is an allocation failure case to deal
with.  Since symbol_string in vsprintf.c would anyway allocate an array
of size KSYM_SYMBOL_LEN on the stack, that might as well be done up
here.

Moreover, since this is a debug feature and the blacklisted_initcalls
list is usually empty, we might as well test that and thus avoid looking
up the symbol name even once in the common case.

Signed-off-by: Rasmus Villemoes <[email protected]>
Acked-by: Rusty Russell <[email protected]>
Acked-by: Prarit Bhargava <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Villemoes authored and torvalds committed May 21, 2016
1 parent 4108124 commit c8cdd2b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions init/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,21 +706,20 @@ static int __init initcall_blacklist(char *str)
static bool __init_or_module initcall_blacklisted(initcall_t fn)
{
struct blacklist_entry *entry;
char *fn_name;
char fn_name[KSYM_SYMBOL_LEN];

fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
if (!fn_name)
if (list_empty(&blacklisted_initcalls))
return false;

sprint_symbol_no_offset(fn_name, (unsigned long)fn);

list_for_each_entry(entry, &blacklisted_initcalls, next) {
if (!strcmp(fn_name, entry->buf)) {
pr_debug("initcall %s blacklisted\n", fn_name);
kfree(fn_name);
return true;
}
}

kfree(fn_name);
return false;
}
#else
Expand Down

0 comments on commit c8cdd2b

Please sign in to comment.