From patchwork Fri Feb 2 15:57:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543095 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 1BC991474D0; Fri, 2 Feb 2024 15:58:31 +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=1706889512; cv=none; b=lBBQQp/omGHFvS6vgKdMn8qM5hm1zSBvU+dP4DeaSDztsAxhX4si5Ir4xK59dHHlSj+gb8LAnKiqKoWyo2xnStuIIOpL79H5hxupDEEVJQYoRJX+aCk8uq5YKUs/wYlWyFeWoQVYKA7w2VPecykrOsJPZaMjbnuLyiBA26uN744= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889512; c=relaxed/simple; bh=0zjrnd8HxqGEk4V/+9L30lJo6lzcn61RhZYmqtdDahY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rOEsJ0DYvyWGd+uuYSVzM6fM0Gu2IE252Uz8uITV2OizQ2IK0Cf+v3BLkSbu2DjJmL93LTv3j+9DYEM4C1cHpgQBxrwFa4r4VNn3TtATsD6ResTxD5mt/8rK68A9vUvtbjhoXHvIUg4U/tgXdi/r8u+D8Lu9lBgGsKREJx4aIwc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NjPyEICc; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NjPyEICc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0CBBC43390; Fri, 2 Feb 2024 15:58:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889511; bh=0zjrnd8HxqGEk4V/+9L30lJo6lzcn61RhZYmqtdDahY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NjPyEICcCinl8z3u4AxSSHdlSJA2HhXiOK0v8gPVhLMPkDkG1KeD3HTgqSwUfxqfQ Icne3B9EFy9SqptamIRc+TR2Wf+s2AV7pRbWg/zPt4EqKzovuhH5B8AoENgdSQddfA c8Ka+yiJ0ellWjGRGL2fGQ+UtQwKC4r5b74KdkZHHp65cauwwa35qN42Aha/VsDx+2 EyYtH52Jnk8am2jFHpvfnt/ll1s4+ifKfEozdfMxNQ4z701wMKKqILKio1f7Ot+ovh /3JldDJD+nf8MJxG0eQjIeeZh2M4GEwB43qFbf0pR5ANvNH7U14vctxncRD3rInEbf j3DVnAR83Blag== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 01/27] kconfig: fix infinite loop when expanding a macro at the end of file Date: Sat, 3 Feb 2024 00:57:59 +0900 Message-Id: <20240202155825.314567-2-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 A macro placed at the end of a file with no newline causes an infinite loop. [Test Kconfig] $(info,hello) \ No newline at end of file I realized that flex-provided input() returns 0 instead of EOF when it reaches the end of a file. Fixes: 104daea149c4 ("kconfig: reference environment variables directly and remove 'option env='") Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index f93b535a080c..5f1bc3320307 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -303,8 +303,11 @@ static char *expand_token(const char *in, size_t n) new_string(); append_string(in, n); - /* get the whole line because we do not know the end of token. */ - while ((c = input()) != EOF) { + /* + * get the whole line because we do not know the end of token. + * input() returns 0 (not EOF!) when it reachs the end of file. + */ + while ((c = input()) != 0) { if (c == '\n') { unput(c); break; From patchwork Fri Feb 2 15:58:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543096 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 1FE5C1482E3; Fri, 2 Feb 2024 15:58:32 +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=1706889513; cv=none; b=AxcEewD3rokcQkAwVQfzhPogE7TbmhgEWMMfHISJ5EntoiMu3342eBcoQRt4sn5Ba02jsR1feh71ORLF8jqAmefDh7Gx51+34cvBHFMmH+ACgyRBr+nYkP5DxCvmiT3HYxWmAs3/u34du6SNkIUJCXqrPA2blqMYcf62XuoV7Ug= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889513; c=relaxed/simple; bh=iLMWYG9L/UfAHJBH+yDa8fL9Z1alCW8nTVuRLWkFGEM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WjYCTjxD1AeVcetxnhD7toIsUiLAcLmmeA7s9i395WgDyQhLIo6vvGiul90mhljtXLLv8/A+dxovVkGsHkgTk2iofpNJqE6M+Ds31qcxyu/znJvLLkvw9PtxAmpJ0GK0YQhR7KyemTmwazfWKxk9wLINPSQs+sZOE3imf3hrLaE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NpuPqRlk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NpuPqRlk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 061D0C433C7; Fri, 2 Feb 2024 15:58:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889512; bh=iLMWYG9L/UfAHJBH+yDa8fL9Z1alCW8nTVuRLWkFGEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NpuPqRlkvGyBwYgYUT16rib5rySaETzs/nqVuIY5CKa0/laJ4lhuboWHFRZt9MFy5 dCj9jM44SzStc7QpKiMe1vsKJOn/fc6S7Rs6V2BuVOxJH0M6KroAPtk/5ZZlhCQuEe nzwmDRMCvvdFcp8NbwV2qQyep08nevb+637wq2lH6LsBgA/lXgdSwozcjLVUWJPf3d qa4ABjM8q4MswOH+92fwi/aqmgatahYy2VEE3tHNvYC5xk0feDEAdcbw0WlQ3HeWOM ZXv/ZhGaVwVoSZDSIx+WXX+h0AsiXh2OdCIJTmSRP7cyd07LMQKiVQDLKv0Y5Q9BRS 0Lfj81ou4IaoQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 02/27] kconfig: fix off-by-one in zconf_error() Date: Sat, 3 Feb 2024 00:58:00 +0900 Message-Id: <20240202155825.314567-3-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 yyerror() reports the line number of the next line. This +1 adjustment was introduced more than 20 years ago [1]. At that time, the line number was decremented then incremented back and forth. The line number management was refactored in a more maintainable way. Such compensation is no longer needed. [1]: https://git.kernel.org/pub/scm/linux/kernel/git/history/history.git/commit/?id=d4f8a4530eb07a1385fd17b0e62a7dce97486f49 Signed-off-by: Masahiro Yamada --- scripts/kconfig/parser.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 2af7ce4e1531..5ab2e3f7ca33 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -557,7 +557,7 @@ static void zconf_error(const char *err, ...) static void yyerror(const char *err) { - fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno() + 1, err); + fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno(), err); } static void print_quoted_string(FILE *out, const char *str) From patchwork Fri Feb 2 15:58:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543097 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 53D29148306; Fri, 2 Feb 2024 15:58:33 +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=1706889514; cv=none; b=VeZlrYTX4IDr44KRLxCWsBTj0KZyLo8OLto00t2MVO3nNrAxulO4HD9/HSwIcInwEdnEALdWEpxgZ+kVbIYZPWXQhJAKjUNcx6srPz4vjnInlnUGOvL4uS3ggyK9xey1NjDVhsa0vZa8RLJavoEG2UgxAko6bZbdlwTTRRLytX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889514; c=relaxed/simple; bh=U5NM7Nt1jzE4iRK2epL3mIB1zFDNJP0QdfPYsv0sK38=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Paffz+8cnpXb+fd+SbNygp5dQP/bt4eEaClRNEFq5sLaTOAx5MArwz1gzft22gCD30xb4dOc++nyVCYG+AWGxueN9PJ1kXdbNVBCJAESlVQAF6wcSQZhOwNWk5Jy76qAsxO1LZZYJkbKL8XE/Y4Ku7J5b+fXaAZRg1COaKqFZZg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=J3YzqHSF; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="J3YzqHSF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2052EC43390; Fri, 2 Feb 2024 15:58:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889513; bh=U5NM7Nt1jzE4iRK2epL3mIB1zFDNJP0QdfPYsv0sK38=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J3YzqHSFhHi/Xn7vCle18PeBGaX/7q1UbDyit2H5q+IpYHWf0ytoRBCOnCJE52OHB bVVZygYNsWon2/wSxLISzOFDKYs9b2af6fJvaI6U+KqexT4vjwUV7FafeB7snJlsuM AljXW9pKS0iOCaTXeNV+TPqcJ8MmbH3zRyE3nWUpkXPr37NpBam/0n0MU46rejfLMj kjETDZbZptK2dSJlxCdoY759SVoQClevoVR7z2zJgSpFfdun8Ln4QUMCOBGYUAuKkP kKsOSErVCP6nsd5o1RLn0YIqr0E/HN7vX/m3PTLhHqSk47xl4/7ZFkTczY2CIT9G/j JM9wM/B7FMspg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 03/27] kconfig: remove orphan lookup_file() declaration Date: Sat, 3 Feb 2024 00:58:01 +0900 Message-Id: <20240202155825.314567-4-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There is no definition, no caller for lookup_file(). Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 4a9a23b1b7e1..e0d866569155 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -279,7 +279,6 @@ struct jump_key { extern struct file *file_list; extern struct file *current_file; -struct file *lookup_file(const char *name); extern struct symbol symbol_yes, symbol_no, symbol_mod; extern struct symbol *modules_sym; From patchwork Fri Feb 2 15:58:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543098 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 7260A1487D3; Fri, 2 Feb 2024 15:58:35 +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=1706889515; cv=none; b=GvbzoIncIWT91PazMq+kDr9H5zM8RSzhAZtfm4Cpkz9LXS39CmGnNE3hRLSoOvlhxI1v29nYMacoMh5r+jU/cFeQOAs6BnzukXIeTwFKvu49xa/jwvveAeUZtorbta5eljdbzdwdM5MCZ+fnK6lj+BlxaakmXX36Z0duShAiP+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889515; c=relaxed/simple; bh=nSRikX5IZ2J1r96VDgq1SrF4bz4pPtNZkcuO4TYY710=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sZ4vPbHv0L4mjV2Bzq+gg+exBAiiRDrschWOy8JERZXG8Kl3xRaaZHfgDVv345mVKOiLIM/MMBqEzTSQXsGjf0QkHuOP+4ztIrEIIotsCQxUJteSkWZMy0+k2pBjkcHjr0brfko94167GAavHKZ1vu+AysElgAKA8Ku9KB2Y3Mo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CV62y6n5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CV62y6n5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45BF9C433C7; Fri, 2 Feb 2024 15:58:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889514; bh=nSRikX5IZ2J1r96VDgq1SrF4bz4pPtNZkcuO4TYY710=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CV62y6n5vEDASX+xf/AutgHxnf/P5YBnpFM/BAEhoZzY3FEbrJHCneBJB/LQZc+hY 9BbfRSPPA5ErdoGySq43TYdBMwI7BW2oK0RB1vMQtM2RDTt55azyoEC7tZ/JtPRL6H gUwPDPbYsVQMTGO1t2+WErK5yFqjfAj2Obq2v14kRac8R5Ppi+17MLKhGoC8NfoidV jeFf5D6ZpQzDwdQHDHChMB94zcz2s10npXwQatOonr+YcmHlY6zO6LueOjKwO07YRm 4ZTnYT77R+QtRI7Cpn/R5bRcMl8tq8Fej1uTNv/kpmNMa16hkZ5OvlXAmKw6Lx5SU1 hHk/xhtTjNQ1g== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 04/27] kconfig: remove compat_getline() Date: Sat, 3 Feb 2024 00:58:02 +0900 Message-Id: <20240202155825.314567-5-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Commit 1a7a8c6fd8ca ("kconfig: allow long lines in config file") added a self-implemented getline() for better portability. However, getline() is standardized [1] and already used in other programs such as scripts/kallsyms.c. Use getline() provided by libc. [1]: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getdelim.html Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 53 +------------------------------------- 1 file changed, 1 insertion(+), 52 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index f53dcdd44597..7f0aa39b68c1 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -293,63 +293,12 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) return 0; } -#define LINE_GROWTH 16 -static int add_byte(int c, char **lineptr, size_t slen, size_t *n) -{ - size_t new_size = slen + 1; - - if (new_size > *n) { - new_size += LINE_GROWTH - 1; - new_size *= 2; - *lineptr = xrealloc(*lineptr, new_size); - *n = new_size; - } - - (*lineptr)[slen] = c; - - return 0; -} - -static ssize_t compat_getline(char **lineptr, size_t *n, FILE *stream) -{ - char *line = *lineptr; - size_t slen = 0; - - for (;;) { - int c = getc(stream); - - switch (c) { - case '\n': - if (add_byte(c, &line, slen, n) < 0) - goto e_out; - slen++; - /* fall through */ - case EOF: - if (add_byte('\0', &line, slen, n) < 0) - goto e_out; - *lineptr = line; - if (slen == 0) - return -1; - return slen; - default: - if (add_byte(c, &line, slen, n) < 0) - goto e_out; - slen++; - } - } - -e_out: - line[slen-1] = '\0'; - *lineptr = line; - return -1; -} - /* like getline(), but the newline character is stripped away */ static ssize_t getline_stripped(char **lineptr, size_t *n, FILE *stream) { ssize_t len; - len = compat_getline(lineptr, n, stream); + len = getline(lineptr, n, stream); if (len > 0 && (*lineptr)[len - 1] == '\n') { len--; From patchwork Fri Feb 2 15:58:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543099 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 8CADE1482E3; Fri, 2 Feb 2024 15:58:36 +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=1706889516; cv=none; b=mxygVc23mrNxy1blwmc/4JYwFRPLR6YWdbcKufGd/Xp2hVZdpwRG6JMoHsRfaHRwKtChGq+OpRLls8k3E/U40FZI0r3a/ZS5xSY7fgMqyntu3DS3sGLtAMUBlSvxWDr78n2kzODhoyUUkJBfR43bXjheEH/grb9C3NuPoruMPUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889516; c=relaxed/simple; bh=QxttmJ6wH6mvkJitGwDubEDFOUUd2Xr4fYtG01w5re4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WONbj9olxerMc9dvNFdNkDvnv5vqbsbp1+zQ5gVOl4b88YUOUSIhdQfiHCmWsdAsVOiw1/dSbFjoCoU7vE3clarlJNKfDnO5r3nFtqdZYwVyQtI68YgzUka8lDf7DSYvfdpmmqZausQseG3FEWdnYrSVTunzey2OazMw5y5ql2Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OzARufdB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="OzARufdB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EC86C43394; Fri, 2 Feb 2024 15:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889516; bh=QxttmJ6wH6mvkJitGwDubEDFOUUd2Xr4fYtG01w5re4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OzARufdBT5hsokUprAZCTDzxdWpGu+Zgr8rkMV6VpJTEoyd7K0Zj0EDWoTyH/8ksw NWxctv98n7HaGkAbYF3bVksUklaPM/Pj9n3MZsApGSnB300SB10Y+nGQFuv8DssnFB XIrA72wAAr/x0BZokXdPHoas20PqgAbG4SUBDbC9UdApGxyDW49W86hhotLQ9hFE25 0pPy1VpIoGOVORHKWrL2si/hI/MsHWQo69+lKaY283REIWZptn97kKBRYJQasiSbRi Dis1SEEwDJ4eabvi9qyTEh4N1/DeIyxc1hqes+Ddm63hGEgJGuUzI8cKX1xejrVm7a Y27KPWi15K/Qw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 05/27] kconfig: remove unneeded sym_find() call in conf_parse() Date: Sat, 3 Feb 2024 00:58:03 +0900 Message-Id: <20240202155825.314567-6-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 sym_find("n") is equivalent to &symbol_no. Signed-off-by: Masahiro Yamada --- scripts/kconfig/parser.y | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 5ab2e3f7ca33..625224973c51 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -494,7 +494,7 @@ void conf_parse(const char *name) if (yynerrs) exit(1); if (!modules_sym) - modules_sym = sym_find( "n" ); + modules_sym = &symbol_no; if (!menu_has_prompt(&rootmenu)) { current_entry = &rootmenu; From patchwork Fri Feb 2 15:58:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543100 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 A79C314830D; Fri, 2 Feb 2024 15:58:37 +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=1706889517; cv=none; b=AnawPIoGxsLCPtf2eiLbE7V6jv8kOOm4eLmb90OBzVZtT+uSiWVvDtsUdJyKPXOjKqq41RIoIvmI5g6a/f2rOb/cpWfIp9l1comQrpapX1Olrm4xyOSnojY7MGA7MayuZi1OVeN3w+qIi+BrehBkfbUwzpkCV6x3hKD8HJye6VA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889517; c=relaxed/simple; bh=/e+y+eilKt3GBjvzu+Sekt9FhDg+Vd4BKzKbrcOkrYI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VcKz+5i0vKCbmswHxq7Aw3QN/4fxepBBZ9dcyfXhZC6K1bwNl7Kx16TVHBCYbdc+okAtaNILV85mSTY+haVfYcz5e+iDTwkoLgyeNNMR528qfzkk8yWfo4LoNyTH8AXRGoD0WCumq9ekLpJnxv0Gnb1No9ZjktxCHcWZ3eGEY4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pnIkimcj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pnIkimcj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84531C43390; Fri, 2 Feb 2024 15:58:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889517; bh=/e+y+eilKt3GBjvzu+Sekt9FhDg+Vd4BKzKbrcOkrYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pnIkimcj7yXLKIMbA2EwdXN2Gjp4jGovzk46bpMGsxBm8+RYhxONTJM2iLqPQfJ9J Rh39I2hn/xjT2KgHvlXmkbz/wBgpRgNwjzOC1qBag6Y44QNd4wMW/sOWMQSDc91mlH Q260z921WkCeN2y0x1rmh+Vk/lRymcY3TAV/VK4/3l1lYDIGb9TOesWQ1Vjj79mgHw Y5+bo2k8bNEeuWiVP42+r4ULgd120vKnqNj7KYPUtIATBS2/JKPFQLvj6lW6/xab57 GqLhkJKagNVO2OYkNBJMXtyFJRD9LtcXs8/UNYitsw6XLHVDo3klUIeNZS/G0y6Z5k WvRts7dICAfzA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 06/27] kconfig: write Kconfig files to autoconf.cmd in order Date: Sat, 3 Feb 2024 00:58:04 +0900 Message-Id: <20240202155825.314567-7-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, include/config/autoconf.cmd saves included Kconfig files in reverse order. While this is not a big deal, it is inconsistent with other *.cmd files generated by fixdep. Output the included Kconfig files in the included order. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 7 +++---- scripts/kconfig/lkc.h | 1 + scripts/kconfig/parser.y | 4 ++++ scripts/kconfig/util.c | 3 +++ 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 7f0aa39b68c1..f6a96fdddb7e 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -20,6 +20,8 @@ #include "lkc.h" +struct gstr autoconf_cmd; + /* return true if 'path' exists, false otherwise */ static bool is_present(const char *path) { @@ -972,7 +974,6 @@ int conf_write(const char *name) static int conf_write_autoconf_cmd(const char *autoconf_name) { char name[PATH_MAX], tmp[PATH_MAX]; - struct file *file; FILE *out; int ret; @@ -993,9 +994,7 @@ static int conf_write_autoconf_cmd(const char *autoconf_name) return -1; } - fprintf(out, "deps_config := \\\n"); - for (file = file_list; file; file = file->next) - fprintf(out, "\t%s \\\n", file->name); + fputs(str_get(&autoconf_cmd), out); fprintf(out, "\n%s: $(deps_config)\n\n", autoconf_name); diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 5cdc8f5e6446..8616ad83be6d 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -40,6 +40,7 @@ int zconf_lineno(void); const char *zconf_curname(void); /* confdata.c */ +extern struct gstr autoconf_cmd; const char *conf_get_configname(void); void set_all_choice_values(struct symbol *csym); diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 625224973c51..611038c502fc 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -480,6 +480,10 @@ void conf_parse(const char *name) struct symbol *sym; int i; + autoconf_cmd = str_new(); + + str_printf(&autoconf_cmd, "deps_config := \\\n"); + zconf_initscan(name); _menu_init(); diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 92e5b2b9761d..958543bb0a37 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -25,6 +25,9 @@ struct file *file_lookup(const char *name) file->name = xstrdup(name); file->next = file_list; file_list = file; + + str_printf(&autoconf_cmd, "\t%s \\\n", name); + return file; } From patchwork Fri Feb 2 15:58:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543101 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 DC6651487D3; Fri, 2 Feb 2024 15:58:38 +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=1706889519; cv=none; b=liqUIMJlxlNi6InJ/rxUdHgFhyA7stYJBzad3NDohcBepiArlJprw1YDwXgz1my3ytbm9KPUOjy/tnT/VNanWC9eG1wBlkbj8/5/uFJx+7ZjmoTvEZyu8mtaSbea/4afdAhuNNzfc0MczMBUdwSH9vg/fJNs97fzuVwRH26+Y/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889519; c=relaxed/simple; bh=R/ud+/692kalgVHV0nqCoalOnQuqYPYP1Bs8zxfM520=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Knxhn2bUoDQZDT3rO/CGKv0vmYR/403atT9R6OvbPsOf8nNRg47zJD7+jVLgIKyV91fylm210Lb/84KwZYkqOne5sPKWnijfsj0sTuWjBg9+Q/oEZFqwTFG4QanXRJsog5CwfX5wRAubKe0ajkGcFnO9obg92c5NQolEyiqOh4g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iNYxlaze; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iNYxlaze" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FE71C433F1; Fri, 2 Feb 2024 15:58:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889518; bh=R/ud+/692kalgVHV0nqCoalOnQuqYPYP1Bs8zxfM520=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iNYxlazejOtTkfIDYgKVtb0w3qXSn/htZNacZR08Yz1ZnsDAGDrl5dXkTmKgew4+b 7B93InMSKi1t4t0iLFaJ+uxVy9U5i2I0za3d3Npy24JTbWAfzrfqPCDhIe9FCZ5jXJ xGYJ9mtlROeoV8AorAayvblqUmYHca3/iYwRqzFKXnTlfDSWyvTWhyZyYfvT6ot97w JemRdBbueOE0dyP/pCulU4fiN8qJ8/OvaeGlMkNFMkdEBGmhKVayu/MksxLyrvFjis HTPwIcxrzvhVgCOzYBp89Bn0+7ctPJNCrDn9ntOhDzKS/iXVlc3cgOWRl5V6kWpHA+ tbIAJNf1RGBfw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 07/27] kconfig: call env_write_dep() right after yyparse() Date: Sat, 3 Feb 2024 00:58:05 +0900 Message-Id: <20240202155825.314567-8-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This allows preprocess.c to free up all of its resources when the parse stage is finished. It also ensures conf_write_autoconf_cmd() produces consistent results even if called multiple times for any reason. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 8 ++------ scripts/kconfig/lkc_proto.h | 2 +- scripts/kconfig/parser.y | 9 ++++++++- scripts/kconfig/preprocess.c | 11 +++++++---- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index f6a96fdddb7e..dafc572e7b7e 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -994,14 +994,10 @@ static int conf_write_autoconf_cmd(const char *autoconf_name) return -1; } + fprintf(out, "autoconfig := %s\n", autoconf_name); + fputs(str_get(&autoconf_cmd), out); - fprintf(out, "\n%s: $(deps_config)\n\n", autoconf_name); - - env_write_dep(out, autoconf_name); - - fprintf(out, "\n$(deps_config): ;\n"); - fflush(out); ret = ferror(out); /* error check for all fprintf() calls */ fclose(out); diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index a4ae5e9eadad..85491d74a094 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -46,7 +46,7 @@ enum variable_flavor { VAR_RECURSIVE, VAR_APPEND, }; -void env_write_dep(FILE *f, const char *auto_conf_name); +void env_write_dep(struct gstr *gs); void variable_add(const char *name, const char *value, enum variable_flavor flavor); void variable_all_del(void); diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index 611038c502fc..cfb82ba09037 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -482,7 +482,7 @@ void conf_parse(const char *name) autoconf_cmd = str_new(); - str_printf(&autoconf_cmd, "deps_config := \\\n"); + str_printf(&autoconf_cmd, "\ndeps_config := \\\n"); zconf_initscan(name); @@ -492,6 +492,13 @@ void conf_parse(const char *name) yydebug = 1; yyparse(); + str_printf(&autoconf_cmd, + "\n" + "$(autoconfig): $(deps_config)\n" + "$(deps_config): ;\n"); + + env_write_dep(&autoconf_cmd); + /* Variables are expanded in the parse phase. We can free them here. */ variable_all_del(); diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index d1f5bcff4b62..b9853d4a891c 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -87,14 +87,17 @@ static char *env_expand(const char *name) return xstrdup(value); } -void env_write_dep(FILE *f, const char *autoconfig_name) +void env_write_dep(struct gstr *s) { struct env *e, *tmp; list_for_each_entry_safe(e, tmp, &env_list, node) { - fprintf(f, "ifneq \"$(%s)\" \"%s\"\n", e->name, e->value); - fprintf(f, "%s: FORCE\n", autoconfig_name); - fprintf(f, "endif\n"); + str_printf(s, + "\n" + "ifneq \"$(%s)\" \"%s\"\n" + "$(autoconfig): FORCE\n" + "endif\n", + e->name, e->value); env_del(e); } } From patchwork Fri Feb 2 15:58:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543102 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 DA55A14A0AB; Fri, 2 Feb 2024 15:58:39 +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=1706889519; cv=none; b=JEJTQAqbeePQQDES1nGgrr55vwOz+047CdiSkyCqqKyM6dkQGTa0MBeui+wLicsJTnlgdvkfw1cpmBNBo7ettQc2cIRn3UQaoyiQATcKzgWAZDNBoxk2SKdPGYZRQuSN30RkUD2iT7blAv0eqmHLqmC/zSSDQ1r5J8XdGFjCtLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889519; c=relaxed/simple; bh=6fgo0sRjNFgx+31jjBB4hfJzesvi3QurT2SN9+UQZOc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZgrIK0BBf1wdfNKG+0qspwYpos49k23xKJxK38cXpcDlcilBzVnnxHVIQbib3appwI1IkfHBDa28XheiZS53tydQ4TBTRUHVRZoZD+U3CmBKqy0izU58yjfNzWXLYiZjyz5kIHrFlQf/7INsjNbNNkjdZdJHZPPad0k02M6rAPk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M43/Ok1/; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="M43/Ok1/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBA29C433C7; Fri, 2 Feb 2024 15:58:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889519; bh=6fgo0sRjNFgx+31jjBB4hfJzesvi3QurT2SN9+UQZOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M43/Ok1/EiL895vytxYLJICTMw4tmYih6gGNoN69mxCxzVNpA6pNFX1yIxYTv8AV3 CuINhA4h/5ghM8yLCdurI9dqa9wXeR/ATg8CMBFoYnHkQkCHbQHCQbp3FJqdI9aTkV tAWPnJAFNDTNA0VdPTf3knNglwkR3axa6PQMcXCLkv6RNEaKym4ATEjupRa+yKdTxv IljyEMvCDvsPN1FoG4w8JklfWerggQiNk51ykC4cbGrmwT+Q+gSiJh9DMbFqw8FNf/ 90O9NnmcTQLZcR5ye35mjXIhS9IgTbjepWMcBmHqZC/bhlr2nJ0ah1nC/cRv6/PUxl QTN+OBYS9ZYJA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 08/27] kconfig: split preprocessor prototypes into preprocess.h Date: Sat, 3 Feb 2024 00:58:06 +0900 Message-Id: <20240202155825.314567-9-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 These are needed only for the parse stage. Move the prototypes into a separate header to make sure they are not used after that. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 2 ++ scripts/kconfig/lkc_proto.h | 13 ------------- scripts/kconfig/parser.y | 1 + scripts/kconfig/preprocess.c | 1 + scripts/kconfig/preprocess.h | 19 +++++++++++++++++++ 5 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 scripts/kconfig/preprocess.h diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 5f1bc3320307..1bb372868ecf 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -14,6 +14,8 @@ #include #include "lkc.h" +#include "preprocess.h" + #include "parser.tab.h" #define YY_DECL static int yylex1(void) diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 85491d74a094..94299e42402f 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -40,19 +40,6 @@ const char * sym_get_string_value(struct symbol *sym); const char * prop_get_type_name(enum prop_type type); -/* preprocess.c */ -enum variable_flavor { - VAR_SIMPLE, - VAR_RECURSIVE, - VAR_APPEND, -}; -void env_write_dep(struct gstr *gs); -void variable_add(const char *name, const char *value, - enum variable_flavor flavor); -void variable_all_del(void); -char *expand_dollar(const char **str); -char *expand_one_token(const char **str); - /* expr.c */ void expr_print(struct expr *e, void (*fn)(void *, struct symbol *, const char *), void *data, int prevtoken); diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index cfb82ba09037..ff68def09a2b 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -13,6 +13,7 @@ #include "lkc.h" #include "internal.h" +#include "preprocess.h" #define printd(mask, fmt...) if (cdebug & (mask)) printf(fmt) diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index b9853d4a891c..12665b981c3e 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -11,6 +11,7 @@ #include "list.h" #include "lkc.h" +#include "preprocess.h" #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) diff --git a/scripts/kconfig/preprocess.h b/scripts/kconfig/preprocess.h new file mode 100644 index 000000000000..a7e4a550638c --- /dev/null +++ b/scripts/kconfig/preprocess.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef PREPROCESS_H +#define PREPROCESS_H + +enum variable_flavor { + VAR_SIMPLE, + VAR_RECURSIVE, + VAR_APPEND, +}; + +struct gstr; +void env_write_dep(struct gstr *gs); +void variable_add(const char *name, const char *value, + enum variable_flavor flavor); +void variable_all_del(void); +char *expand_dollar(const char **str); +char *expand_one_token(const char **str); + +#endif /* PREPROCESS_H */ From patchwork Fri Feb 2 15:58:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543103 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 0A7A614A4D0; Fri, 2 Feb 2024 15:58:40 +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=1706889521; cv=none; b=LUEmCLpak0qYw3CAaad0CUhZZlBkMGa4F0EbzEMHIGn/qd/HL2pp3nd2IP8Dibha24tW/L4UIVQfqzZRYcjwZ+W89Qi2bQ2X9iFFzY1wpiH5Gb8AtBqwtBhQaNxltOpaQ1DhryfOxaV46hBkr9IV47laTxyHxU3fRKW0jJjWty0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889521; c=relaxed/simple; bh=8wkF4aCE3aM2rNs899RXOTttKfK3DnuDTaZdLUAKOrA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JDq4Xyy14MPvM0t4SgDZDev0qqOjj47pVmeu6NrZwpstMQ8AA8Sqcy5/HdoERLp4jreXrNTVvnLVrNjg0TapXopVzzYvmWuUNb3YXu/M8q4Ge3nehjpXc/lrHlJhGZUtqa5KyFt3F+8a12CqJeB1NY5NuVi8/DYxBL7ZiQqKm0E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EtAWmj2G; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EtAWmj2G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D56A0C43394; Fri, 2 Feb 2024 15:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889520; bh=8wkF4aCE3aM2rNs899RXOTttKfK3DnuDTaZdLUAKOrA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EtAWmj2GnZ9LalaqkZJtJmN54oRDwbsmKa3ZSy+feXm/bK+8miHaLi8rLJ0KlGz17 svTAIO0xE2Ik+DZ2Vvhrag3+bOCH48ienK0/8htM5PaL0gs/4SmRNRCcqTmsZGnvmI LjGUl8x2/UgxL8QW1gPMExpWq8jy6eFZSIGoHFBRetJti4/kVh6XkllGlRcWqEmF76 f9OCQdGw4j8ILqN5FZ49QYK2qSBpAkAh4C5ZHwi+qUX7Yzp+0XBYRmMtoJj2whcAG6 qWi7q5Dw0nbZtiNhex0wQs8RI/D6n1342U+psgnRSa1g9ZRQtgK9WojsAjbTHX9+cn 85Ml7qSR1H2ew== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 09/27] kconfig: replace current_pos with separate cur_{filename,lineno} Date: Sat, 3 Feb 2024 00:58:07 +0900 Message-Id: <20240202155825.314567-10-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replace current_pos with separate variables representing the file name and the line number, respectively. No functional change is intended. By the way, you might wonder why the "" fallback exists in zconf_curname(). menu_add_symbol() saves the current file and the line number. It is intended to be called only during the yyparse() time. However, menu_finalize() calls it, where there is no file being parsed. This is a long-standing hack that should be fixed later. I left a FIXME comment. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 1bb372868ecf..540098435a3b 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -22,10 +22,14 @@ #define START_STRSIZE 16 -static struct { - struct file *file; - int lineno; -} current_pos; +/* The Kconfig file currently being parsed. */ +static const char *cur_filename; + +/* + * The line number of the current statement. This does not match yylineno. + * yylineno is used by the lexer, while cur_lineno is used by the parser. + */ +static int cur_lineno; static int prev_prev_token = T_EOL; static int prev_token = T_EOL; @@ -279,9 +283,14 @@ repeat: * of each statement. Generally, \n is a statement * terminator in Kconfig, but it is not always true * because \n could be escaped by a backslash. + * + * FIXME: + * cur_filename and cur_lineno are used even after + * yyparse(); menu_finalize() calls menu_add_symbol(). + * This should be fixed. */ - current_pos.file = current_file; - current_pos.lineno = yylineno; + cur_filename = current_file ? current_file->name : ""; + cur_lineno = yylineno; } } @@ -462,10 +471,10 @@ static void zconf_endfile(void) int zconf_lineno(void) { - return current_pos.lineno; + return cur_lineno; } const char *zconf_curname(void) { - return current_pos.file ? current_pos.file->name : ""; + return cur_filename; } From patchwork Fri Feb 2 15:58:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543104 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 C096514A4E0; Fri, 2 Feb 2024 15:58:41 +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=1706889521; cv=none; b=kDGYq9YA7x8lUd8gkpjjwHaEseP5zkq3XGQjqBiSsjP1dKnxUVsreB2gzCIEumqaDZZ/wunVc/1YnysJhOCraeTGt58ONux5lWcdqtV26Vd2cpoTef7pKTj37Qml27Ci6tRk1gm62Q4IubknJ9KJm5dV9qaSVcBoRy1+6+jN4Xg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889521; c=relaxed/simple; bh=iHM8Es9wLEFNU6sshaQjaQFTw2pijimnR0FYXBXj7F4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QSsW0SaU3mLatyyPpeLLHf/leJCCxemvt95ecdqevRhzH33idUWqyBMUxqMXu7iDKWS+dSogpEYg2FDwMCD/ytqqK+7H1lC7oRx+HbjikLCpdqaBRDuq/ccsL/aF4GOchBOKEv3oqzPhCKtJn1TsTdNQta7HZeqrn2k82KHvN+E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=p0C4So1+; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="p0C4So1+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF894C43399; Fri, 2 Feb 2024 15:58:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889521; bh=iHM8Es9wLEFNU6sshaQjaQFTw2pijimnR0FYXBXj7F4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p0C4So1+9VMNvuKisbwVe9z+KtLjpJDVG3acEzCU05Uj8F1wvC/Fw8tuA5QU9jOAU 9XRyExVSBzroC+XcUNTaRbvP7KnjxQ0fuAzCFg4BMdP1tyPLHbHjrWJLO5d9Cb55PO OLYALwt+X9PS1cMve7NS7URkvy8ehpyqfD6/CwXtQQkHWBIvnPiOYeKen1movyXNje hNmsmqb2XBB0kdxtIbe7ST8q6zHBAN1yYCdt3zFiv/37NsgJtAQwRrIA2rgRwB7cgq rT70758KUI1Y5VyHS8MN+sWZzNB1iIU0Vc9c7JR9DYYFfq0Bo1a7rGn7nlgtRz4L4V V7q4EpNBL5TWA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 10/27] kconfig: remove zconf_curname() and zconf_lineno() Date: Sat, 3 Feb 2024 00:58:08 +0900 Message-Id: <20240202155825.314567-11-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Now zconf_curname() and zconf_lineno() are so simple that they just return cur_filename, cur_lineno, respectively. Remove these functions, and then use cur_filename and cur_lineno directly. Signed-off-by: Masahiro Yamada --- scripts/kconfig/internal.h | 3 ++ scripts/kconfig/lexer.l | 20 ++++--------- scripts/kconfig/lkc.h | 2 -- scripts/kconfig/menu.c | 4 +-- scripts/kconfig/parser.y | 59 +++++++++++++++++--------------------- 5 files changed, 37 insertions(+), 51 deletions(-) diff --git a/scripts/kconfig/internal.h b/scripts/kconfig/internal.h index 2f7298c21b64..788401cd5d6f 100644 --- a/scripts/kconfig/internal.h +++ b/scripts/kconfig/internal.h @@ -6,4 +6,7 @@ struct menu; extern struct menu *current_menu, *current_entry; +extern const char *cur_filename; +extern int cur_lineno; + #endif /* INTERNAL_H */ diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 540098435a3b..3b3893f673dc 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -23,13 +23,13 @@ #define START_STRSIZE 16 /* The Kconfig file currently being parsed. */ -static const char *cur_filename; +const char *cur_filename; /* * The line number of the current statement. This does not match yylineno. * yylineno is used by the lexer, while cur_lineno is used by the parser. */ -static int cur_lineno; +int cur_lineno; static int prev_prev_token = T_EOL; static int prev_token = T_EOL; @@ -187,7 +187,7 @@ n [A-Za-z0-9_-] \n { fprintf(stderr, "%s:%d:warning: multi-line strings not supported\n", - zconf_curname(), zconf_lineno()); + cur_filename, cur_lineno); unput('\n'); BEGIN(INITIAL); yylval.string = text; @@ -423,12 +423,12 @@ void zconf_nextfile(const char *name) yyin = zconf_fopen(file->name); if (!yyin) { fprintf(stderr, "%s:%d: can't open file \"%s\"\n", - zconf_curname(), zconf_lineno(), file->name); + cur_filename, cur_lineno, file->name); exit(1); } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - current_file->lineno = zconf_lineno(); + current_file->lineno = cur_lineno; file->parent = current_file; for (iter = current_file; iter; iter = iter->parent) { @@ -468,13 +468,3 @@ static void zconf_endfile(void) current_buf = current_buf->parent; free(tmp); } - -int zconf_lineno(void) -{ - return cur_lineno; -} - -const char *zconf_curname(void) -{ - return cur_filename; -} diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 8616ad83be6d..d8249052f2e3 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -36,8 +36,6 @@ void zconf_starthelp(void); FILE *zconf_fopen(const char *name); void zconf_initscan(const char *name); void zconf_nextfile(const char *name); -int zconf_lineno(void); -const char *zconf_curname(void); /* confdata.c */ extern struct gstr autoconf_cmd; diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 2cce8b651f61..ddca95879631 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -54,7 +54,7 @@ void menu_add_entry(struct symbol *sym) menu->sym = sym; menu->parent = current_menu; menu->file = current_file; - menu->lineno = zconf_lineno(); + menu->lineno = cur_lineno; *last_entry_ptr = menu; last_entry_ptr = &menu->next; @@ -135,7 +135,7 @@ static struct property *menu_add_prop(enum prop_type type, struct expr *expr, memset(prop, 0, sizeof(*prop)); prop->type = type; prop->file = current_file; - prop->lineno = zconf_lineno(); + prop->lineno = cur_lineno; prop->menu = current_entry; prop->expr = expr; prop->visible.expr = dep; diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index ff68def09a2b..b9d7e26fc160 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -144,19 +144,19 @@ config_entry_start: T_CONFIG nonconst_symbol T_EOL { $2->flags |= SYMBOL_OPTIONAL; menu_add_entry($2); - printd(DEBUG_PARSE, "%s:%d:config %s\n", zconf_curname(), zconf_lineno(), $2->name); + printd(DEBUG_PARSE, "%s:%d:config %s\n", cur_filename, cur_lineno, $2->name); }; config_stmt: config_entry_start config_option_list { - printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:endconfig\n", cur_filename, cur_lineno); }; menuconfig_entry_start: T_MENUCONFIG nonconst_symbol T_EOL { $2->flags |= SYMBOL_OPTIONAL; menu_add_entry($2); - printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", zconf_curname(), zconf_lineno(), $2->name); + printd(DEBUG_PARSE, "%s:%d:menuconfig %s\n", cur_filename, cur_lineno, $2->name); }; menuconfig_stmt: menuconfig_entry_start config_option_list @@ -165,7 +165,7 @@ menuconfig_stmt: menuconfig_entry_start config_option_list current_entry->prompt->type = P_MENU; else zconfprint("warning: menuconfig statement without prompt"); - printd(DEBUG_PARSE, "%s:%d:endconfig\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:endconfig\n", cur_filename, cur_lineno); }; config_option_list: @@ -178,15 +178,13 @@ config_option_list: config_option: type prompt_stmt_opt T_EOL { menu_set_type($1); - printd(DEBUG_PARSE, "%s:%d:type(%u)\n", - zconf_curname(), zconf_lineno(), - $1); + printd(DEBUG_PARSE, "%s:%d:type(%u)\n", cur_filename, cur_lineno, $1); }; config_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL { menu_add_prompt(P_PROMPT, $2, $3); - printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:prompt\n", cur_filename, cur_lineno); }; config_option: default expr if_expr T_EOL @@ -194,27 +192,26 @@ config_option: default expr if_expr T_EOL menu_add_expr(P_DEFAULT, $2, $3); if ($1 != S_UNKNOWN) menu_set_type($1); - printd(DEBUG_PARSE, "%s:%d:default(%u)\n", - zconf_curname(), zconf_lineno(), + printd(DEBUG_PARSE, "%s:%d:default(%u)\n", cur_filename, cur_lineno, $1); }; config_option: T_SELECT nonconst_symbol if_expr T_EOL { menu_add_symbol(P_SELECT, $2, $3); - printd(DEBUG_PARSE, "%s:%d:select\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:select\n", cur_filename, cur_lineno); }; config_option: T_IMPLY nonconst_symbol if_expr T_EOL { menu_add_symbol(P_IMPLY, $2, $3); - printd(DEBUG_PARSE, "%s:%d:imply\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:imply\n", cur_filename, cur_lineno); }; config_option: T_RANGE symbol symbol if_expr T_EOL { menu_add_expr(P_RANGE, expr_alloc_comp(E_RANGE,$2, $3), $4); - printd(DEBUG_PARSE, "%s:%d:range\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:range\n", cur_filename, cur_lineno); }; config_option: T_MODULES T_EOL @@ -234,7 +231,7 @@ choice: T_CHOICE word_opt T_EOL menu_add_entry(sym); menu_add_expr(P_CHOICE, NULL, NULL); free($2); - printd(DEBUG_PARSE, "%s:%d:choice\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:choice\n", cur_filename, cur_lineno); }; choice_entry: choice choice_option_list @@ -246,7 +243,7 @@ choice_end: end { if (zconf_endtoken($1, "choice")) { menu_end_menu(); - printd(DEBUG_PARSE, "%s:%d:endchoice\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:endchoice\n", cur_filename, cur_lineno); } }; @@ -263,27 +260,25 @@ choice_option_list: choice_option: T_PROMPT T_WORD_QUOTE if_expr T_EOL { menu_add_prompt(P_PROMPT, $2, $3); - printd(DEBUG_PARSE, "%s:%d:prompt\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:prompt\n", cur_filename, cur_lineno); }; choice_option: logic_type prompt_stmt_opt T_EOL { menu_set_type($1); - printd(DEBUG_PARSE, "%s:%d:type(%u)\n", - zconf_curname(), zconf_lineno(), $1); + printd(DEBUG_PARSE, "%s:%d:type(%u)\n", cur_filename, cur_lineno, $1); }; choice_option: T_OPTIONAL T_EOL { current_entry->sym->flags |= SYMBOL_OPTIONAL; - printd(DEBUG_PARSE, "%s:%d:optional\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:optional\n", cur_filename, cur_lineno); }; choice_option: T_DEFAULT nonconst_symbol if_expr T_EOL { menu_add_symbol(P_DEFAULT, $2, $3); - printd(DEBUG_PARSE, "%s:%d:default\n", - zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:default\n", cur_filename, cur_lineno); }; type: @@ -305,7 +300,7 @@ default: if_entry: T_IF expr T_EOL { - printd(DEBUG_PARSE, "%s:%d:if\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:if\n", cur_filename, cur_lineno); menu_add_entry(NULL); menu_add_dep($2); $$ = menu_add_menu(); @@ -315,7 +310,7 @@ if_end: end { if (zconf_endtoken($1, "if")) { menu_end_menu(); - printd(DEBUG_PARSE, "%s:%d:endif\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:endif\n", cur_filename, cur_lineno); } }; @@ -331,7 +326,7 @@ menu: T_MENU T_WORD_QUOTE T_EOL { menu_add_entry(NULL); menu_add_prompt(P_MENU, $2, NULL); - printd(DEBUG_PARSE, "%s:%d:menu\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:menu\n", cur_filename, cur_lineno); }; menu_entry: menu menu_option_list @@ -343,7 +338,7 @@ menu_end: end { if (zconf_endtoken($1, "menu")) { menu_end_menu(); - printd(DEBUG_PARSE, "%s:%d:endmenu\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:endmenu\n", cur_filename, cur_lineno); } }; @@ -358,7 +353,7 @@ menu_option_list: source_stmt: T_SOURCE T_WORD_QUOTE T_EOL { - printd(DEBUG_PARSE, "%s:%d:source %s\n", zconf_curname(), zconf_lineno(), $2); + printd(DEBUG_PARSE, "%s:%d:source %s\n", cur_filename, cur_lineno, $2); zconf_nextfile($2); free($2); }; @@ -369,7 +364,7 @@ comment: T_COMMENT T_WORD_QUOTE T_EOL { menu_add_entry(NULL); menu_add_prompt(P_COMMENT, $2, NULL); - printd(DEBUG_PARSE, "%s:%d:comment\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:comment\n", cur_filename, cur_lineno); }; comment_stmt: comment comment_option_list @@ -384,7 +379,7 @@ comment_option_list: help_start: T_HELP T_EOL { - printd(DEBUG_PARSE, "%s:%d:help\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:help\n", cur_filename, cur_lineno); zconf_starthelp(); }; @@ -409,7 +404,7 @@ help: help_start T_HELPTEXT depends: T_DEPENDS T_ON expr T_EOL { menu_add_dep($3); - printd(DEBUG_PARSE, "%s:%d:depends on\n", zconf_curname(), zconf_lineno()); + printd(DEBUG_PARSE, "%s:%d:depends on\n", cur_filename, cur_lineno); }; /* visibility option */ @@ -548,7 +543,7 @@ static void zconfprint(const char *err, ...) { va_list ap; - fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno()); + fprintf(stderr, "%s:%d: ", cur_filename, cur_lineno); va_start(ap, err); vfprintf(stderr, err, ap); va_end(ap); @@ -560,7 +555,7 @@ static void zconf_error(const char *err, ...) va_list ap; yynerrs++; - fprintf(stderr, "%s:%d: ", zconf_curname(), zconf_lineno()); + fprintf(stderr, "%s:%d: ", cur_filename, cur_lineno); va_start(ap, err); vfprintf(stderr, err, ap); va_end(ap); @@ -569,7 +564,7 @@ static void zconf_error(const char *err, ...) static void yyerror(const char *err) { - fprintf(stderr, "%s:%d: %s\n", zconf_curname(), zconf_lineno(), err); + fprintf(stderr, "%s:%d: %s\n", cur_filename, cur_lineno, err); } static void print_quoted_string(FILE *out, const char *str) From patchwork Fri Feb 2 15:58:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543105 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 4D60C14AD07; Fri, 2 Feb 2024 15:58:42 +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=1706889523; cv=none; b=RvoqhVaLgtpxkO14FFwlM3hFVPcgLzquhcEMX/gT0FeY8cBxOZdgMUc160bv3DgjKPGfhD3deaXXkPf6IusVOM+MOw19cXQZcexYIeYAHjsEDvU80Ae52iQsounXydxIVPRHmABQoHTUFYHq6B1rxcczP4tDL63s57nZOvMnoVc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889523; c=relaxed/simple; bh=wpEp8jr15Z5cgoxaTgBZwBu3BqThuXxxzR4c/RRAaAI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BzuiSEDWgeThtnFb5yPm2h4Xp98YztDWMXFTOp7W1vvzEWP4r/jSBDO6H8GBat0w4TqfWkPrx/+tD8nRk27Y/B8T5YZBErjeVZvvVlVV8ebqbn2sFzVa6H5grAiw7sX9XXrcl9Jy8fr14zTPI//KI7nOAxEAziwOdOmeaBFC/sA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hyfdaKcq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hyfdaKcq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14412C43394; Fri, 2 Feb 2024 15:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889522; bh=wpEp8jr15Z5cgoxaTgBZwBu3BqThuXxxzR4c/RRAaAI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hyfdaKcqQxLrNJo8GO3fCAQwWA2hLH6RKVOD9Yek0w0JvBTyi0Wr6x8T0I/GBZnVl M3G+Sn7WXe1yuNQVzLl7zOEDh7l4xyJBBFL9Gj3VSZu+SFEfw9lq8h3VUCKZWjABzM GYRyLDk2OgBcQOLV6qxx34vA3S8c/8UcrF6k4hqYXKl0bhFtKPp4n1E44Up2/PBsfD vSqH8WQ8jMxgVZqnvoEnwWjTdaUDUGmQeGVDlVZifUCQHPMteja/qqEpnA/MFGlyg+ 4Hqa6qLughKdhv8jbpdZA9VK1Zi5xh4jkmBJRkjNdpL8nwgUVF6JZ5FYYylyFXFQ2U YA/LanjiXGH/A== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 11/27] kconfig: associate struct menu with file name directly Date: Sat, 3 Feb 2024 00:58:09 +0900 Message-Id: <20240202155825.314567-12-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 struct menu is linked to struct file for diagnostic purposes. It is always used to retrieve the file name through menu->file->name. Associate struct menu with the file name directly. Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 2 +- scripts/kconfig/menu.c | 6 +++--- scripts/kconfig/parser.y | 6 +++--- scripts/kconfig/qconf.cc | 2 +- scripts/kconfig/symbol.c | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index e0d866569155..e8fc85d98cdd 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -256,7 +256,7 @@ struct menu { char *help; /* The location where the menu node appears in the Kconfig files */ - struct file *file; + const char *filename; int lineno; /* For use by front ends that need to store auxiliary data */ diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index ddca95879631..5ad4d2b9fb82 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -23,7 +23,7 @@ void menu_warn(struct menu *menu, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - fprintf(stderr, "%s:%d:warning: ", menu->file->name, menu->lineno); + fprintf(stderr, "%s:%d:warning: ", menu->filename, menu->lineno); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); va_end(ap); @@ -53,7 +53,7 @@ void menu_add_entry(struct symbol *sym) memset(menu, 0, sizeof(*menu)); menu->sym = sym; menu->parent = current_menu; - menu->file = current_file; + menu->filename = cur_filename; menu->lineno = cur_lineno; *last_entry_ptr = menu; @@ -676,7 +676,7 @@ struct menu *menu_get_parent_menu(struct menu *menu) static void get_def_str(struct gstr *r, struct menu *menu) { str_printf(r, "Defined at %s:%d\n", - menu->file->name, menu->lineno); + menu->filename, menu->lineno); } static void get_dep_str(struct gstr *r, struct expr *expr, const char *prefix) diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index b9d7e26fc160..d1d05c8cd89d 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -101,7 +101,7 @@ struct menu *current_menu, *current_entry; %destructor { fprintf(stderr, "%s:%d: missing end statement for this entry\n", - $$->file->name, $$->lineno); + $$->filename, $$->lineno); if (current_menu == $$) menu_end_menu(); } if_entry menu_entry choice_entry @@ -527,11 +527,11 @@ static bool zconf_endtoken(const char *tokenname, yynerrs++; return false; } - if (current_menu->file != current_file) { + if (strcmp(current_menu->filename, cur_filename)) { zconf_error("'%s' in different file than '%s'", tokenname, expected_tokenname); fprintf(stderr, "%s:%d: location of the '%s'\n", - current_menu->file->name, current_menu->lineno, + current_menu->filename, current_menu->lineno, expected_tokenname); yynerrs++; return false; diff --git a/scripts/kconfig/qconf.cc b/scripts/kconfig/qconf.cc index 620a3527c767..c6c42c0f4e5d 100644 --- a/scripts/kconfig/qconf.cc +++ b/scripts/kconfig/qconf.cc @@ -1058,7 +1058,7 @@ void ConfigInfoView::menuInfo(void) stream << "

"; } - stream << "defined at " << _menu->file->name << ":" + stream << "defined at " << _menu->filename << ":" << _menu->lineno << "

"; } } diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index e9e9fb8d8674..7647e3e87cd5 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -1045,12 +1045,12 @@ static void sym_check_print_recursive(struct symbol *last_sym) if (sym_is_choice(sym)) { fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n", - menu->file->name, menu->lineno, + menu->filename, menu->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); } else if (sym_is_choice_value(sym)) { fprintf(stderr, "%s:%d:\tsymbol %s is part of choice %s\n", - menu->file->name, menu->lineno, + menu->filename, menu->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); } else if (stack->expr == &sym->dir_dep.expr) { From patchwork Fri Feb 2 15:58:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543106 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 0083314AD17; Fri, 2 Feb 2024 15:58:43 +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=1706889524; cv=none; b=MG6skY22OZ76jO0rLClWViiGwSWXs4IG7/JieSuqbVI8wp2Ag+iyMWGnpf/eFsrsj04L/VR0i2Ye7XaxQRNyEteQ3Y9LHhR61vkrVfbyQFs1PYqXv1wLv9VkWRh/UGSwJhEhYeMY90vaTE9o0A13fZRgXSq9PlmrvHshsbI0Jeg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889524; c=relaxed/simple; bh=gxW0tHjrvGhvoRdxh0sVyK7nLpSQS+pdJ3RujiPPaL8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=i1xKyf51bpgxxbrfrpDaznc+B0puwNgrOLBseI6OcISVL42sQvyic2Ty05zu+nlm9+3kMNzrmiT0kpJuVBtEmNaqDA5RnyI3xfp7BuFoTtmJc46wGQGsSXeRhqGufZj5DokQ4p22BpcIG4nq0N+Q9l6ux+rnMZUWv0+KSvm7Kfw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=haZEUMwo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="haZEUMwo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EF78C433C7; Fri, 2 Feb 2024 15:58:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889523; bh=gxW0tHjrvGhvoRdxh0sVyK7nLpSQS+pdJ3RujiPPaL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=haZEUMwoK2qxyOJAE+WGgjaRtCm2pJJSqqFFaOAutj0bG88g+6wRlPQqUJsaKOjho sJ5q8YkizICQyuM6iy/ibz2PR5eT7sIZYPVROWbeAlDPal6ev/DUJRhOIs7MZuWCTN z3ZCPFcP7rTtGFZylp5Lce3S0Yxpuj3lJju4ho5cf4j5kstVpUITCMNvpX2DHxZjsY 6gxP3/s5LbXCxUjvhF/QiMkzHBGNXsiGNhvHpBWiQntJ1II2SZY9zJf59uAkV50JZJ FwpVEnypXXQ4EGtXP3nBV+R/zReZNiLh0mcekvV5vU5lVR3ZFa8w9qXBDYqb1Hwoaq hrgOdTIp0+HQA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 12/27] kconfig: associate struct property with file name directly Date: Sat, 3 Feb 2024 00:58:10 +0900 Message-Id: <20240202155825.314567-13-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 struct property is linked to struct file for diagnostic purposes. It is always used to retrieve the file name through prop->file->name. Associate struct property with the file name directly. Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 2 +- scripts/kconfig/menu.c | 4 ++-- scripts/kconfig/symbol.c | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index e8fc85d98cdd..037db39c5bf0 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -195,7 +195,7 @@ struct property { struct menu *menu; /* the menu the property are associated with * valid for: P_SELECT, P_RANGE, P_CHOICE, * P_PROMPT, P_DEFAULT, P_MENU, P_COMMENT */ - struct file *file; /* what file was this property defined */ + const char *filename; /* what file was this property defined */ int lineno; /* what lineno was this property defined */ }; diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 5ad4d2b9fb82..0ded0b1830d0 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -33,7 +33,7 @@ static void prop_warn(struct property *prop, const char *fmt, ...) { va_list ap; va_start(ap, fmt); - fprintf(stderr, "%s:%d:warning: ", prop->file->name, prop->lineno); + fprintf(stderr, "%s:%d:warning: ", prop->filename, prop->lineno); vfprintf(stderr, fmt, ap); fprintf(stderr, "\n"); va_end(ap); @@ -134,7 +134,7 @@ static struct property *menu_add_prop(enum prop_type type, struct expr *expr, prop = xmalloc(sizeof(*prop)); memset(prop, 0, sizeof(*prop)); prop->type = type; - prop->file = current_file; + prop->filename = cur_filename; prop->lineno = cur_lineno; prop->menu = current_entry; prop->expr = expr; diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 7647e3e87cd5..dae630a74e50 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -1041,7 +1041,7 @@ static void sym_check_print_recursive(struct symbol *last_sym) } if (stack->sym == last_sym) fprintf(stderr, "%s:%d:error: recursive dependency detected!\n", - prop->file->name, prop->lineno); + prop->filename, prop->lineno); if (sym_is_choice(sym)) { fprintf(stderr, "%s:%d:\tchoice %s contains symbol %s\n", @@ -1055,28 +1055,28 @@ static void sym_check_print_recursive(struct symbol *last_sym) next_sym->name ? next_sym->name : ""); } else if (stack->expr == &sym->dir_dep.expr) { fprintf(stderr, "%s:%d:\tsymbol %s depends on %s\n", - prop->file->name, prop->lineno, + prop->filename, prop->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); } else if (stack->expr == &sym->rev_dep.expr) { fprintf(stderr, "%s:%d:\tsymbol %s is selected by %s\n", - prop->file->name, prop->lineno, + prop->filename, prop->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); } else if (stack->expr == &sym->implied.expr) { fprintf(stderr, "%s:%d:\tsymbol %s is implied by %s\n", - prop->file->name, prop->lineno, + prop->filename, prop->lineno, sym->name ? sym->name : "", next_sym->name ? next_sym->name : ""); } else if (stack->expr) { fprintf(stderr, "%s:%d:\tsymbol %s %s value contains %s\n", - prop->file->name, prop->lineno, + prop->filename, prop->lineno, sym->name ? sym->name : "", prop_get_type_name(prop->type), next_sym->name ? next_sym->name : ""); } else { fprintf(stderr, "%s:%d:\tsymbol %s %s is visible depending on %s\n", - prop->file->name, prop->lineno, + prop->filename, prop->lineno, sym->name ? sym->name : "", prop_get_type_name(prop->type), next_sym->name ? next_sym->name : ""); From patchwork Fri Feb 2 15:58:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543107 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 79229146916; Fri, 2 Feb 2024 15:58:45 +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=1706889525; cv=none; b=jJSjd8Z/hae/rwvbIzxusJF9/yFHKFZ4DCYdwJs8MTtYBE3/2Q77gLMgCmX2hZ9sTfF+5LhdTVn1NGqtqeel5qM0JuGj3GvfvWaA8LfuyWkUWlqszWeBwKCeXRjJmkxTrCm0sqJYl/7TQNhTHANDZYQYIBF1i3NrDlv0Ee85UJo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889525; c=relaxed/simple; bh=3mNf0ZSZTDvEBfE5C19X3m4Dwgk1+kn+7smzF28GagI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s9nkBG7it1P5pDRky9Moqmflh2YkpbWO+Cbh+m820nwk/+5UJafvRrsUqiclou+15T8T49QELilj5Jza/aEjsnRjrJ3o55ElQP3vphIhE8FKG/hgcI3PQ9kcGmPgqsMZVEFOs3R1Y2sBAu0Qd7lmDbL/iArY/l/HyNiIuWOfVds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lt21hQpl; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lt21hQpl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49ECBC43390; Fri, 2 Feb 2024 15:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889524; bh=3mNf0ZSZTDvEBfE5C19X3m4Dwgk1+kn+7smzF28GagI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lt21hQplVb5hpQcN3B1YGxA27O40fqtkxEjJknCLhtioRhIMsTNmsb2AaIeWKOaTB Y4f8jNCpoET6elOnrKzGV5o19M3YyeAiJn872n6ngh9D6m8QOMm2wtlai2wuap1aGN oV9tD0Ny4rsv+vCq6fY69G2Zy4vxnoy9SRRlu8A7PpDB0pJDom37XqBJxtiEGzv/Nw K4oM3fpAH+dRbd+SBKgTOsk31SoNWBy98uCB3uuvDPxt5s0kF4J+RzkrME80gtZlNi 1ZC+5LmxzFpsP/d7YNQ0cXArHQ2TR90yD/q+IJgRda+P0tOJPTReTHSsenHzpME11d sMjETBZ+AetuQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 13/27] kconfig: replace file->name with name in zconf_nextfile() Date: Sat, 3 Feb 2024 00:58:11 +0900 Message-Id: <20240202155825.314567-14-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The 'file->name' and 'name' are the same in this function. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 3b3893f673dc..35ad1b256470 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -420,10 +420,10 @@ void zconf_nextfile(const char *name) buf->yylineno = yylineno; buf->parent = current_buf; current_buf = buf; - yyin = zconf_fopen(file->name); + yyin = zconf_fopen(name); if (!yyin) { fprintf(stderr, "%s:%d: can't open file \"%s\"\n", - cur_filename, cur_lineno, file->name); + cur_filename, cur_lineno, name); exit(1); } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); @@ -432,17 +432,17 @@ void zconf_nextfile(const char *name) file->parent = current_file; for (iter = current_file; iter; iter = iter->parent) { - if (!strcmp(iter->name, file->name)) { + if (!strcmp(iter->name, name)) { fprintf(stderr, "Recursive inclusion detected.\n" "Inclusion path:\n" - " current file : %s\n", file->name); + " current file : %s\n", name); iter = file; do { iter = iter->parent; fprintf(stderr, " included from: %s:%d\n", iter->name, iter->lineno); - } while (strcmp(iter->name, file->name)); + } while (strcmp(iter->name, name)); exit(1); } } From patchwork Fri Feb 2 15:58:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543108 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 363DE14C592; Fri, 2 Feb 2024 15:58:46 +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=1706889526; cv=none; b=OdcD5WW3hss7KKmdx7z45yWZKSCpZV3Mahjaxeamc3T/PJAmzbslRHnXGP5s+X8Pa0BhHQkEnnqKNgABBIBH2gTFukYJLmzceZD8kyjCrBWk7/7fIGjHjjulVNljNZAF/s6X/BiEPJBLBdWtCfNyoZclQOv9xmH/fmcibXQl3DA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889526; c=relaxed/simple; bh=wHVLJm31U+fA47auTd9+uU0toq5m5ICZ6w8E0bowFB4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oIYcfXroHojkMMwMJ1BtujEeGeVhzhUNuz2fs3jCODmHydDrl0GNGzs7jK5U5L2lJyhKuyiCtgk2IOTww6o4eBqmGSnGqZ1+R0AAgRY/Q4++D3JiQ9DKy8x3i3p4172xcik9dXKspT3Abc58wzM7T6rvpt3is39L3orhVxG/IJA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JCMA1Rn8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JCMA1Rn8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 64F8AC433F1; Fri, 2 Feb 2024 15:58:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889526; bh=wHVLJm31U+fA47auTd9+uU0toq5m5ICZ6w8E0bowFB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JCMA1Rn8MXKR7+56P3lyywwXtbccGzQZOw5FBgWPErFILpiZ0uSjyFghWApxHNGUh OnOktXn61WWGGT3uDO99/3EFVQYYBcbIoTL2aLOR5EDjiyw87BMO9+/VwdE7ZdgAfU TFIJHl0crcCB3RnriYixGgQsGJXfHQ24eIvWa34KW57CP4dk0WibbrU/kqjMWRuojw lDDzqTjr5thlDu/8kvZsSzjVmtk6m14f60pqLOglw1INbYZkKqZhEUP8UplL5bXun7 eIZauYpw3kewrzGTmRpu9jIEx3PRp+bnL3UD8esWOXjPvwIY74JvMssFZoU9x1z9Bz zXynzYixu/vNA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 14/27] kconfig: do not delay the cur_filename update Date: Sat, 3 Feb 2024 00:58:12 +0900 Message-Id: <20240202155825.314567-15-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, cur_filename is updated at the first token of each statement. However, this seems unnecessary based on my understanding; the parser can use the same variable as the lexer tracks. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 17 +++++++---------- scripts/kconfig/parser.y | 8 ++++++++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 35ad1b256470..28e279cd5a22 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -274,24 +274,17 @@ repeat: token = yylex1(); if (prev_token == T_EOL || prev_token == T_HELPTEXT) { - if (token == T_EOL) { + if (token == T_EOL) /* Do not pass unneeded T_EOL to the parser. */ goto repeat; - } else { + else /* - * For the parser, update file/lineno at the first token + * For the parser, update lineno at the first token * of each statement. Generally, \n is a statement * terminator in Kconfig, but it is not always true * because \n could be escaped by a backslash. - * - * FIXME: - * cur_filename and cur_lineno are used even after - * yyparse(); menu_finalize() calls menu_add_symbol(). - * This should be fixed. */ - cur_filename = current_file ? current_file->name : ""; cur_lineno = yylineno; - } } if (prev_prev_token == T_EOL && prev_token == T_WORD && @@ -407,6 +400,7 @@ void zconf_initscan(const char *name) } current_file = file_lookup(name); + cur_filename = current_file->name; yylineno = 1; } @@ -448,6 +442,7 @@ void zconf_nextfile(const char *name) } yylineno = 1; + cur_filename = file->name; current_file = file; } @@ -456,6 +451,8 @@ static void zconf_endfile(void) struct buffer *tmp; current_file = current_file->parent; + if (current_file) + cur_filename = current_file->name; if (!current_buf) return; diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index d1d05c8cd89d..e58c24d2e5ab 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -488,6 +488,14 @@ void conf_parse(const char *name) yydebug = 1; yyparse(); + /* + * FIXME: + * cur_filename and cur_lineno are used even after yyparse(); + * menu_finalize() calls menu_add_symbol(). This should be fixed. + */ + cur_filename = ""; + cur_lineno = 0; + str_printf(&autoconf_cmd, "\n" "$(autoconfig): $(deps_config)\n" From patchwork Fri Feb 2 15:58:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543109 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 5000F14C5BA; Fri, 2 Feb 2024 15:58:47 +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=1706889527; cv=none; b=o4+wSrR1oYYrWqMFB9/ziEqKH+o0+OTc5tcWMUQm543MCiRsBPvc39OthNbHYyH7BD3Nwn48vHfU+2r8XdUWKsgW+2jDFtFzQIGdsx7+uSAee681jQKBr5bVDKBRbYREmGTzU3vICf2F8yp43cGBG+MGkafoQsGjv1di3XQU7qs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889527; c=relaxed/simple; bh=iQfJFbCfo6g+jL93vYCPjdUyp6aRJx+Zc0bUp6Uw6sQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A4f5E0y/wi7hBk17YH/EaMLHnAdhIrL1shc6NesxIN7WL0YY09H5QHqjRtqJFKt3gbYkGv443fuuMLgp9Dv8kYiE9CvI2AkJ1qj86xVuBR2XULVEtBgEBT6w4AoX8UOyfMZMUOB8WtSXZGMLYN0iJyCNuF4LV1iPVqYHj46cpLM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q+pSyziy; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="q+pSyziy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80171C43399; Fri, 2 Feb 2024 15:58:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889527; bh=iQfJFbCfo6g+jL93vYCPjdUyp6aRJx+Zc0bUp6Uw6sQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q+pSyziySnu8Lju8MA/luc1F9M6N3CrRz4pHXOEMWnZXGqN5iYhwHBWgOktnOqE1R i7dHfKfihIoTBvE47kKMInfeaDOLQFPHdA7vWX5tRq/la63RVmqdPI6ZIHe+0dbnR9 pooakkKDIAc6ljG1mZYRr0EzjLN5HimPYRGQDubE7IGx4iIrlH21Jx5wN+8QU42Qnn W+x3w+87KpYfsRei5OI5Z5Z9VqcWUFgUTHWIGWtDs11PHQHGiR3f/4Q0FkAmBjCjQU ie3gcXs2gKlaO+DIylXw+TCj7MKXYrZLsZ6NLU3aK4uipyrXRjUJ2O2GoUGQvXl7ui YOz6a36G4Z9Fw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 15/27] kconfig: replace remaining current_file->name with cur_filename Date: Sat, 3 Feb 2024 00:58:13 +0900 Message-Id: <20240202155825.314567-16-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Replace the remaining current_file->name in the lexer context. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 4 ++-- scripts/kconfig/preprocess.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 28e279cd5a22..db2397c4e343 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -84,7 +84,7 @@ static void warn_ignored_character(char chr) { fprintf(stderr, "%s:%d:warning: ignoring unsupported character '%c'\n", - current_file->name, yylineno, chr); + cur_filename, yylineno, chr); } %} @@ -253,7 +253,7 @@ n [A-Za-z0-9_-] if (prev_token != T_EOL && prev_token != T_HELPTEXT) fprintf(stderr, "%s:%d:warning: no new line at end of file\n", - current_file->name, yylineno); + cur_filename, yylineno); if (current_file) { zconf_endfile(); diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 12665b981c3e..69b806a6d8b7 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -9,6 +9,7 @@ #include #include +#include "internal.h" #include "list.h" #include "lkc.h" #include "preprocess.h" @@ -22,7 +23,7 @@ static void __attribute__((noreturn)) pperror(const char *format, ...) { va_list ap; - fprintf(stderr, "%s:%d: ", current_file->name, yylineno); + fprintf(stderr, "%s:%d: ", cur_filename, yylineno); va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); @@ -123,7 +124,7 @@ static char *do_error_if(int argc, char *argv[]) static char *do_filename(int argc, char *argv[]) { - return xstrdup(current_file->name); + return xstrdup(cur_filename); } static char *do_info(int argc, char *argv[]) @@ -185,8 +186,7 @@ static char *do_shell(int argc, char *argv[]) static char *do_warning_if(int argc, char *argv[]) { if (!strcmp(argv[0], "y")) - fprintf(stderr, "%s:%d: %s\n", - current_file->name, yylineno, argv[1]); + fprintf(stderr, "%s:%d: %s\n", cur_filename, yylineno, argv[1]); return xstrdup(""); } From patchwork Fri Feb 2 15:58:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543110 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 C060D14D44A; Fri, 2 Feb 2024 15:58:48 +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=1706889528; cv=none; b=vGlH9TsSE/tRJ+ywiiaT5NYZj8a4j0EykBecXIyKxZKtutsXWJJjJGLglRVN1MoHuDuuaTGVU+tv5U4xDgCsPnCxG9rN0TEPS4727OX6iBeulwELS/IjTpjl+w4w0rjK5CBzlpecCfqOol/EKCfYPKtfEiPHYAQ8ubkkRa1HMjA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889528; c=relaxed/simple; bh=XGcvVEbpwvjpyVs7c6B8hKp1bvuUZzxnFMzXDLqk/JQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VPNiRrLPU/jPSnV/SCOyBZ6g22DKKGTKBYabJ/orl5DZJAVcuTGTZMV9ilqb/G3JzoMIwumxTYCI+iJHs77HK5p4CvHLlHR3Uje0HfHKTYpGTOec67tQsS+ECwYwkwJhlovnTd3ZeaZO3hJhEf3ToRRdpozwpp4W0j/L1CgWWHw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dzabgXpC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dzabgXpC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AD2EC433F1; Fri, 2 Feb 2024 15:58:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889528; bh=XGcvVEbpwvjpyVs7c6B8hKp1bvuUZzxnFMzXDLqk/JQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dzabgXpCqPZGOOmY2HjYfoRaQDHhH7gXNlUAfg2P6hpRiGf6F3shxQfVIzl6C6H8V H629bnB/SwuPIYgpAW4laXhFoErIRoCJPjwTxtVtFuyk/mgAtUpgucIM5BRtFg5ihl R3bhViG2PdiimUVEWaF5M/Alv8ybNbdikVc7M2dh0dxaGtMZgRbrRlF3KTXnF2EIdn L392q5NJZ8paAoI1TBlbTXvE+uFQ93YTVTdEmxTGWUBKtP2pUhfXjBGyV0E1HNe3tG tJ/A4brR7IGKyHS7OII9DgpSZlCXigSn0aZ80ULa8jqLimKyMY7jtqLi14Y0Kch4uu owQfRWCOAHwEw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 16/27] kconfig: move the file and lineno in struct file to struct buffer Date: Sat, 3 Feb 2024 00:58:14 +0900 Message-Id: <20240202155825.314567-17-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 struct file has two link nodes, 'next' and 'parent'. The former is used to link files in the 'file_list' linked list, which manages the list of Kconfig files seen so far. The latter is used to link files in the 'current_file' linked list, which manages the inclusion ("source") tree. The latter should be tracked together with the lexer state. Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 3 --- scripts/kconfig/lexer.l | 50 ++++++++++++++++++----------------------- scripts/kconfig/menu.c | 1 - 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 037db39c5bf0..85e0d1ab3c8a 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -19,9 +19,7 @@ extern "C" { struct file { struct file *next; - struct file *parent; const char *name; - int lineno; }; typedef enum tristate { @@ -278,7 +276,6 @@ struct jump_key { }; extern struct file *file_list; -extern struct file *current_file; extern struct symbol symbol_yes, symbol_no, symbol_mod; extern struct symbol *modules_sym; diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index db2397c4e343..71f651bb82ba 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -40,6 +40,8 @@ struct buffer { struct buffer *parent; YY_BUFFER_STATE state; int yylineno; + const char *filename; + int source_lineno; }; static struct buffer *current_buf; @@ -255,7 +257,7 @@ n [A-Za-z0-9_-] fprintf(stderr, "%s:%d:warning: no new line at end of file\n", cur_filename, yylineno); - if (current_file) { + if (current_buf) { zconf_endfile(); return T_EOL; } @@ -399,19 +401,20 @@ void zconf_initscan(const char *name) exit(1); } - current_file = file_lookup(name); - cur_filename = current_file->name; + cur_filename = file_lookup(name)->name; yylineno = 1; } void zconf_nextfile(const char *name) { - struct file *iter; struct file *file = file_lookup(name); struct buffer *buf = xmalloc(sizeof(*buf)); + bool recur_include = false; buf->state = YY_CURRENT_BUFFER; buf->yylineno = yylineno; + buf->filename = cur_filename; + buf->source_lineno = cur_lineno; buf->parent = current_buf; current_buf = buf; yyin = zconf_fopen(name); @@ -422,45 +425,36 @@ void zconf_nextfile(const char *name) } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - current_file->lineno = cur_lineno; - file->parent = current_file; + for (buf = current_buf; buf; buf = buf->parent) { + if (!strcmp(buf->filename, name)) + recur_include = true; + } - for (iter = current_file; iter; iter = iter->parent) { - if (!strcmp(iter->name, name)) { - fprintf(stderr, - "Recursive inclusion detected.\n" - "Inclusion path:\n" - " current file : %s\n", name); - iter = file; - do { - iter = iter->parent; - fprintf(stderr, " included from: %s:%d\n", - iter->name, iter->lineno); - } while (strcmp(iter->name, name)); - exit(1); - } + if (recur_include) { + fprintf(stderr, + "Recursive inclusion detected.\n" + "Inclusion path:\n" + " current file : %s\n", name); + + for (buf = current_buf; buf; buf = buf->parent) + fprintf(stderr, " included from: %s:%d\n", + buf->filename, buf->source_lineno); + exit(1); } yylineno = 1; cur_filename = file->name; - current_file = file; } static void zconf_endfile(void) { struct buffer *tmp; - current_file = current_file->parent; - if (current_file) - cur_filename = current_file->name; - - if (!current_buf) - return; - fclose(yyin); yy_delete_buffer(YY_CURRENT_BUFFER); yy_switch_to_buffer(current_buf->state); yylineno = current_buf->yylineno; + cur_filename = current_buf->filename; tmp = current_buf; current_buf = current_buf->parent; free(tmp); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 0ded0b1830d0..b879576d1ab4 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -17,7 +17,6 @@ struct menu rootmenu; static struct menu **last_entry_ptr; struct file *file_list; -struct file *current_file; void menu_warn(struct menu *menu, const char *fmt, ...) { From patchwork Fri Feb 2 15:58:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543111 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZpRuZ5dP" 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 To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada 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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Call malloc() just once to allocate needed memory. Signed-off-by: Masahiro Yamada --- 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; From patchwork Fri Feb 2 15:58:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543112 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 9C1C91474CF; Fri, 2 Feb 2024 15:58:50 +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=1706889530; cv=none; b=Df1xGNeHmxIjyKq0I4aOVqjnordNutv5/neGb0ffFABc9qdJ2ua0Mb37u668Tg8q2d3uhNhd07xpxck9/yc0j5EuRzvuvL+jgIdJZsMO13LpRy+Np/4IilIte1N53/SgFGxqZGPYXVbmy7L0D4VHNXkegkmEOlTmyMUl/YRTxVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889530; c=relaxed/simple; bh=peshsf7E5lCNRV8+zJr6/ajkl2ZpyVwBUVUkykrK4Hk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kvUatAVbEJtOdqoQ00CNq6i24+RtTI94e6F5nGjJttEgQu3X0Q5Auqf8UoFcIMBBLJnvNWvqbC1BcDUowlW3MDOhJscU7GRDebwD1GuBPEkjycJkLBMFs7MUkFubvYCI0hZnMuty/aArzdXmguyYwWRs95oV1GQlFHca2VxZYrY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U5hexQDB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="U5hexQDB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB573C433F1; Fri, 2 Feb 2024 15:58:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889530; bh=peshsf7E5lCNRV8+zJr6/ajkl2ZpyVwBUVUkykrK4Hk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U5hexQDBI2JZxNkl1U0WzrOHVbWR5yUFkSZTnMNyoaK8jpz1fbdNxgWRsdrmPwsfO zFI416IPRWrUvtONVxEcRpvdV4mG1sLe67QTZfl0CvfZaYUD+fiR3Rgl18uRev9PwF 4lf1/A3btCeCMr1UeU+QRIvM6rk8M8QEk4aKbMIDlcL3P8nlI8GfQs047swEzMCd4+ OP9xrDGEDxTll/Uc5M+eNoaRX5nrQBKAuxSnuxjhsquX1zAyqyYQK4Nb3loZZ1kTJ/ ZNhRs7f9yBhhD1K6yqYruJVytpWNyaCHaWBvWBYFz1dwA+4E3X+YMJUXSN2SQDgJuG fYmvHc9upPitg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 18/27] kconfig: change file_lookup() to return the file name Date: Sat, 3 Feb 2024 00:58:16 +0900 Message-Id: <20240202155825.314567-19-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, file_lookup() returns a pointer to (struct file), but the callers use only file->name. Make it return the ->name member directly. This adjustment encapsulates struct file and file_list as internal implementation. Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 7 ------- scripts/kconfig/lexer.l | 5 ++--- scripts/kconfig/lkc.h | 2 +- scripts/kconfig/menu.c | 2 -- scripts/kconfig/util.c | 13 ++++++++++--- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index 760b1e681b43..d667f9aa041e 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -17,11 +17,6 @@ extern "C" { #include #endif -struct file { - struct file *next; - char name[]; -}; - typedef enum tristate { no, mod, yes } tristate; @@ -275,8 +270,6 @@ struct jump_key { struct menu *target; }; -extern struct file *file_list; - extern struct symbol symbol_yes, symbol_no, symbol_mod; extern struct symbol *modules_sym; extern int cdebug; diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index 71f651bb82ba..89544c3a1a29 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -401,13 +401,12 @@ void zconf_initscan(const char *name) exit(1); } - cur_filename = file_lookup(name)->name; + cur_filename = file_lookup(name); yylineno = 1; } void zconf_nextfile(const char *name) { - struct file *file = file_lookup(name); struct buffer *buf = xmalloc(sizeof(*buf)); bool recur_include = false; @@ -443,7 +442,7 @@ void zconf_nextfile(const char *name) } yylineno = 1; - cur_filename = file->name; + cur_filename = file_lookup(name); } static void zconf_endfile(void) diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index d8249052f2e3..71afcbd56273 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -52,7 +52,7 @@ static inline void xfwrite(const void *str, size_t len, size_t count, FILE *out) } /* util.c */ -struct file *file_lookup(const char *name); +const char *file_lookup(const char *name); void *xmalloc(size_t size); void *xcalloc(size_t nmemb, size_t size); void *xrealloc(void *p, size_t size); diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index b879576d1ab4..f701382f8a69 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -16,8 +16,6 @@ static const char nohelp_text[] = "There is no help available for this option."; struct menu rootmenu; static struct menu **last_entry_ptr; -struct file *file_list; - void menu_warn(struct menu *menu, const char *fmt, ...) { va_list ap; diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 2636dccea0c9..610d64c01479 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -9,15 +9,22 @@ #include #include "lkc.h" +struct file { + struct file *next; + char name[]; +}; + +static struct file *file_list; + /* file already present in list? If not add it */ -struct file *file_lookup(const char *name) +const char *file_lookup(const char *name) { struct file *file; size_t len; for (file = file_list; file; file = file->next) { if (!strcmp(name, file->name)) { - return file; + return file->name; } } @@ -31,7 +38,7 @@ struct file *file_lookup(const char *name) str_printf(&autoconf_cmd, "\t%s \\\n", name); - return file; + return file->name; } /* Allocate initial growable string */ From patchwork Fri Feb 2 15:58:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543113 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 18D66150990; Fri, 2 Feb 2024 15:58:51 +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=1706889532; cv=none; b=pq/5SxPv+g6M8jDAhCcArW55f3akWTKaXdJJxMc2k/zb2WpFDtvsNdYA37fRZ7BABpnH7tEzrmZ8gUryBVwbPmccd/nqQ+DpbE4l+Jg0afwUkV0ng8ekbm5M6jrJU4YmxyAw6cSvqXgUwaAlQ+wn98K/RG4V9iKF566qIoMZunw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889532; c=relaxed/simple; bh=76DEmVP3xis53Bi0cuns0W32xsS7/RdTiZMSnNHJaCY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=fB8YxU3rUNkbncfzCXGTQzCfYpY8Y1DbSf4F97qq5HyEO8AkrPiSF3E0z1J5jCFDruuUg3x11ElEXD2vBF82YID6N9VS3foF3iMwMbVGOkaImTuw6WVmAdcb6cL20mK6Vu+xnGCSbzWAExOnz7rEERUpLgFQR73Hr48mdNzeR8c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=poIKS+Vs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="poIKS+Vs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E5C4CC433F1; Fri, 2 Feb 2024 15:58:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889531; bh=76DEmVP3xis53Bi0cuns0W32xsS7/RdTiZMSnNHJaCY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=poIKS+VsPlvvmjlBlcFPyftfEr6ROrXS/D7HBZpDXhc2SiwfqLnd8vhSq8OMXQBuD tEddaSQ4LJuXxSnHq07B2WVPqAstQPOuqcdvGQL8uYWAiBT9ifHZ2vFKCOVya+fZ4m BJfwGDFN+UcVh30jigSQ7DmJ2+pNZOV4MsSNXr2pZYyYAl4bq7URsKIIzwQHt3+gxh +wmXglxNZCyNJPhq0jZZ3xH4jsaEzkljvqH6ODzZW1R6D7v6oNClxUqE94o/ysDKvO 0TzLdQIHdOXdCcVNbLzgxtHxkWH8/ZbMEMtH7yhUZ/M0C/IhGwodLouk9576sDJoyZ zSHjrQAE5ow1w== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 19/27] kconfig: split list_head into a separate header Date: Sat, 3 Feb 2024 00:58:17 +0900 Message-Id: <20240202155825.314567-20-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The struct list_head is often embedded in other structures, while other code is used in C functions. By separating struct list_head into its own header, other headers are no longer required to include the entire list.h. This is similar to the kernel space, where struct list_head is defined in instead of . Signed-off-by: Masahiro Yamada --- scripts/kconfig/expr.h | 2 +- scripts/kconfig/list.h | 8 ++------ scripts/kconfig/list_types.h | 9 +++++++++ scripts/kconfig/mconf.c | 1 + scripts/kconfig/menu.c | 1 + scripts/kconfig/nconf.c | 1 + 6 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 scripts/kconfig/list_types.h diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index d667f9aa041e..dd3350aed302 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -12,7 +12,7 @@ extern "C" { #include #include -#include "list.h" +#include "list_types.h" #ifndef __cplusplus #include #endif diff --git a/scripts/kconfig/list.h b/scripts/kconfig/list.h index 45cb237ab7ef..babed0baf4ae 100644 --- a/scripts/kconfig/list.h +++ b/scripts/kconfig/list.h @@ -2,6 +2,8 @@ #ifndef LIST_H #define LIST_H +#include "list_types.h" + /* * Copied from include/linux/... */ @@ -20,12 +22,6 @@ const typeof( ((type *)0)->member ) *__mptr = (ptr); \ (type *)( (char *)__mptr - offsetof(type,member) );}) - -struct list_head { - struct list_head *next, *prev; -}; - - #define LIST_HEAD_INIT(name) { &(name), &(name) } #define LIST_HEAD(name) \ diff --git a/scripts/kconfig/list_types.h b/scripts/kconfig/list_types.h new file mode 100644 index 000000000000..32899f424983 --- /dev/null +++ b/scripts/kconfig/list_types.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef LIST_TYPES_H +#define LIST_TYPES_H + +struct list_head { + struct list_head *next, *prev; +}; + +#endif /* LIST_TYPES_H */ diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c index 5df32148a869..f4bb391d50cf 100644 --- a/scripts/kconfig/mconf.c +++ b/scripts/kconfig/mconf.c @@ -19,6 +19,7 @@ #include #include +#include "list.h" #include "lkc.h" #include "lxdialog/dialog.h" #include "mnconf-common.h" diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index f701382f8a69..696803d944e0 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -10,6 +10,7 @@ #include "lkc.h" #include "internal.h" +#include "list.h" static const char nohelp_text[] = "There is no help available for this option."; diff --git a/scripts/kconfig/nconf.c b/scripts/kconfig/nconf.c index 1148163cfa7e..9d22b0f3197b 100644 --- a/scripts/kconfig/nconf.c +++ b/scripts/kconfig/nconf.c @@ -11,6 +11,7 @@ #include #include +#include "list.h" #include "lkc.h" #include "mnconf-common.h" #include "nconf.h" From patchwork Fri Feb 2 15:58:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543114 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 CFEB01509A2; Fri, 2 Feb 2024 15:58:52 +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=1706889532; cv=none; b=Zc29EWufiwbkQ4Tspsnty2XzouPgYO18e2CH1980Eq+yvwrqyPvEZaPLo1jAIk4v3UQezwY3pgyF+j48gQNSNs1aHck0a+FOKw9oWzEjo+9KoFVPUqAToP7nfgH6F1Zp4+WL11FNQDIdqcFBNVCcsW3NmNJSOYw5MHSAUcq8vtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889532; c=relaxed/simple; bh=3UkbuV1BdSBeEq4498jv1YQWyekAl1uueQ2UBHUrDPo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XkmkRz5tNLliQ1rOkwpHLQJHTv2hXG069cdaVfJsuCQU7ukhHOpj2pmhJ3Vks34FCGCPgYsEmgHkL1NWpPd8QwXkqVC7TCQADlbzwPgGMAzFl+L3kkQzjOqeIadFtTkruwJ8P7zLCo3ITMZRWJI/yRjfCiqq5N4xw6Uc7zvEQPE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b48Qze55; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b48Qze55" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B1F4C43399; Fri, 2 Feb 2024 15:58:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889532; bh=3UkbuV1BdSBeEq4498jv1YQWyekAl1uueQ2UBHUrDPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b48Qze55ui0AZMZDN8tdq1p44477owiSB94LCs/NNUhjwkhvi2bS+otpr7oq8u4ij Lnzu5zW8M8V/JF7ilIatMHRzKbujx72Iszg8VmvFKQzgPnjAf/8LYSDBlYPCYXN6ZR xUy9Bz8V9vImondApHcZHomvaRc0WUzES8KrtIOg8idxUefSb0OkO17UWMRylooKrs MnbjBn0NmczTJYZATmCVhBelTf6OOEHP3auGicWFDPZ+Jkw+aWx9kjAQsX7qUg7/U4 Kc4GZn5Y80ej3cbbOLlqnwgRr8msbLfhOTBHcyETErPNJw1pUs/Lkvv/UDf7Ys78j3 60aAx0zEjkLtg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 20/27] kconfig: resync list.h Date: Sat, 3 Feb 2024 00:58:18 +0900 Message-Id: <20240202155825.314567-21-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Update the existing macros and inline functions based on include/linux/list.h. The variable name '_new' can be reverted to 'new' because this header is no longer included from the C++ file, scripts/kconfig/qconf.cc. Signed-off-by: Masahiro Yamada --- scripts/kconfig/list.h | 183 +++++++++++++++++++++++++++-------------- 1 file changed, 121 insertions(+), 62 deletions(-) diff --git a/scripts/kconfig/list.h b/scripts/kconfig/list.h index babed0baf4ae..2bce2b8f21d1 100644 --- a/scripts/kconfig/list.h +++ b/scripts/kconfig/list.h @@ -2,25 +2,39 @@ #ifndef LIST_H #define LIST_H +#include + #include "list_types.h" -/* - * Copied from include/linux/... - */ - -#undef offsetof -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) +/* Are two types/vars the same type (ignoring qualifiers)? */ +#define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) /** * container_of - cast a member of a structure out to the containing structure - * @ptr: the pointer to the member. - * @type: the type of the container struct this is embedded in. - * @member: the name of the member within the struct. + * @ptr: the pointer to the member. + * @type: the type of the container struct this is embedded in. + * @member: the name of the member within the struct. * */ -#define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) +#define container_of(ptr, type, member) ({ \ + void *__mptr = (void *)(ptr); \ + _Static_assert(__same_type(*(ptr), ((type *)0)->member) || \ + __same_type(*(ptr), void), \ + "pointer type mismatch in container_of()"); \ + ((type *)(__mptr - offsetof(type, member))); }) + +#define LIST_POISON1 ((void *) 0x100) +#define LIST_POISON2 ((void *) 0x122) + +/* + * Circular doubly linked list implementation. + * + * Some of the internal functions ("__xxx") are useful when + * manipulating whole lists rather than single entries, as + * sometimes we already know the next/prev entries and we can + * generate better code by using them directly rather than + * using the generic single-entry routines. + */ #define LIST_HEAD_INIT(name) { &(name), &(name) } @@ -28,45 +42,16 @@ struct list_head name = LIST_HEAD_INIT(name) /** - * list_entry - get the struct for this entry - * @ptr: the &struct list_head pointer. - * @type: the type of the struct this is embedded in. - * @member: the name of the list_head within the struct. + * INIT_LIST_HEAD - Initialize a list_head structure + * @list: list_head structure to be initialized. + * + * Initializes the list_head to point to itself. If it is a list header, + * the result is an empty list. */ -#define list_entry(ptr, type, member) \ - container_of(ptr, type, member) - -/** - * list_for_each_entry - iterate over list of given type - * @pos: the type * to use as a loop cursor. - * @head: the head for your list. - * @member: the name of the list_head within the struct. - */ -#define list_for_each_entry(pos, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = list_entry(pos->member.next, typeof(*pos), member)) - -/** - * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry - * @pos: the type * to use as a loop cursor. - * @n: another type * to use as temporary storage - * @head: the head for your list. - * @member: the name of the list_head within the struct. - */ -#define list_for_each_entry_safe(pos, n, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member), \ - n = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ - pos = n, n = list_entry(n->member.next, typeof(*n), member)) - -/** - * list_empty - tests whether a list is empty - * @head: the list to test. - */ -static inline int list_empty(const struct list_head *head) +static inline void INIT_LIST_HEAD(struct list_head *list) { - return head->next == head; + list->next = list; + list->prev = list; } /* @@ -75,14 +60,14 @@ static inline int list_empty(const struct list_head *head) * This is only for internal list manipulation where we know * the prev/next entries already! */ -static inline void __list_add(struct list_head *_new, +static inline void __list_add(struct list_head *new, struct list_head *prev, struct list_head *next) { - next->prev = _new; - _new->next = next; - _new->prev = prev; - prev->next = _new; + next->prev = new; + new->next = next; + new->prev = prev; + prev->next = new; } /** @@ -93,9 +78,9 @@ static inline void __list_add(struct list_head *_new, * Insert a new entry before the specified head. * This is useful for implementing queues. */ -static inline void list_add_tail(struct list_head *_new, struct list_head *head) +static inline void list_add_tail(struct list_head *new, struct list_head *head) { - __list_add(_new, head->prev, head); + __list_add(new, head->prev, head); } /* @@ -111,8 +96,11 @@ static inline void __list_del(struct list_head *prev, struct list_head *next) prev->next = next; } -#define LIST_POISON1 ((void *) 0x00100100) -#define LIST_POISON2 ((void *) 0x00200200) +static inline void __list_del_entry(struct list_head *entry) +{ + __list_del(entry->prev, entry->next); +} + /** * list_del - deletes entry from list. * @entry: the element to delete from the list. @@ -121,8 +109,79 @@ static inline void __list_del(struct list_head *prev, struct list_head *next) */ static inline void list_del(struct list_head *entry) { - __list_del(entry->prev, entry->next); - entry->next = (struct list_head*)LIST_POISON1; - entry->prev = (struct list_head*)LIST_POISON2; + __list_del_entry(entry); + entry->next = LIST_POISON1; + entry->prev = LIST_POISON2; } -#endif + +/** + * list_empty - tests whether a list is empty + * @head: the list to test. + */ +static inline int list_empty(const struct list_head *head) +{ + return head->next == head; +} + +/** + * list_entry - get the struct for this entry + * @ptr: the &struct list_head pointer. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + */ +#define list_entry(ptr, type, member) \ + container_of(ptr, type, member) + +/** + * list_first_entry - get the first element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + * + * Note, that list is expected to be not empty. + */ +#define list_first_entry(ptr, type, member) \ + list_entry((ptr)->next, type, member) + +/** + * list_next_entry - get the next element in list + * @pos: the type * to cursor + * @member: the name of the list_head within the struct. + */ +#define list_next_entry(pos, member) \ + list_entry((pos)->member.next, typeof(*(pos)), member) + +/** + * list_entry_is_head - test if the entry points to the head of the list + * @pos: the type * to cursor + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_entry_is_head(pos, head, member) \ + (&pos->member == (head)) + +/** + * list_for_each_entry - iterate over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry(pos, head, member) \ + for (pos = list_first_entry(head, typeof(*pos), member); \ + !list_entry_is_head(pos, head, member); \ + pos = list_next_entry(pos, member)) + +/** + * list_for_each_entry_safe - iterate over list of given type. Safe against removal of list entry + * @pos: the type * to use as a loop cursor. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_head within the struct. + */ +#define list_for_each_entry_safe(pos, n, head, member) \ + for (pos = list_first_entry(head, typeof(*pos), member), \ + n = list_next_entry(pos, member); \ + !list_entry_is_head(pos, head, member); \ + pos = n, n = list_next_entry(n, member)) + +#endif /* LIST_H */ From patchwork Fri Feb 2 15:58:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543115 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 46ED01509B6; Fri, 2 Feb 2024 15:58:53 +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=1706889534; cv=none; b=WJjUxp7D6m73b3lTXrqQatYbT2IarpHN06FwMaTys1ZDRdjxBnP1g5efcN6Y4qJP0IF7ZGPWvHBzbNMMh4tbEVgBuEJ4eKTl0PIIe+yaS1NWrSOu3Yf6F1SbZ5VkYLMFLROKy0N7ZUUcbsUcb6BC+2rvSOm9EO6/NGKSxaPk1Zo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889534; c=relaxed/simple; bh=2A96WogbH0kuSA8JLvJzBsQjD8uKlSboQJQx9UBHSVM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dwLW0oOugQKEeqTizwTgdNEsganYYeljTxjHshNnxpJFebweGUEoGB6feo636GNczjbR/W49urSaOQwPk5F60N1tAR+15eUKNGOiWG/po8cRRptUs0MEb4mRbEQXNWKTkXO/N1zaf9Jg1WWyWyPv5gh37cZs0N0Qfu2tecofvVA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z/EWCSl2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Z/EWCSl2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2571CC43394; Fri, 2 Feb 2024 15:58:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889533; bh=2A96WogbH0kuSA8JLvJzBsQjD8uKlSboQJQx9UBHSVM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z/EWCSl2wBAICpgIpF3Sra8aDM769fUjPgXy22zP6Hnk9+HH6P6Em6GY9UF0trg1q REgk3P9wJ50M51fGTYcDUurjxWqD1JSZNM/yvU816xfS5+hrdnE3mPWZlnGwa3AjUo Kg/nybbp39tKyCbUUUX+L+6G2nfFbpZ+wbtDiUzXRgRu7QsgInG/eqxulvFbgQlmuF lvFy6cITEHYpaI61fN5F7FY+KTbUDpEItD0mdzs9DX2nkSNOF44+AwMMuYunEYdP3l oStfxAitf73WOmLaV/tL+jlkDf0s4brhojGMpbAVtBh3vsAW6VlIq8QVGYqoTGl+MG IpO7Hui4vz1Xw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 21/27] kconfig: import more list macros and inline functions Date: Sat, 3 Feb 2024 00:58:19 +0900 Message-Id: <20240202155825.314567-22-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Import more macros and inline functions from include/linux/list.h and include/linux/types.h. Signed-off-by: Masahiro Yamada --- scripts/kconfig/list.h | 69 ++++++++++++++++++++++++++++++++++++ scripts/kconfig/list_types.h | 8 +++++ 2 files changed, 77 insertions(+) diff --git a/scripts/kconfig/list.h b/scripts/kconfig/list.h index 2bce2b8f21d1..882859ddf9f4 100644 --- a/scripts/kconfig/list.h +++ b/scripts/kconfig/list.h @@ -70,6 +70,19 @@ static inline void __list_add(struct list_head *new, prev->next = new; } +/** + * list_add - add a new entry + * @new: new entry to be added + * @head: list head to add it after + * + * Insert a new entry after the specified head. + * This is good for implementing stacks. + */ +static inline void list_add(struct list_head *new, struct list_head *head) +{ + __list_add(new, head, head->next); +} + /** * list_add_tail - add a new entry * @new: new entry to be added @@ -114,6 +127,16 @@ static inline void list_del(struct list_head *entry) entry->prev = LIST_POISON2; } +/** + * list_is_head - tests whether @list is the list @head + * @list: the entry to test + * @head: the head of the list + */ +static inline int list_is_head(const struct list_head *list, const struct list_head *head) +{ + return list == head; +} + /** * list_empty - tests whether a list is empty * @head: the list to test. @@ -184,4 +207,50 @@ static inline int list_empty(const struct list_head *head) !list_entry_is_head(pos, head, member); \ pos = n, n = list_next_entry(n, member)) +/* + * Double linked lists with a single pointer list head. + * Mostly useful for hash tables where the two pointer list head is + * too wasteful. + * You lose the ability to access the tail in O(1). + */ + +#define HLIST_HEAD_INIT { .first = NULL } + +/** + * hlist_add_head - add a new entry at the beginning of the hlist + * @n: new entry to be added + * @h: hlist head to add it after + * + * Insert a new entry after the specified head. + * This is good for implementing stacks. + */ +static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) +{ + struct hlist_node *first = h->first; + + n->next = first; + if (first) + first->pprev = &n->next; + h->first = n; + n->pprev = &h->first; +} + +#define hlist_entry(ptr, type, member) container_of(ptr, type, member) + +#define hlist_entry_safe(ptr, type, member) \ + ({ typeof(ptr) ____ptr = (ptr); \ + ____ptr ? hlist_entry(____ptr, type, member) : NULL; \ + }) + +/** + * hlist_for_each_entry - iterate over list of given type + * @pos: the type * to use as a loop cursor. + * @head: the head for your list. + * @member: the name of the hlist_node within the struct. + */ +#define hlist_for_each_entry(pos, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member);\ + pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) + #endif /* LIST_H */ diff --git a/scripts/kconfig/list_types.h b/scripts/kconfig/list_types.h index 32899f424983..d935b7c5aa81 100644 --- a/scripts/kconfig/list_types.h +++ b/scripts/kconfig/list_types.h @@ -6,4 +6,12 @@ struct list_head { struct list_head *next, *prev; }; +struct hlist_head { + struct hlist_node *first; +}; + +struct hlist_node { + struct hlist_node *next, **pprev; +}; + #endif /* LIST_TYPES_H */ From patchwork Fri Feb 2 15:58:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543116 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 6F57415145C; Fri, 2 Feb 2024 15:58:55 +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=1706889535; cv=none; b=SMDrsfJQnlR7I1E+QClkzpZGyN/ubYzKjosspx3jy8FuBS5jXaWy4nokCBwjnVe/bflcciiMw9NbYZ3aYb5Ywm9XvosvnFHpJkxJi+K2gNOPmZ/arlbvwALPb4qIeMagTy1HYjiTQVSieZznRrxBPYeWp1DabBuiwgjdIfq/fC4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889535; c=relaxed/simple; bh=D8GL5EXe9NsGs57qE1qR40Cel+KA+fOzcvMaeqYSUEw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P0m0N8myx7OS7i9ICujsQ26zdhLHNmrS9MySJRHTZCVrg5s3pr/jiAwrgdHFKFxh2qSMZrpKYDygMqrXvA6u6/l8yYGBDJaplIZR0CFsJhVOl3eE06W0nmZ65lLi5MITKAMwR7lWHmgPRE0jxV+wS24I8cFlniv0lD/Ny+czE/A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EBF3HzlA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EBF3HzlA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42F38C43390; Fri, 2 Feb 2024 15:58:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889534; bh=D8GL5EXe9NsGs57qE1qR40Cel+KA+fOzcvMaeqYSUEw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EBF3HzlAFciTdheF83e/1eXRxiduLLwv7xiG/VW0468UcO70fbmYmNr88vjefwNE/ SMaRjSDnRn/8dmgujdNwDVC87ZzyK0IgHEPPoOt9vl/zu/WKNWprM/nnTaqQ+DzQdC 6r4xE1FWm720uABImbWFlj94W0NKEPyvaCp9bhVEL2Fvz52Cuumv+7vq7+4wZo7mI3 Q4ltRD9xYxwqYw+ej/rSXoc9kfgTQE24MArka8C/bYrJvbNy0B41v0B/6V1WnSvrTb FTHSo268/7veL8X3gOHnCl7KOzJeEIzUmq9YkYSm5/mBmsIOczTbcgbV9/xUm8WIWM prX8q2XzQWUPw== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 22/27] kconfig: add macros useful for hashtable Date: Sat, 3 Feb 2024 00:58:20 +0900 Message-Id: <20240202155825.314567-23-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This is similar to include/linux/hashtable.h, but the implementation has been simplified. Signed-off-by: Masahiro Yamada --- scripts/kconfig/hashtable.h | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 scripts/kconfig/hashtable.h diff --git a/scripts/kconfig/hashtable.h b/scripts/kconfig/hashtable.h new file mode 100644 index 000000000000..71724800d178 --- /dev/null +++ b/scripts/kconfig/hashtable.h @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef HASHTABLE_H +#define HASHTABLE_H + +#include "array_size.h" +#include "list.h" + +#define HASH_SIZE(name) (ARRAY_SIZE(name)) + +#define HASHTABLE_DECLARE(name, size) struct hlist_head name[size] + +#define HASHTABLE_DEFINE(name, size) \ + HASHTABLE_DECLARE(name, size) = \ + { [0 ... ((size) - 1)] = HLIST_HEAD_INIT } + +#define hash_head(table, key) (&(table)[(key) % HASH_SIZE(table)]) + +/** + * hash_add - add an object to a hashtable + * @table: hashtable to add to + * @node: the &struct hlist_node of the object to be added + * @key: the key of the object to be added + */ +#define hash_add(table, node, key) \ + hlist_add_head(node, hash_head(table, key)) + +/** + * hash_for_each - iterate over a hashtable + * @table: hashtable to iterate + * @obj: the type * to use as a loop cursor for each entry + * @member: the name of the hlist_node within the struct + */ +#define hash_for_each(table, obj, member) \ + for (int bkt = 0; bkt < HASH_SIZE(table); bkt++) \ + hlist_for_each_entry(obj, &table[bkt], member) + +/** + * hash_for_each_possible - iterate over all possible objects hashing to the + * same bucket + * @table: hashtable to iterate + * @obj: the type * to use as a loop cursor for each entry + * @member: the name of the hlist_node within the struct + * @key: the key of the objects to iterate over + */ +#define hash_for_each_possible(table, obj, member, key) \ + hlist_for_each_entry(obj, hash_head(table, key), member) + +#endif /* HASHTABLE_H */ From patchwork Fri Feb 2 15:58:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543117 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 2F8BE15146A; Fri, 2 Feb 2024 15:58:56 +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=1706889536; cv=none; b=KHPs+jMNNYWh/ls5ITFYvKqyZh8oZjnW/Nenk6hVzBOcSoIx11bwX7xigyrm9TCaWKmOtuGAaS8UJBTSljhwmCrqPOB25wAHmRXDtIrRsoz7+9WdJqtEgx4iCigBXwJ2aGSC+g9O+KS8z4QRFzaJfetGbeRmmQNzBpI06xBRoPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889536; c=relaxed/simple; bh=LeeYFsCIF6jDZaXspMRRLlPcTtCrfxsxcxXxfVfjmc0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HIw0vTeqA0D/XXCm+xaCB/sq8kZZj4xMz0RCd0D8akkbcKjHjREX4DbIdYWCgP2BBS0Y3YkRAZQeROVB5rVA2bFfrDok3xz52jRsAN8NAzlImJolXD5vZHrmXQ5E4g4RWBnjKFwbkCGcPxSOgxdqNauJEqnfCaz62vggGxpTeyI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Kkc9Q6OS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Kkc9Q6OS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61B4DC433F1; Fri, 2 Feb 2024 15:58:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889536; bh=LeeYFsCIF6jDZaXspMRRLlPcTtCrfxsxcxXxfVfjmc0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kkc9Q6OSx+NQaYN1sXTTciCIjpY02DiMrnw3OleDHjk5VD+kSkBImHGMcgWf/1iDh sMgA/LQnwK3mdSpWUsvTs5dmDQwX7R0MBhkIVfBqvnX9Qwl59R+jg4bXCKPvgeZVak /S1sGv4hGcko/u24kLpl2bCnT5FLovzT5GUL0PWgbNme/msrogeqVc2S/NMxbCrvfw 1dTeNrlvZohRQ2iXm1aMuecrCBYziAbXPHt7e3bq/bDPD/WqW3XTAVfzK56Jkh/LO4 nolyr+Zxu2erGeuKFNyWtmzsTxP1ipokaw1q11yag58BiT0FBo+lby705ywg/QqqS9 p+LB6iGLYFwew== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 23/27] kconfig: move ARRAY_SIZE to a header Date: Sat, 3 Feb 2024 00:58:21 +0900 Message-Id: <20240202155825.314567-24-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To use ARRAY_SIZE from other files, move it to its own header, just like include/linux/array_size.h. Signed-off-by: Masahiro Yamada --- scripts/kconfig/array_size.h | 11 +++++++++++ scripts/kconfig/preprocess.c | 3 +-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 scripts/kconfig/array_size.h diff --git a/scripts/kconfig/array_size.h b/scripts/kconfig/array_size.h new file mode 100644 index 000000000000..26ba78d867d1 --- /dev/null +++ b/scripts/kconfig/array_size.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef ARRAY_SIZE_H +#define ARRAY_SIZE_H + +/** + * ARRAY_SIZE - get the number of elements in array @arr + * @arr: array to be sized + */ +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) + +#endif /* ARRAY_SIZE_H */ diff --git a/scripts/kconfig/preprocess.c b/scripts/kconfig/preprocess.c index 69b806a6d8b7..f0a4a218c4a5 100644 --- a/scripts/kconfig/preprocess.c +++ b/scripts/kconfig/preprocess.c @@ -9,13 +9,12 @@ #include #include +#include "array_size.h" #include "internal.h" #include "list.h" #include "lkc.h" #include "preprocess.h" -#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) - static char *expand_string_with_args(const char *in, int argc, char *argv[]); static char *expand_string(const char *in); From patchwork Fri Feb 2 15:58:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543118 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 4AD66151CD3; Fri, 2 Feb 2024 15:58:57 +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=1706889537; cv=none; b=B+yYk13ajj21Y8aSFnnVtPInpO5FzQngu0YE9xc66qT0cTSBJt+nUTWxGEd5WIm9xJdizrNUXj0trXc54LRFPcNFhVn5jGM8cOta3NkN5/D9vAo2Z9Lu9um7rfuHg782E8xMd8WrTJ02f+NtGbH+g2HuMRlU+n0VJrMHTLWP5Vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889537; c=relaxed/simple; bh=FTcLV2NufTBnpOgxgoEZStajI6PRmkWD1yAMbETfinQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O2PNPCsHo3IaeaBL9f60AlIDXc+o/0YtJFVGbiE3Lb+UcUYGgQCVX/mz10guUfzqE4XdneuDAUTZmghlRzTpnGEsTF4FPEStFLFaYgAn04CAXeoCwPGCC23F4NTFswN3XvgLl/SnuURzF9tEO0ZC8xVCxfDobBEys4UsFp8t760= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KHPlvMni; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KHPlvMni" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7B232C43390; Fri, 2 Feb 2024 15:58:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889537; bh=FTcLV2NufTBnpOgxgoEZStajI6PRmkWD1yAMbETfinQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KHPlvMni4MDvKigZg2a8wQU1pSZK2Voh6N8Em4TtlyRxmzpFMuU4EaO2CaSoODtsO IDOo9X/Sdp2qfdXjJkyBaD9o3E5AzRuFcjXmmPXwxzeTi3L7d5jZE/ermuVdypYdfb 3oABKE31z5LET4VBmmqS/AINEF29sKD45qg0jh1n6at/aqMeGmpKQL+nuDP0plZ8OO 0C3JhMx//nm9vqD9v/gd1tvkFaWtmhTiogp5vpfnqZhCBhtQ0c/QRZqevxCuGU9iH/ ROLHvzYGKjTvem876+4Ly6jEJqMQnoo7acgzjItSPSKifOAd0Zett2SzkQIITOzArH aTPo0cn6B2qfA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 24/27] kconfig: move strhash() to a header Date: Sat, 3 Feb 2024 00:58:22 +0900 Message-Id: <20240202155825.314567-25-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move strhash() to a header, so it can be used from other files. Signed-off-by: Masahiro Yamada --- scripts/kconfig/symbol.c | 10 +--------- scripts/kconfig/util.h | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 scripts/kconfig/util.h diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index dae630a74e50..518977c525de 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -10,6 +10,7 @@ #include #include "lkc.h" +#include "util.h" struct symbol symbol_yes = { .name = "y", @@ -803,15 +804,6 @@ bool sym_is_changeable(struct symbol *sym) return sym->visible > sym->rev_dep.tri; } -static unsigned strhash(const char *s) -{ - /* fnv32 hash */ - unsigned hash = 2166136261U; - for (; *s; s++) - hash = (hash ^ *s) * 0x01000193; - return hash; -} - struct symbol *sym_lookup(const char *name, int flags) { struct symbol *symbol; diff --git a/scripts/kconfig/util.h b/scripts/kconfig/util.h new file mode 100644 index 000000000000..d4e35bee6450 --- /dev/null +++ b/scripts/kconfig/util.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef UTIL_H +#define UTIL_H + +static unsigned int strhash(const char *s) +{ + /* fnv32 hash */ + unsigned int hash = 2166136261U; + + for (; *s; s++) + hash = (hash ^ *s) * 0x01000193; + return hash; +} + +#endif /* UTIL_H */ From patchwork Fri Feb 2 15:58:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543119 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 662B5151CF4; Fri, 2 Feb 2024 15:58:58 +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=1706889538; cv=none; b=ZwFKWZmXplKlHChirBOhDFliu1r94yjwY/jYY/3zSLFpAw2q4iYHhncbQvV8RKGaSN6fB2McH+m4QiLL891xHxysoxfP88TMwOEGbifnP8WyBubwYU5CQ6a4pmff86TKFEzk6ftGJTjeSb7gecqiUhDnUzAQBgHYiUTjhTKS6jM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889538; c=relaxed/simple; bh=X8I9rXVeGCoi7QcnwK71myLC6oWao8zTKDKpyMAWvVo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=q02AA6ixz2XkoF09bp+idYDM3ey6oXXHaJCRKcg6zOk6Sa9IUfGcrLDJkakwWYxMIyCJOk5h6vMx4Ns1Gr0/TZdP90mMrniU8Ec1uYFsCU4x9w5zf35Yf9zMFJKNpFQlNp05YHeqROwa0ex+faZgpsN3eh6X8SoN25EYB52j7xo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ruhFwbtw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ruhFwbtw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95B95C433F1; Fri, 2 Feb 2024 15:58:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889538; bh=X8I9rXVeGCoi7QcnwK71myLC6oWao8zTKDKpyMAWvVo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ruhFwbtwadYQ+aNHjKCd11eXVlQ7wLThqD6C1mWZNU+jhMKHpQ2auVnO/eSPsB6+u 37fcPp48rAWE7w8tmgQYNgB205Io0CJL1RzBt5MN6MVDulVdvkZNXNS8yyzBeOD6dq 0Nuy2uyWp560OU3J+py8kfOlcsRxjitACuxs778wcKnhtQP4/ufG5yFAdmDGuoBFUy ZxBG8KGyl8XEzY4hpEvAmUzyXcrdsHLpFF4Wzscwb/kSbDEO62qKYMtqehjee25PRx 6yij5ztam2Vo9vMKZwrkOgVwit0UIp5GpPcAB4KTMVDWxZZVr0SljfNwNju0I5yHT9 8LliXU3QuTMug== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 25/27] kconfig: convert linked list of files to hash table Date: Sat, 3 Feb 2024 00:58:23 +0900 Message-Id: <20240202155825.314567-26-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently, a linked list is used to keep track of all the Kconfig files that have ever been parsed. Every time the "source" statement is encountered, the linked list is traversed to check if the file has been opened before. This prevents the same file from being recorded in include/config/auto.conf.cmd again. Given 1500+ Kconfig files parsed, a hashtable is now a more optimal data structure. By the way, you may wonder why we check this in the first place. It matters only when the same file is included multiple times. In old days, such a use case was forbidden, but commit f094f8a1b273 ("kconfig: allow multiple inclusion of the same file") provided a bit more flexibility. Of course, it is almost hypothetical... Signed-off-by: Masahiro Yamada --- scripts/kconfig/util.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index 610d64c01479..abd697ed8de7 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -7,34 +7,37 @@ #include #include #include + +#include "hashtable.h" #include "lkc.h" +#include "util.h" + +/* hash table of all parsed Kconfig files */ +static HASHTABLE_DEFINE(file_hashtable, 1U << 11); struct file { - struct file *next; + struct hlist_node node; char name[]; }; -static struct file *file_list; - /* file already present in list? If not add it */ const char *file_lookup(const char *name) { struct file *file; size_t len; + int hash = strhash(name); - for (file = file_list; file; file = file->next) { - if (!strcmp(name, file->name)) { + hash_for_each_possible(file_hashtable, file, node, hash) + if (!strcmp(name, file->name)) return file->name; - } - } len = strlen(name); file = xmalloc(sizeof(*file) + len + 1); memset(file, 0, sizeof(*file)); memcpy(file->name, name, len); file->name[len] = '\0'; - file->next = file_list; - file_list = file; + + hash_add(file_hashtable, &file->node, hash); str_printf(&autoconf_cmd, "\t%s \\\n", name); From patchwork Fri Feb 2 15:58:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543120 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 E2396151CD9; Fri, 2 Feb 2024 15:58:59 +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=1706889540; cv=none; b=XgQ4U62xvrd3wKecJZnrIuB7Wt9++dXe0hXEn4TGoOTCWW6mNr2HHgszQfL7eX7I7Q+fdZP1VznWJOpchIZo5K4HbG/85WoaQcMQXlm+XkJIgXFlVZYCiXRbtY2sg8bAkZiU/adbWMZzU2rk8MUAy3tTadwMLHc74dlPselRz/E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889540; c=relaxed/simple; bh=k9Sfj6G74FhB17Co2/07H2mwmXKZRLmR93bIQOS6wrw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CAQnELQbF86QnuQG0s9SyB2pWiTA2JlfWR9IrqHjc99+LSWTAxAHyPeEm7cNElFdrnf3hU24Kr2WBOydN3oTsF/NnmevwN1a4+lsREzl88bGqwK8Dd0GF97YFexzM7b1qXhqHDa2tW8KZlyo9lInahLMgSLLiqcWj3Hs6qcKeyc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eYqeowhx; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eYqeowhx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B327FC43394; Fri, 2 Feb 2024 15:58:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889539; bh=k9Sfj6G74FhB17Co2/07H2mwmXKZRLmR93bIQOS6wrw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eYqeowhxfk0mGaeCDX4LInidLVKrblDFemMbSzO9p90R8KzMZhtZ6rt+KbL88mLHM 3c+y/y18m5psSDUS14JLyVs9MThe5pmyuE9BceKtpThf/4tEb7YuFIk66EEbcBsDT/ o73nmSoQbPvZvNqTgOA0hz0Bmi9J6sI48BTq4FGGNbcmP6B98vH/eYVTvDhV5/pu1z uC81v28M8BEAOZmUxIDpFPFnEKhylLXapPijRiAdZOxswFZ3rtgpLo4xsZFYm8j/Zv S6SpAzWPWpfXGND3Ndp2kkKZOlcfmNDoyPpIITXUMTzD7sYniQSS6+tDa5ae+6BKPl jG+h2ti3vNWiA== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 26/27] kconfig: use generic macros to implement symbol hashtable Date: Sat, 3 Feb 2024 00:58:24 +0900 Message-Id: <20240202155825.314567-27-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use helper macros in hashtable.h for generic hashtable implementation. We can git rid of the hash head index of for_all_symbols(). Signed-off-by: Masahiro Yamada --- scripts/kconfig/conf.c | 12 ++++++------ scripts/kconfig/confdata.c | 25 ++++++++++++------------- scripts/kconfig/expr.h | 9 ++++----- scripts/kconfig/internal.h | 9 +++++++++ scripts/kconfig/lkc_proto.h | 2 -- scripts/kconfig/parser.y | 5 +---- scripts/kconfig/symbol.c | 22 +++++++++++----------- 7 files changed, 43 insertions(+), 41 deletions(-) diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c index 662a5e7c37c2..b5730061872b 100644 --- a/scripts/kconfig/conf.c +++ b/scripts/kconfig/conf.c @@ -14,6 +14,7 @@ #include #include +#include "internal.h" #include "lkc.h" static void conf(struct menu *menu); @@ -171,7 +172,7 @@ enum conf_def_mode { static bool conf_set_all_new_symbols(enum conf_def_mode mode) { struct symbol *sym, *csym; - int i, cnt; + int cnt; /* * can't go as the default in switch-case below, otherwise gcc whines * about -Wmaybe-uninitialized @@ -226,7 +227,7 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode) } } - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym_has_value(sym) || sym->flags & SYMBOL_VALID) continue; switch (sym_get_type(sym)) { @@ -278,14 +279,14 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode) * and the rest to no. */ if (mode != def_random) { - for_all_symbols(i, csym) { + for_all_symbols(csym) { if ((sym_is_choice(csym) && !sym_has_value(csym)) || sym_is_choice_value(csym)) csym->flags |= SYMBOL_NEED_SET_CHOICE_VALUES; } } - for_all_symbols(i, csym) { + for_all_symbols(csym) { if (sym_has_value(csym) || !sym_is_choice(csym)) continue; @@ -304,9 +305,8 @@ static bool conf_set_all_new_symbols(enum conf_def_mode mode) static void conf_rewrite_tristates(tristate old_val, tristate new_val) { struct symbol *sym; - int i; - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym_get_type(sym) == S_TRISTATE && sym->def[S_DEF_USER].tri == old_val) sym->def[S_DEF_USER].tri = new_val; diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index dafc572e7b7e..c5b6487d68ac 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -18,6 +18,7 @@ #include #include +#include "internal.h" #include "lkc.h" struct gstr autoconf_cmd; @@ -322,7 +323,7 @@ int conf_read_simple(const char *name, int def) size_t line_asize = 0; char *p, *val; struct symbol *sym; - int i, def_flags; + int def_flags; const char *warn_unknown, *sym_name; warn_unknown = getenv("KCONFIG_WARN_UNKNOWN_SYMBOLS"); @@ -380,7 +381,7 @@ int conf_read_simple(const char *name, int def) conf_warnings = 0; def_flags = SYMBOL_DEF << def; - for_all_symbols(i, sym) { + for_all_symbols(sym) { sym->flags |= SYMBOL_CHANGED; sym->flags &= ~(def_flags|SYMBOL_VALID); if (sym_is_choice(sym)) @@ -489,7 +490,6 @@ int conf_read(const char *name) { struct symbol *sym; int conf_unsaved = 0; - int i; conf_set_changed(false); @@ -500,7 +500,7 @@ int conf_read(const char *name) sym_calc_value(modules_sym); - for_all_symbols(i, sym) { + for_all_symbols(sym) { sym_calc_value(sym); if (sym_is_choice(sym) || (sym->flags & SYMBOL_NO_WRITE)) continue; @@ -524,7 +524,7 @@ int conf_read(const char *name) /* maybe print value in verbose mode... */ } - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym_has_value(sym) && !sym_is_choice_value(sym)) { /* Reset values of generates values, so they'll appear * as new, if they should become visible, but that @@ -862,7 +862,6 @@ int conf_write(const char *name) const char *str; char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1]; char *env; - int i; bool need_newline = false; if (!name) @@ -946,7 +945,7 @@ int conf_write(const char *name) } fclose(out); - for_all_symbols(i, sym) + for_all_symbols(sym) sym->flags &= ~SYMBOL_WRITTEN; if (*tmpname) { @@ -1016,7 +1015,7 @@ static int conf_touch_deps(void) { const char *name, *tmp; struct symbol *sym; - int res, i; + int res; name = conf_get_autoconfig_name(); tmp = strrchr(name, '/'); @@ -1030,7 +1029,7 @@ static int conf_touch_deps(void) conf_read_simple(name, S_DEF_AUTO); sym_calc_value(modules_sym); - for_all_symbols(i, sym) { + for_all_symbols(sym) { sym_calc_value(sym); if ((sym->flags & SYMBOL_NO_WRITE) || !sym->name) continue; @@ -1096,7 +1095,7 @@ static int __conf_write_autoconf(const char *filename, char tmp[PATH_MAX]; FILE *file; struct symbol *sym; - int ret, i; + int ret; if (make_parent_dir(filename)) return -1; @@ -1113,7 +1112,7 @@ static int __conf_write_autoconf(const char *filename, conf_write_heading(file, comment_style); - for_all_symbols(i, sym) + for_all_symbols(sym) if ((sym->flags & SYMBOL_WRITE) && sym->name) print_symbol(file, sym); @@ -1136,7 +1135,7 @@ int conf_write_autoconf(int overwrite) { struct symbol *sym; const char *autoconf_name = conf_get_autoconfig_name(); - int ret, i; + int ret; if (!overwrite && is_present(autoconf_name)) return 0; @@ -1148,7 +1147,7 @@ int conf_write_autoconf(int overwrite) if (conf_touch_deps()) return 1; - for_all_symbols(i, sym) + for_all_symbols(sym) sym_calc_value(sym); ret = __conf_write_autoconf(conf_get_autoheader_name(), diff --git a/scripts/kconfig/expr.h b/scripts/kconfig/expr.h index dd3350aed302..3bc375f1a1cd 100644 --- a/scripts/kconfig/expr.h +++ b/scripts/kconfig/expr.h @@ -17,6 +17,8 @@ extern "C" { #include #endif +#include "list_types.h" + typedef enum tristate { no, mod, yes } tristate; @@ -74,8 +76,8 @@ enum { * SYMBOL_CHOICE bit set in 'flags'. */ struct symbol { - /* The next symbol in the same bucket in the symbol hash table */ - struct symbol *next; + /* link node for the hash table */ + struct hlist_node node; /* The name of the symbol, e.g. "FOO" for 'config FOO' */ char *name; @@ -124,8 +126,6 @@ struct symbol { struct expr_value implied; }; -#define for_all_symbols(i, sym) for (i = 0; i < SYMBOL_HASHSIZE; i++) for (sym = symbol_hash[i]; sym; sym = sym->next) - #define SYMBOL_CONST 0x0001 /* symbol is const */ #define SYMBOL_CHECK 0x0008 /* used during dependency checking */ #define SYMBOL_CHOICE 0x0010 /* start of a choice block (null name) */ @@ -150,7 +150,6 @@ struct symbol { #define SYMBOL_NEED_SET_CHOICE_VALUES 0x100000 #define SYMBOL_MAXLENGTH 256 -#define SYMBOL_HASHSIZE 9973 /* A property represent the config options that can be associated * with a config "symbol". diff --git a/scripts/kconfig/internal.h b/scripts/kconfig/internal.h index 788401cd5d6f..6c721c4cfd72 100644 --- a/scripts/kconfig/internal.h +++ b/scripts/kconfig/internal.h @@ -2,6 +2,15 @@ #ifndef INTERNAL_H #define INTERNAL_H +#include "hashtable.h" + +#define SYMBOL_HASHSIZE (1U << 14) + +extern HASHTABLE_DECLARE(sym_hashtable, SYMBOL_HASHSIZE); + +#define for_all_symbols(sym) \ + hash_for_each(sym_hashtable, sym, node) + struct menu; extern struct menu *current_menu, *current_entry; diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h index 94299e42402f..2807fa584c2b 100644 --- a/scripts/kconfig/lkc_proto.h +++ b/scripts/kconfig/lkc_proto.h @@ -18,8 +18,6 @@ void conf_set_message_callback(void (*fn)(const char *s)); bool conf_errors(void); /* symbol.c */ -extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; - struct symbol * sym_lookup(const char *name, int flags); struct symbol * sym_find(const char *name); void print_symbol_for_listconfig(struct symbol *sym); diff --git a/scripts/kconfig/parser.y b/scripts/kconfig/parser.y index e58c24d2e5ab..112831da4f44 100644 --- a/scripts/kconfig/parser.y +++ b/scripts/kconfig/parser.y @@ -28,8 +28,6 @@ static void zconf_error(const char *err, ...); static bool zconf_endtoken(const char *tokenname, const char *expected_tokenname); -struct symbol *symbol_hash[SYMBOL_HASHSIZE]; - struct menu *current_menu, *current_entry; %} @@ -474,7 +472,6 @@ assign_val: void conf_parse(const char *name) { struct symbol *sym; - int i; autoconf_cmd = str_new(); @@ -517,7 +514,7 @@ void conf_parse(const char *name) } menu_finalize(&rootmenu); - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym_check_deps(sym)) yynerrs++; } diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 518977c525de..1290c6d2f8c2 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -9,6 +9,7 @@ #include #include +#include "internal.h" #include "lkc.h" #include "util.h" @@ -161,9 +162,8 @@ static void sym_set_changed(struct symbol *sym) static void sym_set_all_changed(void) { struct symbol *sym; - int i; - for_all_symbols(i, sym) + for_all_symbols(sym) sym_set_changed(sym); } @@ -476,9 +476,8 @@ void sym_calc_value(struct symbol *sym) void sym_clear_all_valid(void) { struct symbol *sym; - int i; - for_all_symbols(i, sym) + for_all_symbols(sym) sym->flags &= ~SYMBOL_VALID; conf_set_changed(true); sym_calc_value(modules_sym); @@ -804,6 +803,8 @@ bool sym_is_changeable(struct symbol *sym) return sym->visible > sym->rev_dep.tri; } +HASHTABLE_DEFINE(sym_hashtable, SYMBOL_HASHSIZE); + struct symbol *sym_lookup(const char *name, int flags) { struct symbol *symbol; @@ -818,9 +819,9 @@ struct symbol *sym_lookup(const char *name, int flags) case 'n': return &symbol_no; } } - hash = strhash(name) % SYMBOL_HASHSIZE; + hash = strhash(name); - for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { + hash_for_each_possible(sym_hashtable, symbol, node, hash) { if (symbol->name && !strcmp(symbol->name, name) && (flags ? symbol->flags & flags @@ -839,8 +840,7 @@ struct symbol *sym_lookup(const char *name, int flags) symbol->type = S_UNKNOWN; symbol->flags = flags; - symbol->next = symbol_hash[hash]; - symbol_hash[hash] = symbol; + hash_add(sym_hashtable, &symbol->node, hash); return symbol; } @@ -860,9 +860,9 @@ struct symbol *sym_find(const char *name) case 'n': return &symbol_no; } } - hash = strhash(name) % SYMBOL_HASHSIZE; + hash = strhash(name); - for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { + hash_for_each_possible(sym_hashtable, symbol, node, hash) { if (symbol->name && !strcmp(symbol->name, name) && !(symbol->flags & SYMBOL_CONST)) @@ -922,7 +922,7 @@ struct symbol **sym_re_search(const char *pattern) if (regcomp(&re, pattern, REG_EXTENDED|REG_ICASE)) return NULL; - for_all_symbols(i, sym) { + for_all_symbols(sym) { if (sym->flags & SYMBOL_CONST || !sym->name) continue; if (regexec(&re, sym->name, 1, match, 0)) From patchwork Fri Feb 2 15:58:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 13543121 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 E73D915350E; Fri, 2 Feb 2024 15:59:00 +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=1706889541; cv=none; b=VsuSThnnYomgWjk6JFcsg7/9mga9UFVFcAPqe4BagROxq+VptKycGF93SAN0C6PeDfOvmEGsIevuyE5uG04dRRb4B0Oj7AYPfz7owQwuxYTQr0gW5PxwBlh5BsuwgvGM2oitRCXWf4lnUaY7WSbnLdA1N9CFhWVByW/maD/G09I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706889541; c=relaxed/simple; bh=z4Cms56kmTfXRHkY+P++VOmPThXzhuLEMnCh+5t5LTk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XpBfO3kKOzjLLhS0sOJaEb1M3U4UQafTpl/PxSdxhs7Q+GBZ9hV95VtwRwXlXq5KPg4S+ACEw9TX5DO9tKQcPfrSF7VDR3RnW3ZPYG7woFyGzGNCKEayiG8tllvGvxSsMhENVpjhlHhOcWTyObbOkSeWwscp0JfCuo0Zi2y4SPQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nn3YZR80; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nn3YZR80" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBF86C43390; Fri, 2 Feb 2024 15:58:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706889540; bh=z4Cms56kmTfXRHkY+P++VOmPThXzhuLEMnCh+5t5LTk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nn3YZR80OfoXt/sLgprXuYM20Lq3vti3Bsrk0CaUs8c7oU5QF7MwxAzEWpoAp9dGH 7rM06W06R0+Uc+bAhvFj+HuwDNJUXxXM12eCARlJH9by5rQqTStGZPzBilgeI/p5MJ zUr2e3hI5gBKtgGLvo9zFFSWMuLsr7zqWMjsTaS9/tncjCAYGRzRoJIwbQZVWRpYF2 lXgiuhMH+k5Kq7rgx3lRGc4eBztnQjo6zIwlPiwFSdQNnJ1XEPeLr792PFoXTrmEo2 ZOAn5mBQ+DSbMPqRfKYqqNjxjzNKH8fE+0IEAhaVFyPXRnJOxdwu19DP2OUWxbVUNg MmBYRI1Hd6Afg== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Masahiro Yamada Subject: [PATCH 27/27] kconfig: do not imply the type of choice value Date: Sat, 3 Feb 2024 00:58:25 +0900 Message-Id: <20240202155825.314567-28-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-kbuild@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Do not feed back the choice type to choice values. Each choice value should explicitly specify 'bool' or 'tristate', as all the Kconfig files already do. If the type were missing, "config symbol defined without type" would be shown. Signed-off-by: Masahiro Yamada --- scripts/kconfig/menu.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c index 696803d944e0..44465945d6b1 100644 --- a/scripts/kconfig/menu.c +++ b/scripts/kconfig/menu.c @@ -305,12 +305,6 @@ void menu_finalize(struct menu *parent) } } } - /* set the type of the remaining choice values */ - for (menu = parent->list; menu; menu = menu->next) { - current_entry = menu; - if (menu->sym && menu->sym->type == S_UNKNOWN) - menu_set_type(sym->type); - } /* * Use the choice itself as the parent dependency of