From patchwork Thu Jun 8 14:24:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 105002 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp382676rwl; Thu, 8 Jun 2023 07:49:27 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5R45VgjYFiyzpHOJp2ABKKJXmnhjAVhotiLSWWl6VWA6IuEqf6LGXbpBws/LQti1c1x+19 X-Received: by 2002:a17:902:e5c5:b0:1b0:5ce9:adc7 with SMTP id u5-20020a170902e5c500b001b05ce9adc7mr2609962plf.28.1686235767628; Thu, 08 Jun 2023 07:49:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686235767; cv=none; d=google.com; s=arc-20160816; b=qzSaYrmptGVDSzXm5WKknirpKK9a/vXF2+eRmyRsLS3y2yt33q/4OTVgTYShKClQuS 4NJxRS9kT63x/Mc6XlKYXNnHeBH5OTA4mafteexyszUomwcuZ7SJ9r+uq0xa8QY2nKHQ IwEQj0dH5+3bgtY+ZP1C3sAJTqCZDMKsHyDJK6gv5JoJV1IyaAbapmpgRlZCosD9UCO0 fRJyJJGWx0209JfHnaor7q32p0Bu5Azgz1U/AqOUnWf7Q0GTRFhK9Sv1MmstVL0iqvg8 PlWmZ55vN0G1ME2hE7lZ5KbrFGbxPCLSkKRSR5BFkg/uGswdjmZGcN5XU5M9XeJebaOd eOzQ== 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=bB6JjFtJ5iki5iTIcuNeCfgWlmLsVWt8weVIA5Nt5G8=; b=Yk0+/4bBG0SKmAHYLKI5wPqMvskyvOzWoPAMtNDshc6iJb3G+FGLh51FbTp0dbUqkc Jguz9BtF50kCwuHnWTtYzcaXIYNNdvAkKxMkYIMc6/WE1Bma/kFYC7hZLb0A6e8NbXRn /IKdvbYH2iNAPKIke8DwSWZCfFPsYl4QP6/LKMVpBagK96IfdjxzICaxOJ6VxILSsPWc cxv2wSjLrUA3Vzxk/APvqCVN2f5gdE4RWiis5T0bidfN7fuXGhnZRgSkLFt0RBkfT/5R vQgFQMNh8bUP5/qoJFN6cP1KChvXESgzO6A/+pSRq7rmtLJGMHndKL5vcF99aXaHZSdl S6tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="E/ppkNpU"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg9-20020a17090326c900b001b25c006fbcsi1177662plb.99.2023.06.08.07.49.14; Thu, 08 Jun 2023 07:49:27 -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="E/ppkNpU"; 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 S237239AbjFHOZc (ORCPT + 99 others); Thu, 8 Jun 2023 10:25:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237097AbjFHOZI (ORCPT ); Thu, 8 Jun 2023 10:25:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E6202D6A; Thu, 8 Jun 2023 07:24:53 -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 2C75264E2B; Thu, 8 Jun 2023 14:24:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52D36C4339E; Thu, 8 Jun 2023 14:24:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686234288; bh=Ap3GuMqINZf2WdIT1xsNL1OzEvsLgkbr6RhrjaSFN2U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E/ppkNpUa1T5/FB+OZN82dq2UDzQIyU5Cbo8U3TTO4UUNzBPXl51gEj6FYXPHd0C0 B8fBUUD/WnNo6CND5zxE7A91YlNR8D75vEQqCmvaXDREUZMvckx6QEyeAr2D8LRUg6 mTEF3tCzZrWR/Bz+RWDK09Bl8RxWyDtiAseu46h6FEXk+pM2XpyEbH01OEkUhVaYt3 N6AWER4bq6Z6hZwWxZc4TOIfkzhSS9PaCantt/xrBbkDTIhgc/96+WPERBmKn2RSCz ItV8rK4Zh871ZfPPMNhWASgocY09hJn0uporPngp75NKd2+x//eEWrcaAry+aGCdFy ehyl0GtZu4Lag== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , Nick Desaulniers , Nicolas Schier , linux-um@lists.infradead.org, Masahiro Yamada Subject: [PATCH v7 07/11] modpost: use null string instead of NULL pointer for default namespace Date: Thu, 8 Jun 2023 23:24:24 +0900 Message-Id: <20230608142428.256985-8-masahiroy@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230608142428.256985-1-masahiroy@kernel.org> References: <20230608142428.256985-1-masahiroy@kernel.org> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768146356094387387?= X-GMAIL-MSGID: =?utf-8?q?1768146356094387387?= 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 4b0a009de0fb..7044b257424a 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); @@ -1823,8 +1830,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); @@ -1910,8 +1916,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; @@ -2179,7 +2184,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);