checkpatch: add DT compatible string documentation checks
authorRob Herring <robh@kernel.org>
Thu, 23 Jan 2014 23:54:51 +0000 (15:54 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 24 Jan 2014 00:36:58 +0000 (16:36 -0800)
This adds a simple check that any compatible strings in DeviceTree dts
files are present in Documentation/devicetree/bindings.  Vendor prefixes
are also checked for existing in vendor-prefixes.txt These should be
temporary checks until we have more sophisticated binding schema
checking.

Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Andy Whitcroft <apw@canonical.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
scripts/checkpatch.pl

index d89e4299c19d5eaa32296d5846027546b63dfbe2..05c99c0b7e6c8e272f374c05f3fa86804efaa5ed 100755 (executable)
@@ -2040,6 +2040,33 @@ sub process {
                             "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag});
                }
 
+# check for DT compatible documentation
+               if (defined $root && $realfile =~ /\.dts/ &&
+                   $rawline =~ /^\+\s*compatible\s*=/) {
+                       my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g;
+
+                       foreach my $compat (@compats) {
+                               my $compat2 = $compat;
+                               my $dt_path =  $root . "/Documentation/devicetree/bindings/";
+                               $compat2 =~ s/\,[a-z]*\-/\,<\.\*>\-/;
+                               `grep -Erq "$compat|$compat2" $dt_path`;
+                               if ( $? >> 8 ) {
+                                       WARN("UNDOCUMENTED_DT_STRING",
+                                            "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr);
+                               }
+
+                               my $vendor = $compat;
+                               my $vendor_path = $dt_path . "vendor-prefixes.txt";
+                               next if (! -f $vendor_path);
+                               $vendor =~ s/^([a-zA-Z0-9]+)\,.*/$1/;
+                               `grep -Eq "$vendor" $vendor_path`;
+                               if ( $? >> 8 ) {
+                                       WARN("UNDOCUMENTED_DT_STRING",
+                                            "DT compatible string vendor \"$vendor\" appears un-documented -- check $vendor_path\n" . $herecurr);
+                               }
+                       }
+               }
+
 # check we are in a valid source file if not then ignore this hunk
                next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);