Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1938924rwd; Sun, 21 May 2023 09:13:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7DsY9SzoLBhfu2vf1Z4XnfZomgFbClst4I8tDMocELfsjflaVcH00KVclkhjSvKBPtKX+k X-Received: by 2002:a17:902:6bc2:b0:1ae:6e7b:9bb4 with SMTP id m2-20020a1709026bc200b001ae6e7b9bb4mr7740573plt.59.1684685618752; Sun, 21 May 2023 09:13:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684685618; cv=none; d=google.com; s=arc-20160816; b=wlCyoQ6JxFiZjY/t1B+YgqQ6RSTBBkOz8dW9UxIn0QmDuMJh8pZibyJO80XF9i78kW XZJgpkDHUlJgR2PwTesxgM4KCRaQWMz6jTtRQAXs0koQlut5a7EAkwzdO7WcJn0X9lMZ z8PUm78z0pyqDNZTlmTjS5S7vCADoOCJNQ51mof4fbzIdxslrbU57gN5ytA/OZLvl5nH ZxHBzbYL0dhmPOhixA1IbQyB1eQ4MM2mBmCYqSR/hIq6FMae2fcu05VaHKgh5h/NPfg3 Cekv+OI1FXyrRA8lxozxClFBodNMvXLC+XMp1x4oTyMQ1CsbxSXEV3hZVztxGRSWHhpr tB7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=n4ol6FosDDTEnon8jrKqux+bujlr2GHgCR3txKe5tmE=; b=c1D90xESq6oBif8mgzQZlbrPiy1TeIIwpkmsvUqBb1JtXcB78KLRtpSp6uZag+uzoB et1EQb3vS/8RCVBRYyzmYv8ptEW3ZtUKLKTjlNm6xu7PihBtFwiBA5Ftz4gpYiHGkNos E+OtPK2/yJ2L04vo/Clpk4BLSs8CXKC5n8SCMG7qHDRxLwPKzsh0CCQyGPrWuuOZr3u+ O5MF0AduJ+cB7dKPLqagMMbC5rW7Gz8D7n0bb94EJS7MuJ/Zvx3vRNttbDcZUQYwBNUD Ql5+ScOCNSryk39rZNm5pvJD9krRSxv7DSSyXnvIg5+KA6ma8MxeBmKw/xmUrs5M0a3V 01SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=daYmpNE8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h7-20020a170902f7c700b001ab23cb930bsi927961plw.417.2023.05.21.09.13.23; Sun, 21 May 2023 09:13:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=daYmpNE8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229999AbjEUQGZ (ORCPT + 99 others); Sun, 21 May 2023 12:06:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230317AbjEUQGE (ORCPT ); Sun, 21 May 2023 12:06:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0520EB; Sun, 21 May 2023 09:05:40 -0700 (PDT) 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 8FF6D60FE4; Sun, 21 May 2023 16:05:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A442DC433D2; Sun, 21 May 2023 16:05:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684685140; bh=u+zekrJ6wRjbNqFFVUdlRa3NbSgsRSQhW8QM+KPUZv0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=daYmpNE8SBeBg/ncLjgrQX9hXUf8/Lr9PN8CKnk4v3neIok3ZPyDUY7NzXonPybof XVD2vdCsX+X6tdAqTYYBCYcRpI7608VLhV8bXM3o9bqd4AIL9ori+mIyCRjAPshsOF krHNx/gPTeOSLWUOoRCVXDNOELmcK5E+xU4O4R48frBglEOg7GLuzqCyUW69jNGIyK RRTe7rqacylkQdPbhaiEcou9cBTuD0zppV77pqcbfK/Xp7yRUEi7Bcl8cyEpYY1It6 f8I+NxTFj0uDCP+YfceEEEQ6da6VicV8R+0cxV99ZJEa9J4sUUefuzpRoEeUmWiXqT oTgSCHXaobIoQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , Masahiro Yamada Subject: [PATCH v6 14/20] modpost: use null string instead of NULL pointer for default namespace Date: Mon, 22 May 2023 01:04:19 +0900 Message-Id: <20230521160426.1881124-15-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230521160426.1881124-1-masahiroy@kernel.org> References: <20230521160426.1881124-1-masahiroy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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. Reviewed-by: Nick Desaulniers Signed-off-by: Masahiro Yamada --- 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 8fe2aa7bf71b..f14fe9301ae6 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -298,6 +298,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; @@ -367,7 +374,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); @@ -1775,8 +1782,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); @@ -1862,8 +1868,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; @@ -2131,7 +2136,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