linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scripts: checkpatch.pl: Fix existing typedef false positive warning
@ 2014-09-22  1:32 Greg Donald
  2014-09-22  2:31 ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Donald @ 2014-09-22  1:32 UTC (permalink / raw)
  To: Joe Perches, Andy Whitcroft, linux-kernel; +Cc: Greg Donald

Fixing an "open brace '{' following struct go on the same line" error causes a
false positive warning "do not add new typedefs". Fix existing typedef false
positive warning.

Signed-off-by: Greg Donald <gdonald@gmail.com>
---
 scripts/checkpatch.pl | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4d08b39..eafe5e7 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3081,14 +3081,24 @@ sub process {
 		}
 
 # check for new typedefs, only function parameters and sparse annotations
-# make sense.
+# and existing typedefs make sense.
 		if ($line =~ /\btypedef\s/ &&
 		    $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
 		    $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
 		    $line !~ /\b$typeTypedefs\b/ &&
 		    $line !~ /\b__bitwise(?:__|)\b/) {
-			WARN("NEW_TYPEDEFS",
-			     "do not add new typedefs\n" . $herecurr);
+			# check if $line is diff-like
+			if (substr($rawlines[$linenr - 3], 0, 1) eq '-') {
+				my $oldline3 = substr($rawlines[$linenr - 3], 1);
+				# check if typedef already existed
+				if ($line !~ /$oldline3/) {
+					WARN("NEW_TYPEDEFS",
+					     "do not add new typedefs\n" . $herecurr);
+				}
+			} else {
+				WARN("NEW_TYPEDEFS",
+				     "do not add new typedefs\n" . $herecurr);
+			}
 		}
 
 # * goes on variable not on type
-- 
1.9.1


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

* Re: [PATCH] scripts: checkpatch.pl: Fix existing typedef false positive warning
  2014-09-22  1:32 [PATCH] scripts: checkpatch.pl: Fix existing typedef false positive warning Greg Donald
@ 2014-09-22  2:31 ` Joe Perches
  2014-09-22  3:08   ` Greg Donald
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2014-09-22  2:31 UTC (permalink / raw)
  To: Greg Donald; +Cc: Andy Whitcroft, linux-kernel

On Sun, 2014-09-21 at 20:32 -0500, Greg Donald wrote:
> Fixing an "open brace '{' following struct go on the same line" error causes a
> false positive warning "do not add new typedefs". Fix existing typedef false
> positive warning.

This doesn't work.
The matching deleted line can be any number of lines above.

> Signed-off-by: Greg Donald <gdonald@gmail.com>
> ---
>  scripts/checkpatch.pl | 16 +++++++++++++---
>  1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 4d08b39..eafe5e7 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3081,14 +3081,24 @@ sub process {
>  		}
>  
>  # check for new typedefs, only function parameters and sparse annotations
> -# make sense.
> +# and existing typedefs make sense.
>  		if ($line =~ /\btypedef\s/ &&
>  		    $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
>  		    $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
>  		    $line !~ /\b$typeTypedefs\b/ &&
>  		    $line !~ /\b__bitwise(?:__|)\b/) {
> -			WARN("NEW_TYPEDEFS",
> -			     "do not add new typedefs\n" . $herecurr);
> +			# check if $line is diff-like
> +			if (substr($rawlines[$linenr - 3], 0, 1) eq '-') {
> +				my $oldline3 = substr($rawlines[$linenr - 3], 1);
> +				# check if typedef already existed
> +				if ($line !~ /$oldline3/) {
> +					WARN("NEW_TYPEDEFS",
> +					     "do not add new typedefs\n" . $herecurr);
> +				}
> +			} else {
> +				WARN("NEW_TYPEDEFS",
> +				     "do not add new typedefs\n" . $herecurr);
> +			}
>  		}
>  
>  # * goes on variable not on type




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

* Re: [PATCH] scripts: checkpatch.pl: Fix existing typedef false positive warning
  2014-09-22  2:31 ` Joe Perches
@ 2014-09-22  3:08   ` Greg Donald
  2014-09-22  3:49     ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Greg Donald @ 2014-09-22  3:08 UTC (permalink / raw)
  To: Joe Perches; +Cc: Andy Whitcroft, linux-kernel

On Sun, Sep 21, 2014 at 9:31 PM, Joe Perches <joe@perches.com> wrote:
> On Sun, 2014-09-21 at 20:32 -0500, Greg Donald wrote:
>> Fixing an "open brace '{' following struct go on the same line" error causes a
>> false positive warning "do not add new typedefs". Fix existing typedef false
>> positive warning.
>
> This doesn't work.
> The matching deleted line can be any number of lines above.

But this fixes the most common case:

-typedef struct ksock_proto
-{
+typedef struct ksock_proto {

If you're wanting to check more than just $rawlines[$linenr - 3], how
far above does it make sense to go?  From what I'm seeing the '{' is
usually on the next line.


-- 
Greg Donald

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

* Re: [PATCH] scripts: checkpatch.pl: Fix existing typedef false positive warning
  2014-09-22  3:08   ` Greg Donald
@ 2014-09-22  3:49     ` Joe Perches
  0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2014-09-22  3:49 UTC (permalink / raw)
  To: Greg Donald; +Cc: Andy Whitcroft, linux-kernel

On Sun, 2014-09-21 at 22:08 -0500, Greg Donald wrote:
> On Sun, Sep 21, 2014 at 9:31 PM, Joe Perches <joe@perches.com> wrote:
> > On Sun, 2014-09-21 at 20:32 -0500, Greg Donald wrote:
> >> Fixing an "open brace '{' following struct go on the same line" error causes a
> >> false positive warning "do not add new typedefs". Fix existing typedef false
> >> positive warning.
> >
> > This doesn't work.
> > The matching deleted line can be any number of lines above.
> 
> But this fixes the most common case:
> 
> -typedef struct ksock_proto
> -{
> +typedef struct ksock_proto {

Meh.  I think people are smart enough to work
out that this is not a new typedef.

> If you're wanting to check more than just $rawlines[$linenr - 3], how
> far above does it make sense to go?  From what I'm seeing the '{' is
> usually on the next line.

It's not the most common case working, it's the
generic case working.

It's in a large block being changed, it doesn't work.
If it's checking a file, there are no "-" lines.




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

end of thread, other threads:[~2014-09-22  3:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-22  1:32 [PATCH] scripts: checkpatch.pl: Fix existing typedef false positive warning Greg Donald
2014-09-22  2:31 ` Joe Perches
2014-09-22  3:08   ` Greg Donald
2014-09-22  3:49     ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).