* checkpatch.pl misses list_for_each_entry() coding style issues
@ 2014-07-12 23:08 Greg KH
2014-07-13 3:10 ` Joe Perches
2014-07-13 5:33 ` [PATCH] checkpatch: Add for_each tests to indentation and brace tests Joe Perches
0 siblings, 2 replies; 5+ messages in thread
From: Greg KH @ 2014-07-12 23:08 UTC (permalink / raw)
To: Joe Perches; +Cc: LKML
Hi Joe,
The following function:
$ cat foo.c
static int foo_init(void)
{
list_for_each_entry(foo, &foo, list)
{
do_something_foo(foo);
}
return 0;
}
Will not be caught by checkpatch:
$ ./scripts/checkpatch.pl --file foo.c
total: 0 errors, 0 warnings, 11 lines checked
foo.c has no obvious style problems and is ready for submission.
Any way to fix that up?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: checkpatch.pl misses list_for_each_entry() coding style issues 2014-07-12 23:08 checkpatch.pl misses list_for_each_entry() coding style issues Greg KH @ 2014-07-13 3:10 ` Joe Perches 2014-07-13 5:33 ` [PATCH] checkpatch: Add for_each tests to indentation and brace tests Joe Perches 1 sibling, 0 replies; 5+ messages in thread From: Joe Perches @ 2014-07-13 3:10 UTC (permalink / raw) To: Greg KH; +Cc: LKML On Sat, 2014-07-12 at 16:08 -0700, Greg KH wrote: > static int foo_init(void) > { > > list_for_each_entry(foo, &foo, list) > { > do_something_foo(foo); > } > > return 0; > } > > Will not be caught by checkpatch: > > $ ./scripts/checkpatch.pl --file foo.c > total: 0 errors, 0 warnings, 11 lines checked > > foo.c has no obvious style problems and is ready for submission. > > > Any way to fix that up? Probably. Right now it only works on for/do tests. It should probably also work on all functions. I'll play with it. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] checkpatch: Add for_each tests to indentation and brace tests 2014-07-12 23:08 checkpatch.pl misses list_for_each_entry() coding style issues Greg KH 2014-07-13 3:10 ` Joe Perches @ 2014-07-13 5:33 ` Joe Perches 2014-07-14 8:13 ` Andy Whitcroft 1 sibling, 1 reply; 5+ messages in thread From: Joe Perches @ 2014-07-13 5:33 UTC (permalink / raw) To: Andrew Morton; +Cc: Andy Whitcroft, Greg KH, LKML All the various for_each loop macros were not tested for trailing brace on the following lines and for bad indentation. Add them. Reported-by: Greg KH <gregkh@linuxfoundation.org> Signed-off-by: Joe Perches <joe@perches.com> --- On Sat, 2014-07-12 at 16:08 -0700, Greg KH wrote: > The following function: > > $ cat foo.c > > static int foo_init(void) > { > > list_for_each_entry(foo, &foo, list) > { > do_something_foo(foo); > } > > return 0; > } > > Will not be caught by checkpatch: > > $ ./scripts/checkpatch.pl --file foo.c > total: 0 errors, 0 warnings, 11 lines checked > > foo.c has no obvious style problems and is ready for submission. scripts/checkpatch.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d5ac001..5efbf50 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2698,7 +2698,7 @@ sub process { # if/while/etc brace do not go on next line, unless defining a do while loop, # or if that brace on the next line is for something else - if ($line =~ /(.*)\b((?:if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) { + if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) { my $pre_ctx = "$1$2"; my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0); @@ -2744,7 +2744,7 @@ sub process { } # Check relative indent for conditionals and blocks. - if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) { + if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) { ($stat, $cond, $line_nr_next, $remain_next, $off_next) = ctx_statement_block($linenr, $realcnt, 0) if (!defined $stat); ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] checkpatch: Add for_each tests to indentation and brace tests 2014-07-13 5:33 ` [PATCH] checkpatch: Add for_each tests to indentation and brace tests Joe Perches @ 2014-07-14 8:13 ` Andy Whitcroft 2014-07-14 8:18 ` Joe Perches 0 siblings, 1 reply; 5+ messages in thread From: Andy Whitcroft @ 2014-07-14 8:13 UTC (permalink / raw) To: Joe Perches; +Cc: Andrew Morton, Greg KH, LKML On Sat, Jul 12, 2014 at 10:33:54PM -0700, Joe Perches wrote: > All the various for_each loop macros were not tested for > trailing brace on the following lines and for bad indentation. > > Add them. > > Reported-by: Greg KH <gregkh@linuxfoundation.org> > Signed-off-by: Joe Perches <joe@perches.com> > --- > On Sat, 2014-07-12 at 16:08 -0700, Greg KH wrote: > > The following function: > > > > $ cat foo.c > > > > static int foo_init(void) > > { > > > > list_for_each_entry(foo, &foo, list) > > { > > do_something_foo(foo); > > } > > > > return 0; > > } > > > > Will not be caught by checkpatch: > > > > $ ./scripts/checkpatch.pl --file foo.c > > total: 0 errors, 0 warnings, 11 lines checked > > > > foo.c has no obvious style problems and is ready for submission. > > scripts/checkpatch.pl | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl > index d5ac001..5efbf50 100755 > --- a/scripts/checkpatch.pl > +++ b/scripts/checkpatch.pl > @@ -2698,7 +2698,7 @@ sub process { > > # if/while/etc brace do not go on next line, unless defining a do while loop, > # or if that brace on the next line is for something else > - if ($line =~ /(.*)\b((?:if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) { > + if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) { They way you end this first addition with |) converts it the (?:[a-z_]*) doesn't it? Were you intending to do (?:[a-z_]+_|) ? > my $pre_ctx = "$1$2"; > > my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0); > @@ -2744,7 +2744,7 @@ sub process { > } > > # Check relative indent for conditionals and blocks. > - if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) { > + if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) { > ($stat, $cond, $line_nr_next, $remain_next, $off_next) = > ctx_statement_block($linenr, $realcnt, 0) > if (!defined $stat); With the above clarified it all seems sensible. Acked-by: Andy Whitcroft <apw@canonical.com> -apw ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] checkpatch: Add for_each tests to indentation and brace tests 2014-07-14 8:13 ` Andy Whitcroft @ 2014-07-14 8:18 ` Joe Perches 0 siblings, 0 replies; 5+ messages in thread From: Joe Perches @ 2014-07-14 8:18 UTC (permalink / raw) To: Andy Whitcroft; +Cc: Andrew Morton, Greg KH, LKML On Mon, 2014-07-14 at 09:13 +0100, Andy Whitcroft wrote: > On Sat, Jul 12, 2014 at 10:33:54PM -0700, Joe Perches wrote: > > All the various for_each loop macros were not tested for > > trailing brace on the following lines and for bad indentation. > > > > Add them. [] > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl [] > > @@ -2698,7 +2698,7 @@ sub process { > > > > # if/while/etc brace do not go on next line, unless defining a do while loop, > > # or if that brace on the next line is for something else > > - if ($line =~ /(.*)\b((?:if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) { > > + if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) { > > They way you end this first addition with |) converts it the (?:[a-z_]*) > doesn't it? Were you intending to do (?:[a-z_]+_|) ? I didn't think about it much. It's the same thing no? ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-07-14 8:18 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2014-07-12 23:08 checkpatch.pl misses list_for_each_entry() coding style issues Greg KH 2014-07-13 3:10 ` Joe Perches 2014-07-13 5:33 ` [PATCH] checkpatch: Add for_each tests to indentation and brace tests Joe Perches 2014-07-14 8:13 ` Andy Whitcroft 2014-07-14 8:18 ` Joe Perches
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.