public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] checkpatch: handle variables that begin with 'case'
@ 2025-11-14 23:31 Tiffany Yang
  2025-11-14 23:31 ` [PATCH 2/3] checkpatch: check indentation on case without space Tiffany Yang
  2025-11-14 23:31 ` [PATCH] checkpatch: Allow bare SHA-1 hashes in checkpatch commits Tiffany Yang
  0 siblings, 2 replies; 3+ messages in thread
From: Tiffany Yang @ 2025-11-14 23:31 UTC (permalink / raw)
  To: linux-kernel
  Cc: kernel-team, Andy Whitcroft, Joe Perches, Dwaipayan Ray,
	Lukas Bulwahn

The current script returns switch statement-related errors when
variables that start with "case" are used in a ternary.
For example:
    ./scripts/checkpatch.pl --git d1934ed9803c
    ERROR: space prohibited before that ':' (ctx:WxW)
    #289: FILE: drivers/android/tests/binder_alloc_kunit.c:321:
    +				  case_failed ? "FAILED" : "PASSED",
     				                         ^

    ERROR: trailing statements should be on next line
    #289: FILE: drivers/android/tests/binder_alloc_kunit.c:321:
    +				  case_failed ? "FAILED" : "PASSED",

Fix these false positives.

Signed-off-by: Tiffany Yang <ynaffit@google.com>
---
 scripts/checkpatch.pl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 92669904eecc..b026b1235079 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2179,7 +2179,7 @@ sub annotate_values {
 			$av_pending = 'E';
 			$type = 'N';
 
-		} elsif ($cur =~/^(case)/o) {
+		} elsif ($cur =~/^(case)\b/o) {
 			print "CASE($1)\n" if ($dbg_values > 1);
 			$av_pend_colon = 'C';
 			$type = 'N';
@@ -5797,7 +5797,7 @@ sub process {
 				$herecurr);
 		}
 # case and default should not have general statements after them
-		if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
+		if ($line =~ /^.\s*(?:case\b\s*.*|default\s*):/g &&
 		    $line !~ /\G(?:
 			(?:\s*$;*)(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$|
 			\s*return\s+
-- 
2.52.0.rc1.455.g30608eb744-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-11-14 23:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-14 23:31 [PATCH 1/3] checkpatch: handle variables that begin with 'case' Tiffany Yang
2025-11-14 23:31 ` [PATCH 2/3] checkpatch: check indentation on case without space Tiffany Yang
2025-11-14 23:31 ` [PATCH] checkpatch: Allow bare SHA-1 hashes in checkpatch commits Tiffany Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox