From nobody Sat Jul 25 00:16:24 2026 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (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 BC142480324; Tue, 21 Jul 2026 17:51:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784656272; cv=pass; b=kGlnWax0ShIM8oBfhpGISUFMK/dWARD8iVbOMdya37RV7UYzgOZtY3P8pZq0Ksu9FuICd72v7ndxuW/GCRAmcZON4ddyrD4XByhmqLMC0B/1t+TEqDZH1jvRuvutp9LNO6pF+yHqAXS5pdPXJYP+ID7ziAu0D837PmR8I/ee6/E= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784656272; c=relaxed/simple; bh=T3X+njmtfrUrp+1nxGHXPmYSgYeBdN7EjsKSd8lOyiA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EJ/H25MSDsfvwjNNBJAA97eNZeBr1OqJfm6YH1YsJy2g5cOfP3MoCnnfS8In55f+E2pqpXnTLHA7AOh7TWaNy9bF2BsDX290VFLh6ELuDbclcIB1LjxfOzrPVKdjRqAEbRhmAl6YHx8LQNNIxa9eM7eTpILbQwarz/V/4TMt1AE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=YtN65gm3; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="YtN65gm3" ARC-Seal: i=1; a=rsa-sha256; t=1784656264; cv=none; d=zohomail.com; s=zohoarc; b=oG3OADkv5D6lFSAlpnv1U4u996VGjvG9CsmmU7kd7MhP0JYTc02nHvDsv3bqwCU5zyQUovujAvemAG/zzMGb8tmEGRpIxHs2PXsEzyP4NzFc9oaG6DLusEhYAPLdvJaEqyoEiYyWDVnz6IUWYng5RWPcZS3KIaOJFBPizNtJAiQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784656264; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=LWR5oarPto7YInMTaRYfNj+M8NXlCMMCJAEL7sTg4TA=; b=H3+UMmi3zgj3o1wbG29aJWbRuobnrakjNcAZD41hKjM6mszfRuRlJNvvDe/kuHAnStpy2kG2FabAufxnxG+mZBcpoKL7R8+B54aZg+Vzz4DJW//2jhlKQTaJ5PatlVB52g1dmmN8iViHzOqgw333rEfdUqPm/4DzXROYY9iS4PI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1784656264; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=LWR5oarPto7YInMTaRYfNj+M8NXlCMMCJAEL7sTg4TA=; b=YtN65gm3SAVrbhTNRE9/w0pWz20ItuWpZ0JbBWsZ+FhXCxeevveSJGfGe89TbtvH Es/mIbho/U3fnLAt5WrPmeLL5oDEA0rnb1+Hyedls2Fn+bPv4KPREUQzin7ChbOeoBF sNDXTJtC3Y2NSluTsTICdvgqSscefdoI4xP9hccWp671rZRv3MkH1xrUj0yBvYeJmM3 Zgj3yCfCOY4o1vD/HFA2spy8+oJr2ERhv613FaXRU5HOqjPsfxh3VlnhJ9UI2smCsmp O/7L8E02vmmXtGFj0hF31XhBQ6JnCaI9QQo40LxIrduDomHLcpp5UKwdGNfwT5w25Fu jbDJp/uT+w== Received: by mx.zohomail.com with SMTPS id 1784656259829421.4065527351337; Tue, 21 Jul 2026 10:50:59 -0700 (PDT) From: Rong Zhang Date: Wed, 22 Jul 2026 01:50:48 +0800 Subject: [PATCH v2 1/2] scripts/config: Use POSIX standard ERE (-E) in sed Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260722-config-sed-v2-1-9f2c4b164666@rong.moe> References: <20260722-config-sed-v2-0-9f2c4b164666@rong.moe> In-Reply-To: <20260722-config-sed-v2-0-9f2c4b164666@rong.moe> To: Nathan Chancellor , Nicolas Schier Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.16-dev-4217c X-ZohoMailClient: External The use of Extended Regular Expressions was removed by commit 83e8b90e1d2c ("scripts/config: use sed's POSIX interface"). Before that, the script used `-r' to enable ERE, which is indeed non-portable. However, POSIX.1-2024 [1][2] has accepted `-E' as a standard option to use ERE for matching, and major sed implementations (GNU, FreeBSD, OpenBSD, NetBSD, macOS) have supported `-E' for over two decades, so it makes no sense to use Basic Regular Expressions any more. Switch to ERE to get rid of chained calls to sed. A rough benchmark with ~1000 editions showed a 40.0% speedup (8.78s =3D> 5.27s, GNU sed). The FreeBSD sed showed a similar speedup. Link: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/sed.html [= 1] Link: https://austingroupbugs.net/view.php?id=3D528 [2] Reviewed-by: Nicolas Schier Signed-off-by: Rong Zhang --- scripts/config | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/scripts/config b/scripts/config index ea475c07de28..1f290372a4ce 100755 --- a/scripts/config +++ b/scripts/config @@ -76,7 +76,7 @@ txt_append() { # sed append cmd: 'a\' + newline + text + newline cmd=3D"$(printf "a\\%b$insert" "\n")" =20 - sed -e "/$anchor/$cmd" "$infile" >"$tmpfile" + sed -E -e "/$anchor/$cmd" "$infile" >"$tmpfile" # replace original file with the edited one mv "$tmpfile" "$infile" } @@ -87,7 +87,7 @@ txt_subst() { local infile=3D"$3" local tmpfile=3D"$infile.swp" =20 - sed -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" >"$tmpfil= e" + sed -E -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" >"$tmp= file" # replace original file with the edited one mv "$tmpfile" "$infile" } @@ -97,7 +97,7 @@ txt_delete() { local infile=3D"$2" local tmpfile=3D"$infile.swp" =20 - sed -e "/$text/d" "$infile" >"$tmpfile" + sed -E -e "/$text/d" "$infile" >"$tmpfile" # replace original file with the edited one mv "$tmpfile" "$infile" } @@ -105,14 +105,12 @@ txt_delete() { set_var() { local name=3D$1 new=3D$2 before=3D$3 =20 - name_re=3D"^($name=3D|# $name is not set)" + name_re=3D"^($name=3D.*|# $name is not set)" before_re=3D"^($before=3D|# $before is not set)" if test -n "$before" && grep -Eq "$before_re" "$FN"; then - txt_append "^$before=3D" "$new" "$FN" - txt_append "^# $before is not set" "$new" "$FN" + txt_append "$before_re" "$new" "$FN" elif grep -Eq "$name_re" "$FN"; then - txt_subst "^$name=3D.*" "$new" "$FN" - txt_subst "^# $name is not set" "$new" "$FN" + txt_subst "$name_re" "$new" "$FN" else echo "$new" >>"$FN" fi @@ -121,8 +119,7 @@ set_var() { undef_var() { local name=3D$1 =20 - txt_delete "^$name=3D" "$FN" - txt_delete "^# $name is not set" "$FN" + txt_delete "^($name=3D|# $name is not set)" "$FN" } =20 FN=3D.config --=20 2.53.0 From nobody Sat Jul 25 00:16:24 2026 Received: from sender4-op-o15.zoho.com (sender4-op-o15.zoho.com [136.143.188.15]) (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 76E304F7970; Tue, 21 Jul 2026 17:51:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=136.143.188.15 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784656275; cv=pass; b=nY12fK2TKV1zwlXYRNOx1rcBScBuleIMrqWdpwEu/lPxobvrhrSR2Ln8ordYl7MnLo2ekdtQQIvhl7UJc1cLPEBj5iytkU9FiR/rcYQBb+dNJ/XnBQVJdEErjE7nugwt8zk9GTMZyxIoG/bY3AJPR2mu6MUa/8Dxbp8Jok0NAlk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784656275; c=relaxed/simple; bh=/bHZxP24S/a32ddemO2nyQzVvN6SB+5I8ulGT9BPtZA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kpMKgcN9GihFrTnKC+MVLIRODyqcaCHTxylubUw/mH82vTJSIMTEsYBam2mR5rfw9fEZ13ieXc98duDRFuykPaAAwd2hfmNHf55EmNT3FMvrYh0uEPDvIIIdGp62JovVBHdTjgSnPUMWwbx+gT/yEVGAFzL7yHAsv3saCgAV5uw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe; spf=pass smtp.mailfrom=rong.moe; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b=QRXfWSfB; arc=pass smtp.client-ip=136.143.188.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=rong.moe Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rong.moe Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rong.moe header.i=i@rong.moe header.b="QRXfWSfB" ARC-Seal: i=1; a=rsa-sha256; t=1784656265; cv=none; d=zohomail.com; s=zohoarc; b=YL6Czc2YzKz8Es/jJE2VNf0uMY9QW2SP1qU5A9whE+EQi7+NLKh/PAkojA/m8YxzceWNvjorHRpHI6kC5g5LQBkWP5TLAO3NBa9fyPZDPCbyWadbQ7zdzyHT4b5dVGTQCLnCdy1cDBoya1hE4IFTL9okKMNIEsLcycpq9EP0AQQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784656265; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=iClaI/sWwaLtVWHmwtEQ7Uu96zELQpNcbpHi63H13HE=; b=juz+/k+Pv+YKxeoGV2lPWy3X62qERJd7I1zkL2f2y16zbujeDpoj02XY8usnPFeFOr1DxgTjl9g3+LJBILLri5YwfC/5Id3z6wF4rJJ2Shi7QGmhsIe8ahEo0htFwnnRg0ubVGfEbeTOdmOhH0n2b2+jHj8HOo7Sf5wAUR4JdK4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=rong.moe; spf=pass smtp.mailfrom=i@rong.moe; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1784656265; s=zmail2048; d=rong.moe; i=i@rong.moe; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=iClaI/sWwaLtVWHmwtEQ7Uu96zELQpNcbpHi63H13HE=; b=QRXfWSfBy7n8SAGLbY7lR1z1gKCT3924oagvX1ipGQaTyJpTQfLzdUewv6OHAAm7 gJZOr/jQyCRGnOIuW1/uCR0QmqoEjhxn+hYqp47CLlTpQlynj8nNxtMJDLRP8t0+DN+ R/5SrtAVHxonDA0wKWpHKBK6C9/elMeIPfP3ya1d7ex7XR7eJUKk5P7firHKCjB1E+e iHucb56n+uqZYZw9ECF7ugdLTKahsWsgdIfNsIW9e+3C1mj3pTemcgGyt51npVt/7rf 8tdz960qXtgOM5lCF19VRrQ+V8ZZUkz/VBVqdY3NX0I91T0R9QW1ctkihrRkS7btzFa 2/8WA4IwvQ== Received: by mx.zohomail.com with SMTPS id 1784656261808226.94518967895692; Tue, 21 Jul 2026 10:51:01 -0700 (PDT) From: Rong Zhang Date: Wed, 22 Jul 2026 01:50:49 +0800 Subject: [PATCH v2 2/2] scripts/config: Use in-place editing (-i) in sed portably Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260722-config-sed-v2-2-9f2c4b164666@rong.moe> References: <20260722-config-sed-v2-0-9f2c4b164666@rong.moe> In-Reply-To: <20260722-config-sed-v2-0-9f2c4b164666@rong.moe> To: Nathan Chancellor , Nicolas Schier Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, Rong Zhang X-Mailer: b4 0.16-dev-4217c X-ZohoMailClient: External The use of in-place editing was removed by commit 83e8b90e1d2c ("scripts/config: use sed's POSIX interface"). Before that, the script used bare `-i' to skip creating a backup file. In fact, major sed implementations have supported `-i' for over a decade. It's really doubtful if anyone would still build Linux on a Unix system without it. The issue is more about how we use it: FreeBSD and macOS disallow bare `-i'. To skip creating a backup, an empty string ("zero-length extension") must be passed as a separate argument following `-i'. GNU and other BSDs accept bare `-i' to skip creating a backup, but disallow passing a zero-length extension. That being said, when thinking about it optimistically, using `-i' is portable as long as a backup is created. Use in-place editing (-i) in a portable manner by creating a backup file with a .swp extension (the same name as the current temporary file). The backup file will be deleted on exit. A rough benchmark with ~1000 editions showed a 14.4% speedup (5.27s =3D> 4.51s, GNU sed). The FreeBSD sed showed a similar speedup. Reviewed-by: Nicolas Schier Signed-off-by: Rong Zhang --- Changes in v2: - Fix a typo in commit message (thanks Nicolas Schier) - Do not delete .swp file when sed is not invoked, e.g., `--state' - In my test, unnecessarily deleting .swp file makes `--state' 10% slower due to the overhead of extra fork() and execve() - Unnecessarily deleting .swp file may corrupt Vim even if no editing command is passed --- scripts/config | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/scripts/config b/scripts/config index 1f290372a4ce..7c083c860341 100755 --- a/scripts/config +++ b/scripts/config @@ -71,35 +71,34 @@ txt_append() { local anchor=3D"$1" local insert=3D"$2" local infile=3D"$3" - local tmpfile=3D"$infile.swp" =20 # sed append cmd: 'a\' + newline + text + newline cmd=3D"$(printf "a\\%b$insert" "\n")" =20 - sed -E -e "/$anchor/$cmd" "$infile" >"$tmpfile" - # replace original file with the edited one - mv "$tmpfile" "$infile" + # We don't really need a backup file, but in-place editing with backup + # skipped is not portable due to different implementations parsing + # arguments in incompatible manners. + # Create a backup file anyway to ensure portability. The file will be + # deleted on exit. + sed -E -i.swp -e "/$anchor/$cmd" "$infile" + SED_EDITED=3D1 } =20 txt_subst() { local before=3D"$1" local after=3D"$2" local infile=3D"$3" - local tmpfile=3D"$infile.swp" =20 - sed -E -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" >"$tmp= file" - # replace original file with the edited one - mv "$tmpfile" "$infile" + sed -E -i.swp -e "s$SED_DELIM$before$SED_DELIM$after$SED_DELIM" "$infile" + SED_EDITED=3D1 } =20 txt_delete() { local text=3D"$1" local infile=3D"$2" - local tmpfile=3D"$infile.swp" =20 - sed -E -e "/$text/d" "$infile" >"$tmpfile" - # replace original file with the edited one - mv "$tmpfile" "$infile" + sed -E -i.swp -e "/$text/d" "$infile" + SED_EDITED=3D1 } =20 set_var() { @@ -122,6 +121,14 @@ undef_var() { txt_delete "^($name=3D|# $name is not set)" "$FN" } =20 +SED_EDITED=3D0 +on_exit() { + if [ "$SED_EDITED" -ge 1 ]; then + rm -f "$FN.swp" + fi +} +trap on_exit EXIT + FN=3D.config CMDS=3D() while [[ $# -gt 0 ]]; do --=20 2.53.0