From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751435AbcCXRQT (ORCPT ); Thu, 24 Mar 2016 13:16:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46856 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750732AbcCXRQM (ORCPT ); Thu, 24 Mar 2016 13:16:12 -0400 Message-ID: <56F420DA.7040302@redhat.com> Date: Thu, 24 Mar 2016 13:16:10 -0400 From: Prarit Bhargava User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Rasmus Villemoes , Oleg Nesterov , Rusty Russell CC: Andrew Morton , linux-kernel@vger.kernel.org Subject: Re: [PATCH resend] init/main.c: Simplify initcall_blacklisted() References: <54BEA0EE.10304@redhat.com> <1458602066-15255-1-git-send-email-linux@rasmusvillemoes.dk> In-Reply-To: <1458602066-15255-1-git-send-email-linux@rasmusvillemoes.dk> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 24 Mar 2016 17:16:11 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/21/2016 07:14 PM, Rasmus Villemoes wrote: > 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: Prarit Bhargava P. > --- > 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 >