Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp127640rwb; Tue, 27 Sep 2022 23:52:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7BmH2vJyMIg+xqo2eCE3Tlsx2c78GoEkI44VJDYQXBWcRLD2+scY0ccRVgEBndZQwDp50F X-Received: by 2002:a63:d118:0:b0:43c:1440:6486 with SMTP id k24-20020a63d118000000b0043c14406486mr27560134pgg.92.1664347955268; Tue, 27 Sep 2022 23:52:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664347955; cv=none; d=google.com; s=arc-20160816; b=aOTo4f8viru4GAr9DI8kEHVPFajndfeMGQL7BUzqyuI3nLgYTOjtrhkcDg2nyMac1N BF6ZR8dN/3yXp3tMf0OujDHqag00i5Qo68PDNTquSHo7VwWcDwphIW32i2i2QLIamrB4 K5vNnC+X1cNsijcDXJvauyC9gzWbwpOsDWhwpMcyXDMBhhfwGqXtLQNtIWCrVuaW/J+I IdcMdOlxVPZ1ehEKzpDnRwjS93EqCZbFQQuUsM9sEpmWnUYEdLlJlv/0QxU1R2G6q8BG mZh7pMA7qc9q0LgTm3t+Ib/wJFpdIRl8dr2o/xxmTgVhVBgbzQWrIIO5zeT0HTd1Yecx csyg== 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:dkim-filter; bh=OfuGM282m19iNX0i9PBWYpUdIc6yc2RZLrtabmbI8uk=; b=kmQ9kwW6EC8wE6rgQeqF/FJQ14Trmi0AIGTKc1fadkZGS6TgJ41P1O7cEzHZr6sYbj TJDLf2jHdBwhfsbTJEu+MwezF1kqnkrQs11+vnVE4Wv/ZDabRTxMHDADfFf94wRuzfZe uhLvRw+B+jHOU2UYT7YvFJodBVyPKopBF6HpJsqu+91uIRqyk2UJZ7OkxwAYSbEpR84Z QBkZnWUz0KFWLwJbLSnaQiwIb3M0VnG+F38CRFQBerZTBXEoZ708sPZxFz1cXFNG889L U680FLBEULEh5ooAcHTxFc3WZrVH0L4+00wLEsDchgf6e2rCHpRujRk8PXRl0/amLoHH HJMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=r2DYBVlM; 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 14-20020a63060e000000b0043895127033si4668819pgg.335.2022.09.27.23.52.23; Tue, 27 Sep 2022 23:52:35 -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=@nifty.com header.s=dec2015msa header.b=r2DYBVlM; 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 S233366AbiI1GnB (ORCPT + 99 others); Wed, 28 Sep 2022 02:43:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233238AbiI1Gl4 (ORCPT ); Wed, 28 Sep 2022 02:41:56 -0400 Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACEE4356CA; Tue, 27 Sep 2022 23:41:41 -0700 (PDT) Received: from zoe.. (133-32-182-133.west.xps.vectant.ne.jp [133.32.182.133]) (authenticated) by conuserg-08.nifty.com with ESMTP id 28S6e0G7004120; Wed, 28 Sep 2022 15:40:06 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com 28S6e0G7004120 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1664347207; bh=OfuGM282m19iNX0i9PBWYpUdIc6yc2RZLrtabmbI8uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r2DYBVlM3n1JE/j0i+IrsGIol9aMXxejVN+aAPQkLtcPkZMWC0bSU2aY7K+lfYeMz MO1NRFYfrbr6BiDjHwKAlFjt886M9YxG5DZnXGDMNkIjqWkJVWY2ikwVJjwHvXmVzb LsNHgDbgolEuJaknEXTbXDyzOP9rAws0MKgo3RCRLmCikxdpLaRTT3nM3wDY/YB7fs olNo+od0yBD3FE+cY6Gn27Iwu5kEKimbpBw9g574lWPmI+ns9wyIFjrF8RqNlxAw4o pjC3mVrdO+o5EsjI2qLoage6pOZeX7mSEt9DjpYnlrbvJXrlL/IQ04ddK5Fp28xREr 1c90NWEQtPe3Q== X-Nifty-SrcIP: [133.32.182.133] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ia64@vger.kernel.org, Al Viro , Ard Biesheuvel , Nicolas Pitre , Masahiro Yamada , Nick Desaulniers , Michal Marek Subject: [PATCH v3 6/8] modpost: use null string instead of NULL pointer for default namespace Date: Wed, 28 Sep 2022 15:39:45 +0900 Message-Id: <20220928063947.299333-7-masahiroy@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220928063947.299333-1-masahiroy@kernel.org> References: <20220928063947.299333-1-masahiroy@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,RCVD_IN_VALIDITY_RPBL,SPF_HELO_NONE, SPF_SOFTFAIL autolearn=no 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 --- (no changes since v1) 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 0bb5bbd176b4..29f30558a398 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -297,6 +297,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; @@ -366,7 +373,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); @@ -1928,8 +1935,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); @@ -2015,8 +2021,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; @@ -2284,7 +2289,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.34.1