Commit a55ee0cc authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds

checkpatch: look for c99 comments in ctx_locate_comment

Some checks look for comments around a specific function like
read_barrier_depends.

Extend the check to support both c89 and c90 comment styles.

	c89 /* comment */
or
	c99 // comment

For c99 comments, only look a 3 single lines, the line being scanned,
the line above and the line below the line being scanned rather than
the patch diff context.
Signed-off-by: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Tested-by: default avatarPaul E. McKenney <paulmck@kernel.org>
Cc: Marco Elver <elver@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@google.com>
Cc: Andy Whitcroft <apw@canonical.com>
Cc: Will Deacon <will@kernel.org>
Link: http://lkml.kernel.org/r/65cb075435d2f385a53c77571b491b2b09faaf8e.camel@perches.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 7ccf41a8
...@@ -1676,8 +1676,16 @@ sub ctx_statement_level { ...@@ -1676,8 +1676,16 @@ sub ctx_statement_level {
sub ctx_locate_comment { sub ctx_locate_comment {
my ($first_line, $end_line) = @_; my ($first_line, $end_line) = @_;
# If c99 comment on the current line, or the line before or after
my ($current_comment) = ($rawlines[$end_line - 1] =~ m@^\+.*(//.*$)@);
return $current_comment if (defined $current_comment);
($current_comment) = ($rawlines[$end_line - 2] =~ m@^[\+ ].*(//.*$)@);
return $current_comment if (defined $current_comment);
($current_comment) = ($rawlines[$end_line] =~ m@^[\+ ].*(//.*$)@);
return $current_comment if (defined $current_comment);
# Catch a comment on the end of the line itself. # Catch a comment on the end of the line itself.
my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@); ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
return $current_comment if (defined $current_comment); return $current_comment if (defined $current_comment);
# Look through the context and try and figure out if there is a # Look through the context and try and figure out if there is a
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment