Skip to contentSkip to conversation

checkpatch.pl misses list_for_each_entry() coding style issues

PATCH In review Greg KH 3 participants 5 messages Jul 12, 2014 – Jul 14, 2014 Checkpatch

lore
Share & tools
lore

Greg KH

author
#0 lore raw

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

maintainer
#1 lore raw
Quoted 13 lines · Greg KH

static int foo_init(void)
{

	list_for_each_entry(foo, &foo, list)
	{
		do_something_foo(foo);
	}

	return 0;
}

Will not be caught by checkpatch:

Quoted 7 lines
$ ./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.

maintainer
#2 lore raw

PATCH 1/1 checkpatch: Add for_each tests to indentation and brace tests

In reply to Greg KH

All the various for_each loop macros were not tested for trailing brace on the following lines and for bad indentation.

Add them.

---

Quoted 15 lines · Greg KH

The following function:

$ cat foo.c 

static int foo_init(void)
{

	list_for_each_entry(foo, &foo, list)
	{
		do_something_foo(foo);
	}

	return 0;
}
Quoted 6 lines

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(-)
scripts/checkpatch.pl +2 -2
index d5ac001..5efbf50 100755
@@ -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);
maintainer Acked-by on v1 1/1
#3 lore raw

Re: [PATCH] checkpatch: Add for_each tests to indentation and brace tests

Quoted 39 lines · Joe Perches

All the various for_each loop macros were not tested for trailing brace on the following lines and for bad indentation.

Add them.

---

Quoted 15 lines · Greg KH

The following function:

$ cat foo.c 

static int foo_init(void)
{

	list_for_each_entry(foo, &foo, list)
	{
		do_something_foo(foo);
	}

	return 0;
}
Quoted 6 lines

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(-)
scripts/checkpatch.pl +0 -0
index d5ac001..5efbf50 100755

scripts/checkpatch.pl sub process { · line 2701

Quoted 5 lines
scripts/checkpatch.pl +1 -1
@@ -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_]+_|) ?

scripts/checkpatch.pl sub process { · line 2750

Quoted 12 lines
scripts/checkpatch.pl +1 -1
 			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.

-apw

maintainer
#4 lore raw

Re: [PATCH] checkpatch: Add for_each tests to indentation and brace tests

Quoted 5 lines · Andy Whitcroft
Quoted 4 lines · Joe Perches

All the various for_each loop macros were not tested for trailing brace on the following lines and for bad indentation.

Add them.

[]

Quoted 1 line

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

Quoted 9 lines

scripts/checkpatch.pl sub process { · line 2701

Quoted 6 lines
scripts/checkpatch.pl +1 -1
@@ -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?