Message ID | 20240202155825.314567-18-masahiroy@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-50077-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp526950dyc; Fri, 2 Feb 2024 08:05:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IF2S/4NzO/DSyzT/JjIWTUqjvhbRGf5SUz/uX/QAlVKVaKC+uPGnkL2PivqtWQ4D0j/+48e X-Received: by 2002:a05:6359:1585:b0:178:c7b6:b563 with SMTP id jv5-20020a056359158500b00178c7b6b563mr5015548rwb.15.1706889921676; Fri, 02 Feb 2024 08:05:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706889921; cv=pass; d=google.com; s=arc-20160816; b=mAhO+ASuUXmHUhN1ju5bIqceh0MXzywmVGMxzqMYLU2ErvP58OJp0Q6LvUUYAn4hYX X5vREi5bSovJUhuD5aVz95j8c6uyYDMhGoldBjDHOpTmpZydzvDGlW2dOj44Q0LxNapL HyHu9S2832RihEtSz8l86E3rUK1nTnh+oTN85oUnTnwM+43fTXtteSspAK8riHrk9bYm zFFV1N7tFBomZOfr/Tck8Z6BxHhFoQTFUTJGGqzdHANjQuUBEvo/TgBn0Lw65fs/DHF4 Sk+UVixypQuRQsKSlbNX1Fkow0W9Fuct4YslNv5/09IgXjRZU48g1TfSNAOBJQibuj9q NCnA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=HWmeTPA/Ax1NyR/7++x0YsmWZu/yoNEoSMQEnvO7fJs=; fh=XvXBAVkG9Wf5gfAkxTJkpKjfwRX03goNR7v4Ue5DiUA=; b=hBHp1dto0C8sekiYM6xs/egXS4QDUPA5XY/QCfns3BrJqzXMiqL47Kq01rL3zhDPbw 6IKClscyPHtVt2ZWphP6JfqblNWwAWfxu9mUn6WzbTrmb13xOR/LbIkn6xThWWoPIMJQ 692dn03sV7ibWXNJj0Ume4DbqHWbsKYZFefgZwE7RsTlwwrfsJfwyPLMshPBvp/YN3do u69PnzPK/NL/27puYZTXl/hBKZ1ygaSliur6VuIUzt8WiBx3CgOTdzsU9P7n9GMBqHrs LL+c0AtoYvSJIfMe+uJwizV7nrIMDyylkbOIVnLzVRHOluyH7ltRIcYxCM0+yhn/294r ra6A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZpRuZ5dP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50077-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50077-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCWqisqqmsD7kE2wMyrF7ciD0d3U+YxxPk4xuEh3d8fA/zJ7Zy1SZ/9GrnlQuSEKYYFKJW8MP3Q4r7HWLwksqxcCpP9XcQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id c22-20020a634e16000000b005d2eea210fesi1780369pgb.887.2024.02.02.08.05.21 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 08:05:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50077-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZpRuZ5dP; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50077-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50077-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5891628BB9B for <ouuuleilei@gmail.com>; Fri, 2 Feb 2024 16:03:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9287914E2E9; Fri, 2 Feb 2024 15:58:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZpRuZ5dP" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB4E214C5BF; Fri, 2 Feb 2024 15:58:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889529; cv=none; b=JV9SaGvZUcvdXrWK32GMP4F4/MgNjQ5Jxm7NO9bxuvYFzWBm2eLAHMf+dJxtUAPeJb4qS+v8mTrpU65aJtP5siauzOyfqBTZHeeNoL8exUQNEPt1o5j/TP8wka99tFgnezC6ux7yrM5NHWxcf6+EpqDwuX7GJA92xPAOI7qKJYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889529; c=relaxed/simple; bh=6HFGjcFafgAEeyFv5246DWk9iueSVCKM1qtHrZhaPSg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=p/Jjm0lB/o/H3az7EboYsMqQC0BG3drg4/3TNsltXpOKtGzBjpekIfzpMCgA534pLNi0Q9vMiy3dKW1aaQGhJ1KnSqPCxV5OwNWy6MyHDzI6e1kB+86HlnUOwGR9NYzvgAK4nk+6nrB/DrSGeHZ45nzowo+4UxGDqXIHjrMTnZ8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZpRuZ5dP; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B2705C43394; Fri, 2 Feb 2024 15:58:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889529; bh=6HFGjcFafgAEeyFv5246DWk9iueSVCKM1qtHrZhaPSg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZpRuZ5dPoGqLFy/mD0TUPIugrzKvZNC3pn/xuM5uXOnMUEqeAnO4mP8J8AHOovi2e V9bv0V1t/dUZRfMyT4NzZyNHZMzVHge3oW8tFHgt00Ksh1X3PvC+4dmZYbcJBhXUG/ gcsT67VmRc4T6xM/t/Ax5DuasRogKbT6srB21N5znhBBAnURVRBwa6AM+Rndjg7ToG RbRqnyuADceWcSz5Mc2mJAsN55XxxsNFrtEicOnr2TmRRo+jXuh9lI1chiuVFMNbcE jISsQmgtU8+B5ipXmnnXFbx7nN30wzCHwCpSfLoYghJRfeUrjNLQI6tnvWRrtVOf3q rw+/eJ5ierp4Q== From: Masahiro Yamada <masahiroy@kernel.org> To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada <masahiroy@kernel.org> Subject: [PATCH 17/27] kconfig: make file::name a flexible array member Date: Sat, 3 Feb 2024 00:58:15 +0900 Message-Id: <20240202155825.314567-18-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240202155825.314567-1-masahiroy@kernel.org> References: <20240202155825.314567-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789803806811611421 X-GMAIL-MSGID: 1789803806811611421 |
Series |
kconfig: refactor lexer and parser code
|
|
Commit Message
Masahiro Yamada
Feb. 2, 2024, 3:58 p.m. UTC
Call malloc() just once to allocate needed memory.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/kconfig/expr.h | 2 +-
scripts/kconfig/util.c | 7 +++++--
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 85e0d1ab3c8a..760b1e681b43 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -19,7 +19,7 @@ extern "C" { struct file { struct file *next; - const char *name; + char name[]; }; typedef enum tristate { diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 958543bb0a37..2636dccea0c9 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -13,6 +13,7 @@ struct file *file_lookup(const char *name) { struct file *file; + size_t len; for (file = file_list; file; file = file->next) { if (!strcmp(name, file->name)) { @@ -20,9 +21,11 @@ struct file *file_lookup(const char *name) } } - file = xmalloc(sizeof(*file)); + len = strlen(name); + file = xmalloc(sizeof(*file) + len + 1); memset(file, 0, sizeof(*file)); - file->name = xstrdup(name); + memcpy(file->name, name, len); + file->name[len] = '\0'; file->next = file_list; file_list = file;