[PATCH] checkpatch: check parenthesis alignment against unmodified anchor lines

From: Nguyen Dinh Phi

Date: Tue Aug 18 2026 - 12:44:24 EST


The PARENTHESIS_ALIGNMENT check only compares a continuation line's
indentation against the previous line when that previous line was
itself added by the patch (prefixed with '+'). If a patch touches
only the continuation line of a wrapped condition and leaves the
line with the opening parenthesis as unmodified context, the check
is silently skipped even though alignment is broken.

For example, this hunk drops a stale sk_err check but breaks
parenthesis alignment on the remaining continuation line, while the
anchor "while (" line stays as context:

while ((connected = vsock_dequeue_accept(listener)) == NULL &&
- listener->sk_err == 0 && timeout != 0) {
+ timeout != 0) {

checkpatch --strict reports "0 checks" for this hunk because the
anchor line is unchanged context rather than a '+' line, so the
regex matching it never fires.

Relax the anchor-line match to also accept unmodified context lines,
so alignment is still checked against an anchor line the patch
itself didn't touch. Keep the check scoped to lines the patch
actually changes by requiring the current line to start with '+', so
pairs of untouched context lines are not newly flagged.

Signed-off-by: Nguyen Dinh Phi <phind.uet@xxxxxxxxx>
Assisted-by: Claude:claude-sonnet-5
---
scripts/checkpatch.pl | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f424dafce5bc..589fa6572d95 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4057,9 +4057,12 @@ sub process {
}

# check multi-line statement indentation matches previous line
+# (the anchor line may be unchanged context when only a continuation
+# line of the statement is touched by this patch)
if ($perl_version_ok &&
- $prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|(?:\*\s*)*$Lval\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) {
- $prevline =~ /^\+(\t*)(.*)$/;
+ $line =~ /^\+/ &&
+ $prevline =~ /^[\+ ]([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|(?:\*\s*)*$Lval\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) {
+ $prevline =~ /^[\+ ](\t*)(.*)$/;
my $oldindent = $1;
my $rest = $2;

--
2.53.0