Skip to contentSkip to conversation

checkpatch: check for #if 0/#if 1

PATCH Superseded Prakruthi Deepak Heragu 2 participants 2 messages Jul 25, 2018 – Jul 26, 2018 Checkpatch

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: check for #if 0/#if 1

The #if 0 or #if 1 is used to toggle features. Warn if #if 0 or #if 1 is present and suggest that they can be removed.

---
Changes in v1:
- Rephrase the warning message to fit in a single line without 80 column limit

 scripts/checkpatch.pl | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +8 -3
index 3394ed8..72513c2 100755
@@ -5383,9 +5383,14 @@ sub process {
 
 # warn about #if 0
 		if ($line =~ /^.\s*\#\s*if\s+0\b/) {
-			CHK("REDUNDANT_CODE",
-			    "if this code is redundant consider removing it\n" .
-				$herecurr);
+			WARN("IF_0",
+			     "Consider removing the #if 0 and its #endif\n".  $herecurr);
+		}
+
+# warn about #if 1
+		if ($line =~ /^.\s*\#\s*if\s+1\b/) {
+			WARN("IF_1",
+			     "Consider removing the #if 1 and its #endif\n".  $herecurr);
 		}
 
 # check for needless "if (<foo>) fn(<foo>)" uses
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer
#1 lore raw
Quoted 18 lines · Prakruthi Deepak Heragu

The #if 0 or #if 1 is used to toggle features. Warn if #if 0 or #if 1 is present and suggest that they can be removed.

---
Changes in v1:
- Rephrase the warning message to fit in a single line without 80 column limit

 scripts/checkpatch.pl | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
scripts/checkpatch.pl +0 -0
index 3394ed8..72513c2 100755

scripts/checkpatch.pl sub process { · line 5387

Quoted 8 lines
scripts/checkpatch.pl +2 -3
@@ -5383,9 +5383,14 @@ sub process {
 
 # warn about #if 0
 		if ($line =~ /^.\s*\#\s*if\s+0\b/) {
-			CHK("REDUNDANT_CODE",
-			    "if this code is redundant consider removing it\n" .
-				$herecurr);
+			WARN("IF_0",
+			     "Consider removing the #if 0 and its #endif\n".  $herecurr);

No, this wording is not correct at all.

The entire block, i.e.: 'this code' should be considered to be removed, not just the #if 0 and its #endif.

For #if 1 code, then just the #if 1 and the #endif should be removed.

Quoted 9 lines
scripts/checkpatch.pl +6 -0
+		}
+
+# warn about #if 1
+		if ($line =~ /^.\s*\#\s*if\s+1\b/) {
+			WARN("IF_1",
+			     "Consider removing the #if 1 and its #endif\n".  $herecurr);
 		}
 
 # check for needless "if (<foo>) fn(<foo>)" uses