diff mbox series

[31/31] checkpatch: Don't allow common.h and dm.h in headers

Message ID 20200719161601.495421-32-sjg@chromium.org
State Accepted
Commit 23552ba142860205c4ddec414417cdc251f8cb79
Delegated to: Tom Rini
Headers show
Series dm: Avoid including dm.h in header files | expand

Commit Message

Simon Glass July 19, 2020, 4:16 p.m. UTC
These headers should not be included in other header files. Add a
checkpatch rule and test for this.

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

 scripts/checkpatch.pl           | 10 ++++++++--
 tools/patman/test_checkpatch.py |  7 +++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

Comments

Tom Rini Aug. 4, 2020, 3:06 p.m. UTC | #1
On Sun, Jul 19, 2020 at 10:16:01AM -0600, Simon Glass wrote:

> These headers should not be included in other header files. Add a
> checkpatch rule and test for this.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 238f12cb46..3932362dba 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2322,7 +2322,7 @@  sub get_raw_comment {
 
 # Checks specific to U-Boot
 sub u_boot_line {
-	my ($realfile, $line,  $herecurr) = @_;
+	my ($realfile, $line, $rawline, $herecurr) = @_;
 
 	# ask for a test if a new uclass ID is added
 	if ($realfile =~ /uclass-id.h/ && $line =~ /^\+/) {
@@ -2353,6 +2353,12 @@  sub u_boot_line {
 		ERROR("DEFINE_CONFIG_CMD",
 		      "All commands are managed by Kconfig\n" . $herecurr);
 	}
+
+	# Don't put common.h and dm.h in header files
+	if ($realfile =~ /\.h$/ && $rawline =~ /^\+#include\s*<(common|dm)\.h>*/) {
+		ERROR("BARRED_INCLUDE_IN_HDR",
+		      "Avoid including common.h and dm.h in header files\n" . $herecurr);
+	}
 }
 
 sub process {
@@ -3296,7 +3302,7 @@  sub process {
 		}
 
 		if ($u_boot) {
-			u_boot_line($realfile, $line,  $herecurr);
+			u_boot_line($realfile, $line, $rawline, $herecurr);
 		}
 
 # check we are in a valid source file C or perl if not then ignore this hunk
diff --git a/tools/patman/test_checkpatch.py b/tools/patman/test_checkpatch.py
index 9d233f99ae..792196e689 100644
--- a/tools/patman/test_checkpatch.py
+++ b/tools/patman/test_checkpatch.py
@@ -398,6 +398,13 @@  index 0000000..2234c87
         pm.add_line('common/main.c', '#undef CONFIG_CMD_WHICH')
         self.checkSingleMessage(pm, 'DEFINE_CONFIG_CMD', 'error')
 
+    def testBarredIncludeInHdr(self):
+        """Test for using a barred include in a header file"""
+        pm = PatchMaker()
+        #pm.add_line('include/myfile.h', '#include <common.h>')
+        pm.add_line('include/myfile.h', '#include <dm.h>')
+        self.checkSingleMessage(pm, 'BARRED_INCLUDE_IN_HDR', 'error')
+
 
 if __name__ == "__main__":
     unittest.main()