Skip to content

Commit 3bf9a00

Browse files
vitkyrkatorvalds
authored andcommitted
checkpatch: check for incorrect permissions
Throw an error when a source file has been given execute permissions using the mode change line present in git diffs. Also alow the filename matching to use the "diff" line in addition to the "+++" line, since the mode change lines appear before any "+++" lines. [apw@canonical.com: simplified filename logic slightly, added tests] Cc: Andy Whitcroft <apw@canonical.com> Acked-by: Linus Walleij <linus.walleij@stericsson.com> Signed-off-by: Rabin Vincent <rabin.vincent@stericsson.com> Signed-off-by: Andy Whitcroft <apw@canonical.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 9fe287d commit 3bf9a00

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

scripts/checkpatch.pl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,11 @@ sub process {
13151315
$here = "#$realline: " if ($file);
13161316

13171317
# extract the filename as it passes
1318-
if ($line=~/^\+\+\+\s+(\S+)/) {
1318+
if ($line =~ /^diff --git.*?(\S+)$/) {
1319+
$realfile = $1;
1320+
$realfile =~ s@^([^/]*)/@@;
1321+
1322+
} elsif ($line =~ /^\+\+\+\s+(\S+)/) {
13191323
$realfile = $1;
13201324
$realfile =~ s@^([^/]*)/@@;
13211325

@@ -1339,6 +1343,14 @@ sub process {
13391343

13401344
$cnt_lines++ if ($realcnt != 0);
13411345

1346+
# Check for incorrect file permissions
1347+
if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
1348+
my $permhere = $here . "FILE: $realfile\n";
1349+
if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) {
1350+
ERROR("do not set execute permissions for source files\n" . $permhere);
1351+
}
1352+
}
1353+
13421354
#check the patch for a signoff:
13431355
if ($line =~ /^\s*signed-off-by:/i) {
13441356
# This is a signoff, if ugly, so do not double report.

0 commit comments

Comments
 (0)