Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2444AC7EE43 for ; Sun, 11 Jun 2023 15:51:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1Trv4wiB8nJBRaAwxqVc9NrpHKdlbw9OTBKo6AiuIIo=; b=WrhKXS/gnFBddv K+uv7uwjHK3wExRm0HKOqks/yvTGIUjzUqP8YZJahQDLv4kam+Hcxa7cPSlViNcK8iE9b/0ZhdwUp MShNrveyjrB6WyI1SMs/3X5FlLEnGqDItB0yW22Ph39CbKQEjHaoXBkk9aZ5LH/HC420nobRNj5ob AxZTxw+6BObpsrOBTFW8kay/pTqRLtoITKD28SNiuiu7cYw3WAjgJ8Yusji6owX3c/7qPLNhcI9sW Bsvig54xLROIvrNo2D9pxwVohzTTXfCuV5hlmeDJT5UtuJMy5bAleKVUw/haKsZWe+nBCrG7HxSHx 0qcOIK/O4QbkyDVqcw0g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q8NLg-001GRU-2Q; Sun, 11 Jun 2023 15:51:24 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q8NLe-001GQC-2K for linux-snps-arc@lists.infradead.org; Sun, 11 Jun 2023 15:51:24 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 460BF61C0C; Sun, 11 Jun 2023 15:51:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47AFEC4339C; Sun, 11 Jun 2023 15:51:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686498681; bh=E2k80plMQU9lxqznYfeCXHA3QRFfPyTWCxD7fNNPT3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mG9E/aHBS0eMy3ZsbprrDjpHlYaDbUKHEQviwBu2Hg5yVwCTAoWKfjRP/Vovu1p1J N5ES4fuwwSyGZHD3CXqlwukVBnIYMZOaUbQU4s669I0T8pIPaJXRDrxP+tWP/3FMgC 05TPxX24TJW0eSUeLP2vGAeXAv8BWweK4SZWZzZdLDUTY4Y6z1QHEQAzN10xbAeeRk lXLk440Cx8hXVduSWOCasAYu00bPI9KzpCOWLAalWAeoFReA77z6Pc5etabr9uwpe1 aWl4ZBhSAPVngEfVnBMdEWJ0z0LKG8wn7LWTjb/Rq1dWx59bBaVw371EcJ1OhBW//W s4mJgEozN6KGQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-snps-arc@lists.infradead.org, Masahiro Yamada Subject: [PATCH v9 07/11] modpost: use null string instead of NULL pointer for default namespace Date: Mon, 12 Jun 2023 00:50:56 +0900 Message-Id: <20230611155100.2553804-8-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230611155100.2553804-1-masahiroy@kernel.org> References: <20230611155100.2553804-1-masahiroy@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230611_085122_842916_725D0F3A X-CRM114-Status: GOOD ( 14.96 ) X-BeenThere: linux-snps-arc@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux on Synopsys ARC Processors List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-snps-arc" Errors-To: linux-snps-arc-bounces+linux-snps-arc=archiver.kernel.org@lists.infradead.org The default namespace is the null string, "". When set, the null string "" is converted to NULL: s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL; When printed, the NULL pointer is get back to the null string: sym->namespace ?: "" This saves 1 byte memory allocated for "", but loses the readability. In kernel-space, we strive to save memory, but modpost is a userspace tool used to build the kernel. On modern systems, such small piece of memory is not a big deal. Handle the namespace string as is. Signed-off-by: Masahiro Yamada Reviewed-by: Nick Desaulniers --- scripts/mod/modpost.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 79ad0a346a5c..051ff67875ec 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -300,6 +300,13 @@ static bool contains_namespace(struct list_head *head, const char *namespace) { struct namespace_list *list; + /* + * The default namespace is null string "", which is always implicitly + * contained. + */ + if (!namespace[0]) + return true; + list_for_each_entry(list, head, list) { if (!strcmp(list->namespace, namespace)) return true; @@ -369,7 +376,7 @@ static struct symbol *sym_add_exported(const char *name, struct module *mod, s = alloc_symbol(name); s->module = mod; s->is_gpl_only = gpl_only; - s->namespace = namespace[0] ? NOFAIL(strdup(namespace)) : NULL; + s->namespace = NOFAIL(strdup(namespace)); list_add_tail(&s->list, &mod->exported_symbols); hash_add_symbol(s); @@ -1829,8 +1836,7 @@ static void check_exports(struct module *mod) else basename = mod->name; - if (exp->namespace && - !contains_namespace(&mod->imported_namespaces, exp->namespace)) { + if (!contains_namespace(&mod->imported_namespaces, exp->namespace)) { modpost_log(allow_missing_ns_imports ? LOG_WARN : LOG_ERROR, "module %s uses symbol %s from namespace %s, but does not import it.\n", basename, exp->name, exp->namespace); @@ -1916,8 +1922,7 @@ static void add_exported_symbols(struct buffer *buf, struct module *mod) list_for_each_entry(sym, &mod->exported_symbols, list) buf_printf(buf, "KSYMTAB_%s(%s, \"%s\", \"%s\");\n", sym->is_func ? "FUNC" : "DATA", sym->name, - sym->is_gpl_only ? "_gpl" : "", - sym->namespace ?: ""); + sym->is_gpl_only ? "_gpl" : "", sym->namespace); if (!modversions) return; @@ -2185,7 +2190,7 @@ static void write_dump(const char *fname) buf_printf(&buf, "0x%08x\t%s\t%s\tEXPORT_SYMBOL%s\t%s\n", sym->crc, sym->name, mod->name, sym->is_gpl_only ? "_GPL" : "", - sym->namespace ?: ""); + sym->namespace); } } write_buf(&buf, fname); -- 2.39.2 _______________________________________________ linux-snps-arc mailing list linux-snps-arc@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-snps-arc