kbuild: add checks for include of linux/types in userspace headers
authorSam Ravnborg <sam@ravnborg.org>
Tue, 30 Dec 2008 10:34:58 +0000 (11:34 +0100)
committerSam Ravnborg <sam@ravnborg.org>
Fri, 2 Jan 2009 19:43:26 +0000 (20:43 +0100)
If we see __[us](8|16|32|64) then we must include <linux/types.h>
If wee see include of <asm/types.h> then we recommend <linux/types.h>

Original script from Mike but modified by me.

Cc: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
scripts/headers_check.pl

index 72924a7fcf1ea2b88f982c1033402847ba9def36..b62c319611a25a725eeb513b1522c605fea06293 100644 (file)
@@ -34,9 +34,11 @@ foreach my $file (@files) {
        $lineno = 0;
        while ($line = <FH>) {
                $lineno++;
-               check_include();
-               check_prototypes();
-               check_config();
+               &check_include();
+               &check_asm_types();
+               &check_sizetypes();
+               &check_prototypes();
+               &check_config();
        }
        close FH;
 }
@@ -73,3 +75,42 @@ sub check_config
        }
 }
 
+my $linux_asm_types;
+sub check_asm_types()
+{
+       if ($lineno == 1) {
+               $linux_asm_types = 0;
+       } elsif ($linux_asm_types >= 1) {
+               return;
+       }
+       if ($line =~ m/^\s*#\s*include\s+<asm\/types.h>/) {
+               $linux_asm_types = 1;
+               printf STDERR "$filename:$lineno: " .
+               "include of <linux/types.h> is preferred over <asm/types.h>\n"
+               # Warn until headers are all fixed
+               #$ret = 1;
+       }
+}
+
+my $linux_types;
+sub check_sizetypes
+{
+       if ($lineno == 1) {
+               $linux_types = 0;
+       } elsif ($linux_types >= 1) {
+               return;
+       }
+       if ($line =~ m/^\s*#\s*include\s+<linux\/types.h>/) {
+               $linux_types = 1;
+               return;
+       }
+       if ($line =~ m/__[us](8|16|32|64)\b/) {
+               printf STDERR "$filename:$lineno: " .
+                             "found __[us]{8,16,32,64} type " .
+                             "without #include <linux/types.h>\n";
+               $linux_types = 2;
+               # Warn until headers are all fixed
+               #$ret = 1;
+       }
+}
+