Commit 483b41218fa9d5172312a9e294aaf78e22b266e6

Authored by Sam Ravnborg
1 parent 521b0c774d

kbuild: add checks for include of linux/types in userspace headers

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>

Showing 1 changed file with 44 additions and 3 deletions Side-by-side Diff

scripts/headers_check.pl
... ... @@ -34,9 +34,11 @@
34 34 $lineno = 0;
35 35 while ($line = <FH>) {
36 36 $lineno++;
37   - check_include();
38   - check_prototypes();
39   - check_config();
  37 + &check_include();
  38 + &check_asm_types();
  39 + &check_sizetypes();
  40 + &check_prototypes();
  41 + &check_config();
40 42 }
41 43 close FH;
42 44 }
... ... @@ -70,6 +72,45 @@
70 72 {
71 73 if ($line =~ m/[^a-zA-Z0-9_]+CONFIG_([a-zA-Z0-9]+)[^a-zA-Z0-9]/) {
72 74 printf STDERR "$filename:$lineno: leaks CONFIG_$1 to userspace where it is not valid\n";
  75 + }
  76 +}
  77 +
  78 +my $linux_asm_types;
  79 +sub check_asm_types()
  80 +{
  81 + if ($lineno == 1) {
  82 + $linux_asm_types = 0;
  83 + } elsif ($linux_asm_types >= 1) {
  84 + return;
  85 + }
  86 + if ($line =~ m/^\s*#\s*include\s+<asm\/types.h>/) {
  87 + $linux_asm_types = 1;
  88 + printf STDERR "$filename:$lineno: " .
  89 + "include of <linux/types.h> is preferred over <asm/types.h>\n"
  90 + # Warn until headers are all fixed
  91 + #$ret = 1;
  92 + }
  93 +}
  94 +
  95 +my $linux_types;
  96 +sub check_sizetypes
  97 +{
  98 + if ($lineno == 1) {
  99 + $linux_types = 0;
  100 + } elsif ($linux_types >= 1) {
  101 + return;
  102 + }
  103 + if ($line =~ m/^\s*#\s*include\s+<linux\/types.h>/) {
  104 + $linux_types = 1;
  105 + return;
  106 + }
  107 + if ($line =~ m/__[us](8|16|32|64)\b/) {
  108 + printf STDERR "$filename:$lineno: " .
  109 + "found __[us]{8,16,32,64} type " .
  110 + "without #include <linux/types.h>\n";
  111 + $linux_types = 2;
  112 + # Warn until headers are all fixed
  113 + #$ret = 1;
73 114 }
74 115 }