Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp924492rwd; Sun, 14 May 2023 08:59:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4QZT2CgaXXwClrIRzuzX9Wgl+ofTF/6EBhk+eCuZtjbWyYHGZTnDMUDIZMVWpmIRAgUIVe X-Received: by 2002:a05:6a20:6a0e:b0:ff:f746:1044 with SMTP id p14-20020a056a206a0e00b000fff7461044mr33845508pzk.53.1684079951649; Sun, 14 May 2023 08:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684079951; cv=none; d=google.com; s=arc-20160816; b=iaznJlz06AEJfFxBf5H/fKJEgKzU6FSMPDuVNuUwMBs+Ezp39PlN0GideLNq3NFoJY 1VgIaR02b36dSSQcQVSXbQtuJX6VXEgLuWIyF5IXhKchAuwtyP4uCXS3B5idH1qk3SoX Syk2CWHCvYLfmlSe7NMG7qhG8R1GcHaMLpDSkeRBeMD/rYmErUTXcDTCYKC5LMaYLM5p lnt84IJfN1b/uEDk/+K+8umIfl2MkNqBPq+1ajZ9w7j6WtlAtyJAtfJhwevj/OaHc1n0 WIfGETe/FuM+uYCgIQx9w1LsXusfng8Nxay24ZL1Z1TkHg3qJB3WQhtBDjJD+rLZxXBo 6/NA== 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=D1I0UZv7Ut5PmqSNmyr3SKh/VpsZaM8dbn2+7G/tnJE=; b=FN5/NWUfmfXeqmr3nqhTS5m9HbXYJhPJuuX+GiVksOFAhDpb3K9OXLO5ZlowMI/nda Lf/jXHVC5vTklWX6vil0BtDt0ce5k45hKMX8bOVh4xxGCJNiKF5KX1zjwi5+x8jagpi8 KggRmvebASglS9j4WUz9jcfkLHiK9dJc0sycK/nJUil5OTH9KPU+ZrsjnFz9dGZoEl4T BZQVmGEzMtxfGy78mqa5WvDMVCn6K2iqzasZ7qxrd9EMcytRHQeSIiZlop4sGsAkCQWb aFqHjutVFUNOAIYVM05YnyCJBL0n+GBDKwVWrMaT/djQ1AvHwXO0RZwK5s72pOvgc+75 Ggpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TlMRQMZD; 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 l136-20020a633e8e000000b0052c40645e07si13887879pga.57.2023.05.14.08.58.57; Sun, 14 May 2023 08:59:11 -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=TlMRQMZD; 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 S238222AbjENP3h (ORCPT + 99 others); Sun, 14 May 2023 11:29:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235808AbjENP24 (ORCPT ); Sun, 14 May 2023 11:28:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 936684EEA; Sun, 14 May 2023 08:28:37 -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 228C361138; Sun, 14 May 2023 15:28:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4755C433D2; Sun, 14 May 2023 15:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684078110; bh=bRIrCHjbdkZMIq4/mCKkZCOfrF0gDAT9QeEo9NeR8YE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TlMRQMZD/zkU3pocW4viuecVfsF1DnEGbO1puEEtfxuzd7aZFsNmbtOVLD2ygt2rC atMtQqm5CBSaVzF3i4jhf1PX57ZwlvpNV3Maxn1/hOGHEEyo4+PYM6b2PDzaiJLX1/ hUYWXNDp/qofUeGXS4kOKstlSKN4g9hYL+uxkcnZDnXUbVcnnuVZLJmFLoynKZfIvC Am7+qnkvbSd7NAwZABnSb/HcNb++EZJ6uary++6YjGaXLr1LXPqHdaNz0HoXqZmr8Z ckHvivtA72OtvVw+ZdJTCUR9CJe2RSoXz5j5Vb9fJPA3moAQuPH+m5VPNRh7ZlAIQa TcfQz1fGxbvMg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Pitre , Nicolas Schier , Masahiro Yamada Subject: [PATCH v5 20/21] modpost: use null string instead of NULL pointer for default namespace Date: Mon, 15 May 2023 00:27:38 +0900 Message-Id: <20230514152739.962109-21-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230514152739.962109-1-masahiroy@kernel.org> References: <20230514152739.962109-1-masahiroy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, 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. 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 7edb9a843ead..010c4f88d77b 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); @@ -1784,8 +1791,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); @@ -1871,8 +1877,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; @@ -2140,7 +2145,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