From patchwork Sun Jan 7 13:19:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 185731 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp533882dyq; Sun, 7 Jan 2024 05:20:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IG23zpHPF+h8tD34pKqWSo47A/bdMBJfyqy6oxv3632Wuo9/53zBaBy9SKSgAMicWiZdJou X-Received: by 2002:ac8:574c:0:b0:429:8afd:c884 with SMTP id 12-20020ac8574c000000b004298afdc884mr2502907qtx.73.1704633616670; Sun, 07 Jan 2024 05:20:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704633616; cv=none; d=google.com; s=arc-20160816; b=T6kU6dmFlR1iHJ7IVpVP6OGG1KuI/4+ZrDHMQCORncDSvwiDc7LzBUfgXcOcQE3l3h aDQmIlYLDVTb0bKWM/vnCULfMa84rI6b3y42pAlSGFstNXc4v0J5yfJFZuBbozxiSQRn lUtGsFQAssDKtWf7up5KmZBWk7ZzwTbGxpt7kPk9Mpt/RZNPOvdcOY+3ueFH/8j+Q3H8 qIH7W9O24mzF04BqKGelJ/NoLmt9ERy3AZp9F7F5heTeVsTCNKWtmwgkFlh1Gn1BdQl/ OZQ3Pb4LVnBdQHS7iIIK3/kvtNGZRvqgLs/jl04ZZ3yGIvzSwjDdtGqHCPoTRBdDWme+ rKjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=hovxQgys5XXzm3hbmB1cTGUrIf+R5Ar7BefZSrX6oJM=; fh=cr2kAYujDVm2vUVjNQU/xxltWJfGGL3pZvB2q4ufDBk=; b=qL3FrIsX63LHbyxndXQch88YpbvmPoMsYXJpWetnHbNVviN2JrTdbfG7PQwb/8lst9 kdCvDDPWyTw8t0FIwvIjmGNaktHI5skIS8kRfOy1sSsVJr0ZFsM/tgVD6nox4o211wJp 0GJmxhflKjRs53Irs2MV62JpSshwIMc6fDcpgq/Wt6r3wm6D+6HnIopMLcd40R0iua3w 0B/+oe7RasyX60/h7sEwzDnJzKQooJG4WTbkxoWA72r+LNnyigkdULzYwafi3Q1C5dKg 6Ia7ZtaqJ0iwXzJqf5PmSX6SBSCFtOZ02u0mvX4gG2zPlwG9wRRWXs0kU0//qFDpKgZf TvCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oaocn+Ue; spf=pass (google.com: domain of linux-kernel+bounces-18868-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18868-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t12-20020ac8588c000000b00429899c2e0bsi2108799qta.642.2024.01.07.05.20.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 05:20:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18868-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=oaocn+Ue; spf=pass (google.com: domain of linux-kernel+bounces-18868-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18868-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 7609B1C20DEB for ; Sun, 7 Jan 2024 13:20:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0DF1F134D6; Sun, 7 Jan 2024 13:19:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="oaocn+Ue" X-Original-To: linux-kernel@vger.kernel.org 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 6814A134A6; Sun, 7 Jan 2024 13:19:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3462AC433C8; Sun, 7 Jan 2024 13:19:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704633593; bh=yqUZakV4GV4CxI5FT16aZfQMpPe8/dakYmO+NY7zAso=; h=From:To:Cc:Subject:Date:From; b=oaocn+UeQhTi7Qguxa9FM2DSdeNqH/AX81W4rF5lnGi1M/XWdTy+1TD0jWqtH9UEb m9dLDYdoIW/TXGV/Z53fivq4GnLqu/g8VLcptXWNS3XVCElw8Hrl7625454OM7QL7B qmUK8v5OIeUl4UzdmnFj2OEZ3f9WNpAfLB03/eYw5z5vcy3IgD8Ieg3Rs3mRpdkkkd /p2Cr9MQWTqurLqXH1ZeDGt/qxlvdMB3l+CqqjPk3BvBMhhfpAYS8ORzFl0l+A6tPL jFYlJgZeAKe11ceeosV6wdm4e0r6ZY2ZBQtM67NLYC/goSl6sEwyLYVfGz1FeM3nRp p4uRdLW7IAHfQ== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] kconfig: remove unneeded buffer allocation in zconf_initscan() Date: Sun, 7 Jan 2024 22:19:47 +0900 Message-Id: <20240107131948.39752-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787437899001510859 X-GMAIL-MSGID: 1787437899001510859 In Kconfig, there is a stack to save the lexer state for each inclusion level. Currently, it operates as an empty stack, with the 'current_buf' always pointing to an empty buffer. There is no need to preallocate the buffer. Change it to a full stack. Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index cc386e443683..d75423ec4eae 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -391,9 +391,6 @@ void zconf_initscan(const char *name) exit(1); } - current_buf = xmalloc(sizeof(*current_buf)); - memset(current_buf, 0, sizeof(*current_buf)); - current_file = file_lookup(name); yylineno = 1; } @@ -403,9 +400,10 @@ void zconf_nextfile(const char *name) struct file *iter; struct file *file = file_lookup(name); struct buffer *buf = xmalloc(sizeof(*buf)); - memset(buf, 0, sizeof(*buf)); - current_buf->state = YY_CURRENT_BUFFER; + buf->state = YY_CURRENT_BUFFER; + buf->parent = current_buf; + current_buf = buf; yyin = zconf_fopen(file->name); if (!yyin) { fprintf(stderr, "%s:%d: can't open file \"%s\"\n", @@ -413,8 +411,6 @@ void zconf_nextfile(const char *name) exit(1); } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - buf->parent = current_buf; - current_buf = buf; current_file->lineno = yylineno; file->parent = current_file; @@ -441,20 +437,21 @@ void zconf_nextfile(const char *name) static void zconf_endfile(void) { - struct buffer *parent; + struct buffer *tmp; current_file = current_file->parent; if (current_file) yylineno = current_file->lineno; - parent = current_buf->parent; - if (parent) { - fclose(yyin); - yy_delete_buffer(YY_CURRENT_BUFFER); - yy_switch_to_buffer(parent->state); - } - free(current_buf); - current_buf = parent; + if (!current_buf) + return; + + fclose(yyin); + yy_delete_buffer(YY_CURRENT_BUFFER); + yy_switch_to_buffer(current_buf->state); + tmp = current_buf; + current_buf = current_buf->parent; + free(tmp); } int zconf_lineno(void) From patchwork Sun Jan 7 13:19:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 185732 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp533944dyq; Sun, 7 Jan 2024 05:20:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IH2G4Lw2hjaNVqSrhdGi1HYoC1TKTZM78KblLyvFiTrAwRWN/j3k8k2ZWaOqnU5O9wx9PtL X-Received: by 2002:a17:90a:1f4b:b0:28b:4a30:cf42 with SMTP id y11-20020a17090a1f4b00b0028b4a30cf42mr465598pjy.38.1704633625645; Sun, 07 Jan 2024 05:20:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704633625; cv=none; d=google.com; s=arc-20160816; b=m8bp6pwnMRBFDFbl4Ym8+5QvQsnR2yYozwjt/zg4w38IYmaEdgXaQ2FjW0d3ZUcZQC uFg6d88+xSHJiu16m6qQn95XdODybwTd7ifyAp0cfmEnSJ3OCpx4iO4izmDL5bCXHvLT UH9/5x8PRGhtb/Fyh6wO6nX63kEyrEvosoNa9nmNRXHsCx2UXnlyOlWgnK4oVP6dM99N 1KGvNLvX4uKyBKVMBY+l8uFzQPdmkyXdtBSS0xnsAFMY//bY5/mJZsw+pCr6rWgfl9oR gIaoyjuxfEQKpMy9xP+spGPkf8f/qD1NNbBDU0bL1bQQeqAUW0CDTDaiKblB2yHqBMsQ C0uQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=/GmrabiHSI2ZMn4pO2OtWhG3XZ2wsD9/GCkNvZHKPW0=; fh=cr2kAYujDVm2vUVjNQU/xxltWJfGGL3pZvB2q4ufDBk=; b=D+j/36oEdyL+d1sAjTNKAIsEAYp4Yy2MZxDIqak+XVJQ1ufc/VQWDHbC4v8IkvmltW F95ORLtDSY7r/DHWtOB9riI6oTKDcKItNLIxt3cWsnrwM7KFDUIlm/QQd9z9jL0wBEh0 O2PiYm5KmC8dEJoDhTtKpMBCI1hw2t4iejNPPJ1m0C11WdXtbXPxW3uCDy1mJEPy/Mc6 MosVdA+KzZnFhWyIMi6iH8L7hgBDeo7bUZut2eJiA6dtNuLwRoLNeEl8OYoLaYsEI7/v 35MnApnrAfLLSjRjHf3Xv7Y0SkYSQ2g/ugkDGUxs9phEcxqKwDa78jiaHMEbxZ8mJbRF KTfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CmVgyUqS; spf=pass (google.com: domain of linux-kernel+bounces-18869-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18869-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c6-20020a17090a1d0600b0028c01525883si3929797pjd.14.2024.01.07.05.20.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 05:20:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-18869-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CmVgyUqS; spf=pass (google.com: domain of linux-kernel+bounces-18869-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-18869-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E3493B21640 for ; Sun, 7 Jan 2024 13:20:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 067D213AC9; Sun, 7 Jan 2024 13:19:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CmVgyUqS" X-Original-To: linux-kernel@vger.kernel.org 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 6EF8A134B1; Sun, 7 Jan 2024 13:19:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 48BE9C433C9; Sun, 7 Jan 2024 13:19:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1704633594; bh=EhenJv98wQ6P7JdtZwqrkrF1c5zd39P2pUl1WVROUA8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CmVgyUqS3XISmxGQFJG2CHZfXCPit+YlYoVB7c9MLLiOD3wTPX5dXUdkH1tU7ttPA AsleNMoE3oL9K35UXZfkAFgSsBHhtY+GzTtyCy2V4eJt5Yx5fh71F51JTZymp9ZFlf YB8q2cODNB6dYdxRy7g8GpVsKtR/SMc0whHpCKJikYvqwDO77lLzTagpef14qyq7ZF C2KhBTHRhAw1sDN8ZEs2egAcCRe0tjuITtfvkJer3ayrRDIcBoSnHOsz/c/15GH8N8 zIecPP9oLw/X3XBHxeUab5eUTS/LWrkWIdP9KzfX5WK8L90OEaCCYF9GHfS9ixHvwK s8T5Y5zdcUL0g== From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] kconfig: fix line number in recursive inclusion detection Date: Sun, 7 Jan 2024 22:19:48 +0900 Message-Id: <20240107131948.39752-2-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240107131948.39752-1-masahiroy@kernel.org> References: <20240107131948.39752-1-masahiroy@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787437909009257746 X-GMAIL-MSGID: 1787437909009257746 The error message shows a wrong line number if the 'source' directive is wrapped to the following line. [Test Code] source \ "Kconfig" This results in the following error message: Recursive inclusion detected. Inclusion path: current file : Kconfig included from: Kconfig:2 The correct message should be as follows: Recursive inclusion detected. Inclusion path: current file : Kconfig included from: Kconfig:1 Signed-off-by: Masahiro Yamada --- scripts/kconfig/lexer.l | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/kconfig/lexer.l b/scripts/kconfig/lexer.l index d75423ec4eae..b3aeb29695d7 100644 --- a/scripts/kconfig/lexer.l +++ b/scripts/kconfig/lexer.l @@ -33,6 +33,7 @@ static int text_size, text_asize; struct buffer { struct buffer *parent; YY_BUFFER_STATE state; + int lineno; }; static struct buffer *current_buf; @@ -402,6 +403,7 @@ void zconf_nextfile(const char *name) struct buffer *buf = xmalloc(sizeof(*buf)); buf->state = YY_CURRENT_BUFFER; + buf->lineno = yylineno; buf->parent = current_buf; current_buf = buf; yyin = zconf_fopen(file->name); @@ -412,7 +414,7 @@ void zconf_nextfile(const char *name) } yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - current_file->lineno = yylineno; + current_file->lineno = zconf_lineno(); file->parent = current_file; for (iter = current_file; iter; iter = iter->parent) { @@ -425,7 +427,7 @@ void zconf_nextfile(const char *name) do { iter = iter->parent; fprintf(stderr, " included from: %s:%d\n", - iter->name, iter->lineno - 1); + iter->name, iter->lineno); } while (strcmp(iter->name, file->name)); exit(1); } @@ -440,8 +442,6 @@ static void zconf_endfile(void) struct buffer *tmp; current_file = current_file->parent; - if (current_file) - yylineno = current_file->lineno; if (!current_buf) return; @@ -449,6 +449,7 @@ static void zconf_endfile(void) fclose(yyin); yy_delete_buffer(YY_CURRENT_BUFFER); yy_switch_to_buffer(current_buf->state); + yylineno = current_buf->lineno; tmp = current_buf; current_buf = current_buf->parent; free(tmp);