All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] checkpatch: check for incorrect permissions
@ 2010-08-12  5:15 Rabin Vincent
  2010-08-12 21:02 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Rabin Vincent @ 2010-08-12  5:15 UTC (permalink / raw)
  To: linux-kernel; +Cc: Rabin Vincent, Andy Whitcroft, Linus Walleij

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.

Cc: Andy Whitcroft <apw@canonical.com>
Acked-by: Linus Walleij <linus.walleij@stericsson.com>
Signed-off-by: Rabin Vincent <rabin.vincent@stericsson.com>
---
 scripts/checkpatch.pl |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2039acd..4c35cb9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1308,7 +1308,7 @@ sub process {
 		$here = "#$realline: " if ($file);
 
 		# extract the filename as it passes
-		if ($line=~/^\+\+\+\s+(\S+)/) {
+		if ($line=~/^\+\+\+\s+(\S+)/ || $line=~/^diff\s.*?(\S+)$/) {
 			$realfile = $1;
 			$realfile =~ s@^([^/]*)/@@;
 
@@ -1332,6 +1332,14 @@ sub process {
 
 		$cnt_lines++ if ($realcnt != 0);
 
+# Check for incorrect file permissions
+		if ($line=~/^new (file )?mode.*[7531]\d{0,2}$/) {
+			my $permhere = $here . "FILE: $realfile\n";
+			if ($realfile=~/(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) {
+				ERROR("do not set execute permissions for source files\n" . $permhere);
+			}
+		}
+
 #check the patch for a signoff:
 		if ($line =~ /^\s*signed-off-by:/i) {
 			# This is a signoff, if ugly, so do not double report.
-- 
1.7.2.dirty


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] checkpatch: check for incorrect permissions
  2010-08-12  5:15 [PATCH] checkpatch: check for incorrect permissions Rabin Vincent
@ 2010-08-12 21:02 ` Andrew Morton
  2010-08-13  4:55   ` Rabin VINCENT
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2010-08-12 21:02 UTC (permalink / raw)
  To: Rabin Vincent; +Cc: linux-kernel, Andy Whitcroft, Linus Walleij

On Thu, 12 Aug 2010 10:45:45 +0530
Rabin Vincent <rabin.vincent@stericsson.com> wrote:

> 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.
> 
> Cc: Andy Whitcroft <apw@canonical.com>
> Acked-by: Linus Walleij <linus.walleij@stericsson.com>
> Signed-off-by: Rabin Vincent <rabin.vincent@stericsson.com>
> ---
>  scripts/checkpatch.pl |   10 +++++++++-
>  1 files changed, 9 insertions(+), 1 deletions(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 2039acd..4c35cb9 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -1308,7 +1308,7 @@ sub process {
>  		$here = "#$realline: " if ($file);
>  
>  		# extract the filename as it passes
> -		if ($line=~/^\+\+\+\s+(\S+)/) {
> +		if ($line=~/^\+\+\+\s+(\S+)/ || $line=~/^diff\s.*?(\S+)$/) {

Breakage.  This causes the false warning:

WARNING: patch prefix 'drivers' exists, appears to be a -p0 patch

to be emitted when processing the below patch:



From: Dan Carpenter <error27@gmail.com>

copy_to_user() returns the number of bytes remaining but we want to return
a negative error code on errors.

Signed-off-by: Dan Carpenter <error27@gmail.com>
Cc: "Michael H. Warfield" <mhw@wittsend.com>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/char/ip2/ip2main.c |    2 ++
 1 file changed, 2 insertions(+)

diff -puN drivers/char/ip2/ip2main.c~ip2-return-efault-on-copy_to_user-errors drivers/char/ip2/ip2main.c
--- a/drivers/char/ip2/ip2main.c~ip2-return-efault-on-copy_to_user-errors
+++ a/drivers/char/ip2/ip2main.c
@@ -2930,6 +2930,8 @@ ip2_ipl_ioctl (struct file *pFile, UINT 
 				if ( pCh )
 				{
 					rc = copy_to_user(argp, pCh, sizeof(i2ChanStr));
+					if (rc)
+						rc = -EFAULT;
 				} else {
 					rc = -ENODEV;
 				}
_


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] checkpatch: check for incorrect permissions
  2010-08-12 21:02 ` Andrew Morton
@ 2010-08-13  4:55   ` Rabin VINCENT
  2010-08-18 11:10     ` Andy Whitcroft
  0 siblings, 1 reply; 4+ messages in thread
From: Rabin VINCENT @ 2010-08-13  4:55 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, Andy Whitcroft, Linus WALLEIJ

On Thu, Aug 12, 2010 at 23:02:22 +0200, Andrew Morton wrote:
> On Thu, 12 Aug 2010 10:45:45 +0530
> Rabin Vincent <rabin.vincent@stericsson.com> wrote:
> >  		# extract the filename as it passes
> > -		if ($line=~/^\+\+\+\s+(\S+)/) {
> > +		if ($line=~/^\+\+\+\s+(\S+)/ || $line=~/^diff\s.*?(\S+)$/) {
> 
> Breakage.  This causes the false warning:
> 
> WARNING: patch prefix 'drivers' exists, appears to be a -p0 patch

I've fixed this by matching for the filename in the diff line only when
it's "diff --git".  Also prevented a double-print of the "do not modify
file in include/asm" error.

>From b854ea24f1bd5391a63d8d4e2aa63e1c10870816 Mon Sep 17 00:00:00 2001
From: Rabin Vincent <rabin.vincent@stericsson.com>
Date: Wed, 11 Aug 2010 14:45:45 +0530
Subject: [PATCHv2] 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.

Cc: Andy Whitcroft <apw@canonical.com>
Acked-by: Linus Walleij <linus.walleij@stericsson.com>
Signed-off-by: Rabin Vincent <rabin.vincent@stericsson.com>
---
 scripts/checkpatch.pl |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2039acd..a6858be 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1308,7 +1308,7 @@ sub process {
 		$here = "#$realline: " if ($file);
 
 		# extract the filename as it passes
-		if ($line=~/^\+\+\+\s+(\S+)/) {
+		if ($line =~ /^\+\+\+\s+(\S+)/ || $line =~ /^diff --git.*?(\S+)$/) {
 			$realfile = $1;
 			$realfile =~ s@^([^/]*)/@@;
 
@@ -1318,6 +1318,10 @@ sub process {
 				WARN("patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
 			}
 
+			# filename based errors will anyway get printed when we
+			# get to the context lines
+			next if ($line =~ /^diff/);
+
 			if ($realfile =~ m@^include/asm/@) {
 				ERROR("do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
 			}
@@ -1332,6 +1336,14 @@ sub process {
 
 		$cnt_lines++ if ($realcnt != 0);
 
+# Check for incorrect file permissions
+		if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
+			my $permhere = $here . "FILE: $realfile\n";
+			if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) {
+				ERROR("do not set execute permissions for source files\n" . $permhere);
+			}
+		}
+
 #check the patch for a signoff:
 		if ($line =~ /^\s*signed-off-by:/i) {
 			# This is a signoff, if ugly, so do not double report.
-- 
1.7.2.dirty


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] checkpatch: check for incorrect permissions
  2010-08-13  4:55   ` Rabin VINCENT
@ 2010-08-18 11:10     ` Andy Whitcroft
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Whitcroft @ 2010-08-18 11:10 UTC (permalink / raw)
  To: Rabin VINCENT; +Cc: Andrew Morton, linux-kernel, Linus WALLEIJ

On Fri, Aug 13, 2010 at 10:25:29AM +0530, Rabin VINCENT wrote:
> On Thu, Aug 12, 2010 at 23:02:22 +0200, Andrew Morton wrote:
> > On Thu, 12 Aug 2010 10:45:45 +0530
> > Rabin Vincent <rabin.vincent@stericsson.com> wrote:
> > >  		# extract the filename as it passes
> > > -		if ($line=~/^\+\+\+\s+(\S+)/) {
> > > +		if ($line=~/^\+\+\+\s+(\S+)/ || $line=~/^diff\s.*?(\S+)$/) {
> > 
> > Breakage.  This causes the false warning:
> > 
> > WARNING: patch prefix 'drivers' exists, appears to be a -p0 patch
> 
> I've fixed this by matching for the filename in the diff line only when
> it's "diff --git".  Also prevented a double-print of the "do not modify
> file in include/asm" error.
> 
> From b854ea24f1bd5391a63d8d4e2aa63e1c10870816 Mon Sep 17 00:00:00 2001
> From: Rabin Vincent <rabin.vincent@stericsson.com>
> Date: Wed, 11 Aug 2010 14:45:45 +0530
> Subject: [PATCHv2] checkpatch: check for incorrect permissions

That one looks better.  I've pull this updated one (slightly modified)
into my tree.

Andrew, will send you this shortly.

-apw

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-08-18 11:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-12  5:15 [PATCH] checkpatch: check for incorrect permissions Rabin Vincent
2010-08-12 21:02 ` Andrew Morton
2010-08-13  4:55   ` Rabin VINCENT
2010-08-18 11:10     ` Andy Whitcroft

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.