Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751911AbcCVUyJ (ORCPT ); Tue, 22 Mar 2016 16:54:09 -0400 Received: from ozlabs.org ([103.22.144.67]:46977 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751110AbcCVUyI (ORCPT ); Tue, 22 Mar 2016 16:54:08 -0400 From: Rusty Russell To: Rasmus Villemoes , Oleg Nesterov , Prarit Bhargava Cc: Andrew Morton , Rasmus Villemoes , linux-kernel@vger.kernel.org Subject: Re: [PATCH resend] init/main.c: Simplify initcall_blacklisted() In-Reply-To: <1458602066-15255-1-git-send-email-linux@rasmusvillemoes.dk> References: <54BEA0EE.10304@redhat.com> <1458602066-15255-1-git-send-email-linux@rasmusvillemoes.dk> User-Agent: Notmuch/0.20.2 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-pc-linux-gnu) Date: Tue, 22 Mar 2016 13:57:28 +1030 Message-ID: <87twjzkx9b.fsf@rustcorp.com.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1667 Lines: 55 Rasmus Villemoes writes: > 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 Acked-by: Rusty Russell Thanks! Rusty. > --- > init/main.c | 9 ++++----- > 1 file changed, 4 insertions(+), 5 deletions(-) > > diff --git a/init/main.c b/init/main.c > index b3c6e363ae18..d76d94cd537c 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -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 > -- > 2.1.4