From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=199.89.1.14 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796165652; b=ofmI5YWtcYphMUwVM8G14+QGz/sezqwPanzaCgHEsfw8PnkJpjUix59x4wcfzPbGUFRK H0E5ITp6cqr0uG00QXcaSDDQxnYx1AjAIrHO2/3MKXoh5uLz4KcSQOzWllnlLckIiDGRX gRafHDM1FK3bU9A2fHFK0L0IhLZR/yM8aFTGUl2AZRnjG52Vihnc73BJ23RotkhMShr7D MeCeoB2fAwihE4kkuLj6YadWLAD2kA/ZsNXJEW4sh/fJ9da/JWevPvqEPt0Jm3BKVZWbV ztO7GVWyFHlJZt8qbWXViHXMfpWGxesyZ/H7pxAyLDiwNR2yLyq9oR9hB48ilwpuUkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796165652; h=DMARC-Filter:Received:DKIM-Signature:X-Virus-Scanned:Received: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; bh=tsp4kW+eBfJBqf7QZCkmuz3qNoZT+sr0vH8alAwxXgs=; b=Tvpd7ooh/U9DmwCtUUlHpOLkqFvA3Dly2L1fIVACEsg9BLfWzj5vlZFV6q9/DGLNJ+RM o7zY6MXLAdhjvIjpUxeDGxh4QzWo3rxQt4Js3grrNrEXz0ylIpG5uvpcs7nGvfR3Rap9B GSkWyFFfbuEsGc2StpkrstOCrZKl51m/O0NCt4V4C4139hVFfyjEf5KXwEp+JjMsPFeu8 +4MAW+wGAunrtSoYbAtKoZ1OsWV6wvj5n62GzT3g4vSRUcMDo2/9QQxz8ahRRsCLIou3A ot33KazqRpcAqehfWOvzdfgG+u89e7GGR3pILA2keTIr4O0mHihQGNVWrufL/BuEf7w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=acm.org; spf=pass smtp.mailfrom=acm.org; dkim=pass header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=QJm5doj2; arc=none smtp.remote-ip=199.89.1.14 Received: from 011.lax.mailroute.net (011.lax.mailroute.net [199.89.1.14]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2859C606A6A4 for ; Tue, 1 Dec 2026 22:54:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2859C606A6A4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=acm.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=acm.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=acm.org header.i=@acm.org header.a=rsa-sha256 header.s=mr01 header.b=QJm5doj2 Received: from localhost (localhost [127.0.0.1]) by 011.lax.mailroute.net (Postfix) with ESMTP id 4jfGR76dszz1XMYJR; Tue, 1 Dec 2026 22:54:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=mr01; t=1796165647; x=1798757648; bh=tsp4k W+eBfJBqf7QZCkmuz3qNoZT+sr0vH8alAwxXgs=; b=QJm5doj2UEGYq/eIqJGEX mWbaI7TEuEBOCuUIOPm1RwC/TRKJHF/ZWzwQkqwMOgBtdB7ok3ggSKYZnHEAtaFy HnMrUhvhBtY3foodOhWa+l1H9CF3Ma++O8qTdjzQdicoO9BJ2cdm7adkdyXHL1g7 qtsVrAALP1zNgDi6pvMTPkrRMjFS5buHsCqcaSCCQ5MrxlwRnx8QKYAOyHkK0VYV tQC8FoFOR9WSzyz23PZ2fAH1UjkaUOAvqmyB9qFNrfi6QX5Y8m3UbS9434C5qUMS cqSmw1UkF/n03RGxDvgnxNas2TJP1nPR1QxaaHatLQ7HdDVB+/n9RpF9oKiyQtu5 A== X-Virus-Scanned: by MailRoute Received: from 011.lax.mailroute.net ([127.0.0.1]) by localhost (011.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id PdAP0Fmlc1DI; Tue, 1 Dec 2026 22:54:07 +0000 (UTC) Received: from bvanassche.c.googlers.com.com (57.237.82.34.bc.googleusercontent.com [34.82.237.57]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 011.lax.mailroute.net (Postfix) with ESMTPSA id 4jfGQz67xtz1XMYJS; Tue, 1 Dec 2026 22:54:03 +0000 (UTC) From: Bart Van Assche To: Joe Perches , Andy Whitcroft Cc: Andrew Morton , linux-kernel@vger.kernel.org, Bart Van Assche Subject: [PATCH 05/10] checkpatch: avoid dynamic regex recompilation in hot checks Date: Tue, 1 Dec 2026 14:53:49 -0800 Message-ID: <5896ccc8853fef7656779f477b98b58fda1009d9.1796165270.git.bvanassche@acm.org> X-Mailer: git-send-email 2.56.1.911.g883d8bcb20-goog In-Reply-To: References: X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Replace dynamic regex patterns that force Perl to recompile large regular expressions on every match: - SELF_ASSIGNMENT: guard on index($line, '=3D') >=3D 0, capture the right= -hand side in the initial $Declare match, and check it with a static pattern plus string equality instead of interpolating $var alongside $Declare. Keep using the original two-regex check if --typedefsfile is used or if the line contains __aligned because $Declare may then match across an '=3D' sign and the original second regex may select a different split o= f the line than the first match. - EXPORT_SYMBOL: test \n.}\s*$ first and guard the remaining branches on index($stat, $name) >=3D 0 and simpler matches before falling back to patterns interpolating $name with $Type or $Attribute. - PREFER_FALLTHROUGH: hoist @fallthroughs to file scope as a single precompiled $fallthrough_re guarded by /fall/i instead of rebuilding th= e string list per line and recompiling seven patterns per comment line. Signed-off-by: Bart Van Assche --- scripts/checkpatch.pl | 66 +++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index ffafef4cd4f1..fbde43ed1767 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1123,6 +1123,20 @@ our $declaration_macros =3D qr{(?x: __dma_from_device_group_(?:begin|end)\s*\( )}; =20 +our @fallthroughs =3D ( + 'fallthrough', + '@fallthrough@', + 'lint -fallthrough[ \t]*', + 'intentional(?:ly)?[ \t]*fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)', + '(?:else,?\s*)?FALL(?:S | |-)?THR(?:OUGH|U|EW)[ \t.!]*(?:-[^\n\r]*)?', + 'Fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?', + 'fall(?:s | |-)?thr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?', +); +our $fallthrough_re =3D do { + my $joined =3D join('|', @fallthroughs); + qr{$joined}; +}; + our %allow_repeated_words =3D ( add =3D> '', added =3D> '', @@ -4739,9 +4753,14 @@ sub process { # check for self assignments used to avoid compiler warnings # e.g.: int foo =3D foo, *bar =3D NULL; # struct foo bar =3D *(&(bar)); - if ($line =3D~ /^\+\s*(?:$Declare)?([A-Za-z_][A-Za-z\d_]*)\s*=3D/) { - my $var =3D $1; - if ($line =3D~ /^\+\s*(?:$Declare)?$var\s*=3D\s*(?:$var|\*\s*\(?\s*&\= s*\(?\s*$var\s*\)?\s*\)?)\s*[;,]/) { + if (index($line, '=3D') >=3D 0 && + $line =3D~ /^\+\s*(?:$Declare)?([A-Za-z_][A-Za-z\d_]*)\s*=3D(.*)/)= { + my ($var, $rhs) =3D ($1, $2); + if ((!defined($typedefsfile) && + $rhs =3D~ /^\s*(?:([A-Za-z_][A-Za-z\d_]*)|\*\s*\(?\s*&\s*\(?\s*(= [A-Za-z_][A-Za-z\d_]*)\s*\)?\s*\)?)\s*[;,]/ && + (defined($1) ? $1 : $2) eq $var) || + ((defined($typedefsfile) || index($line, '__aligned') >=3D 0) && + $line =3D~ /^\+\s*(?:$Declare)?$var\s*=3D\s*(?:$var|\*\s*\(?\s*&= \s*\(?\s*$var\s*\)?\s*\)?)\s*[;,]/)) { WARN("SELF_ASSIGNMENT", "Do not use self-assignments to avoid compiler warnings\n" . $h= erecurr); } @@ -4874,14 +4893,13 @@ sub process { #print "FOO C name<$name>\n"; $suppress_export{$realline_next} =3D 1; =20 - } elsif ($stat !~ /(?: - \n.}\s*$| - ^.DEFINE_$Ident\(\Q$name\E\)| - ^.DECLARE_$Ident\(\Q$name\E\)| - ^.LIST_HEAD\(\Q$name\E\)| - ^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(| - \b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=3D|\[|\() - )/x) { + } elsif ($stat !~ /\n.}\s*$/ && + (index($stat, $name) < 0 || + ($stat !~ /^.(?:(?:DEFINE|DECLARE)_$Ident|LIST_HEAD)\(\Q$name\E\)/= && + $stat !~ /\b\Q$name\E\s*(?:;|=3D|\[|\()/ && + !($stat =3D~ /\(\s*\*\s*\Q$name\E\s*\)\s*\(/ && + $stat =3D~ /^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\= s*\(/) && + $stat !~ /\b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=3D|\[|\()/))) { #print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n"; $suppress_export{$realline_next} =3D 2; } else { @@ -7631,25 +7649,13 @@ sub process { } =20 # check for /* fallthrough */ like comment, prefer fallthrough; - my @fallthroughs =3D ( - 'fallthrough', - '@fallthrough@', - 'lint -fallthrough[ \t]*', - 'intentional(?:ly)?[ \t]*fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)', - '(?:else,?\s*)?FALL(?:S | |-)?THR(?:OUGH|U|EW)[ \t.!]*(?:-[^\n\r]*)?'= , - 'Fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?', - 'fall(?:s | |-)?thr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?', - ); - if ($raw_comment ne '') { - foreach my $ft (@fallthroughs) { - if ($raw_comment =3D~ /$ft/) { - my $msg_level =3D \&WARN; - $msg_level =3D \&CHK if ($file); - &{$msg_level}("PREFER_FALLTHROUGH", - "Prefer 'fallthrough;' over fallthrough comment\n" . $herecu= rr); - last; - } - } + if ($raw_comment ne '' && + $raw_comment =3D~ /fall/i && + $raw_comment =3D~ $fallthrough_re) { + my $msg_level =3D \&WARN; + $msg_level =3D \&CHK if ($file); + &{$msg_level}("PREFER_FALLTHROUGH", + "Prefer 'fallthrough;' over fallthrough comment\n" . $herecurr= ); } =20 # check for switch/default statements without a break;