Skip to contentSkip to conversation

checkpatch: check parenthesis alignment against unmodified anchor lines

PATCH New Nguyen Dinh Phi 1 participant 1 message Aug 18 Checkpatch

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: check parenthesis alignment against unmodified anchor lines

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.

Assisted-by Claude:claude-sonnet-5
---
 scripts/checkpatch.pl | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +5 -2
index f424dafce5bc..589fa6572d95 100755
@@ -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;
 
Signature · 1 line
2.53.0