[PATCH 6/6] checkpatch.pl: Request if() instead #ifdef

Simon Glass sjg at chromium.org
Sat May 23 00:32:40 CEST 2020


There is a lot of use of #ifdefs in U-Boot. In an effort reduce this,
suggest using the compile-time construct.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 22869992e90..33ec4e2bfd4 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2259,6 +2259,12 @@ sub u_boot_line {
 		WARN("CMD_TEST",
 		     "Possible new command - make sure you add a test\n" . $herecurr);
 	}
+
+	# use if instead of #if
+	if ($line =~ /^\+#if.*CONFIG.*/) {
+		WARN("PREFER_IF",
+		     "Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible\n" . $herecurr);
+	}
 }
 
 sub process {
-- 
2.27.0.rc0.183.gde8f92d652-goog



More information about the U-Boot mailing list