]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
scripts/checkpatch: Avoid false positive on empty blocks
authorAkihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Fri, 24 Apr 2026 09:27:11 +0000 (18:27 +0900)
committerPhilippe Mathieu-Daudé <philmd@linaro.org>
Wed, 6 May 2026 14:10:46 +0000 (16:10 +0200)
SUSPECT_CODE_INDENT checks the first line after a conditional statement.
When the block is empty, the first line after the conditional is the
closing brace at the same indentation level, so checkpatch reports a
bogus indentation error.

Ignore same-indented braces and else statements, matching with:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f6950a735f29e782bc219ece22bb91d6e1ab7bbc

Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Message-ID: <20260424-force_rcu-v4-6-feccfaca0568@rsg.ci.i.u-tokyo.ac.jp>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
scripts/checkpatch.pl

index d440553a7ed03d52784201fff618f156233cfb35..2189db19f5402a36253b134986eb8171f591493e 100755 (executable)
@@ -2283,7 +2283,8 @@ sub process {
                        #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n";
 
                        if ($check && (($sindent % 4) != 0 ||
-                           ($sindent <= $indent && $s ne ''))) {
+                           ($sindent <= $indent &&
+                            $s !~ /^\s*(?:\}|\{|else\b)/))) {
                                ERROR("suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
                        }
                }