checkpatch: Warn about data_race() without comment
PATCH 1/1 checkpatch: Warn about data_race() without comment
Warn about applications of data_race() without a comment, to encourage documenting the reasoning behind why it was deemed safe.
--- scripts/checkpatch.pl | 8 ++++++++ 1 file changed, 8 insertions(+)
scripts/checkpatch.pl +8 -0
@@ -5833,6 +5833,14 @@ sub process { } } +# check for data_race without a comment. + if ($line =~ /\bdata_race\s*\(/) { + if (!ctx_has_comment($first_line, $linenr)) { + WARN("DATA_RACE", + "data_race without comment\n" . $herecurr); + } + } + # check for smp_read_barrier_depends and read_barrier_depends if (!$file && $line =~ /\b(smp_|)read_barrier_depends\s*\(/) { WARN("READ_BARRIER_DEPENDS",
Signature · 1 line
2.26.0.rc2.310.g2932bb562d-goog
Quoted 15 lines · Marco Elver
Warn about applications of
data_race()without a comment, to encourage documenting the reasoning behind why it was deemed safe.Suggested-by Will Deacon <[email protected]>Signed-off-by Marco Elver <[email protected]>--- scripts/checkpatch.pl | 8 ++++++++ 1 file changed, 8 insertions(+)scripts/checkpatch.pl +0
-0@@ -5833,6 +5833,14 @@ sub process { }
scripts/checkpatch.pl sub process { · line 5843
Quoted 10 lines
scripts/checkpatch.pl +8
-0} +# check for data_race without a comment. + if ($line =~ /\bdata_race\s*\(/) { + if (!ctx_has_comment($first_line, $linenr)) { + WARN("DATA_RACE", + "data_race without comment\n" . $herecurr); + } + } +
Thanks, looks sane to me:
Although I suppose I now need to add some comments to my list stuff. I didn't think that through, did I? ;)
Will
Joe Perches
maintainerQuoted 2 lines · Marco Elver
Warn about applications of
data_race()without a comment, to encourage documenting the reasoning behind why it was deemed safe.
[]
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0
[]
Quoted 5 lines
scripts/checkpatch.pl +1
-0@@ -5833,6 +5833,14 @@ sub process { } } +# check for data_race without a comment.
scripts/checkpatch.pl sub process { · line 5846
Quoted 10 lines
scripts/checkpatch.pl +7
-0+ if ($line =~ /\bdata_race\s*\(/) { + if (!ctx_has_comment($first_line, $linenr)) { + WARN("DATA_RACE", + "data_race without comment\n" . $herecurr); + } + } + # check for smp_read_barrier_depends and read_barrier_depends if (!$file && $line =~ /\b(smp_|)read_barrier_depends\s*\(/) { WARN("READ_BARRIER_DEPENDS",
Sensible enough but it looks like ctx_has_comment should be updated to allow c99 comments too, but that should be a separate change from this patch.
Otherwise, this style emits a message:
WARNING: data_race without comment
#135: FILE: kernel/rcu/tasks.h:135:
+ int i = data_race(rtp->gp_state); // Let KCSAN detect update races
Quoted 31 lines · Joe Perches
Quoted 2 lines · Marco Elver
Warn about applications of
data_race()without a comment, to encourage documenting the reasoning behind why it was deemed safe.[]
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0[]
Quoted 5 lines
scripts/checkpatch.pl +1
-0@@ -5833,6 +5833,14 @@ sub process { } } +# check for data_race without a comment.scripts/checkpatch.pl sub process { · line 5846
Quoted 10 lines
scripts/checkpatch.pl +7
-0+ if ($line =~ /\bdata_race\s*\(/) { + if (!ctx_has_comment($first_line, $linenr)) { + WARN("DATA_RACE", + "data_race without comment\n" . $herecurr); + } + } + # check for smp_read_barrier_depends and read_barrier_depends if (!$file && $line =~ /\b(smp_|)read_barrier_depends\s*\(/) { WARN("READ_BARRIER_DEPENDS",Sensible enough but it looks like
ctx_has_commentshould be updated to allow c99 comments too, but that should be a separate change from this patch.Otherwise, this style emits a message:
WARNING:
data_racewithout comment
#135: FILE:kernel/rcu/tasks.h:135:
Review
Quoted 1 line
(quoted diff) +1
-0+ int i = data_race(rtp->gp_state); // Let KCSAN detect update races
Yes, please!
Thanx, Paul
Joe Perches
maintainerPATCH 1/1 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.
--- scripts/checkpatch.pl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
scripts/checkpatch.pl +9 -1
@@ -1674,8 +1674,16 @@ sub ctx_statement_level { sub ctx_locate_comment { 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. - 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); # Look through the context and try and figure out if there is a
Re: [PATCH] checkpatch: Look for c99 comments in ctx_locate_comment
Quoted 9 lines · Joe Perches
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
Quoted 5 lines
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 Joe Perches <[email protected]>
Quoted 28 lines
--- scripts/checkpatch.pl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)scripts/checkpatch.pl +9
-1@@ -1674,8 +1674,16 @@ sub ctx_statement_level { sub ctx_locate_comment { 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. - 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); # Look through the context and try and figure out if there is a
Quoted 11 lines · Joe Perches
Quoted 2 lines · Marco Elver
Warn about applications of
data_race()without a comment, to encourage documenting the reasoning behind why it was deemed safe.[]
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0[]
Quoted 4 lines
scripts/checkpatch.pl +0
-0@@ -5833,6 +5833,14 @@ sub process { } }
Quoted 11 lines
scripts/checkpatch.pl sub process { · line 5846
Quoted 11 lines
scripts/checkpatch.pl +8
-0+# check for data_race without a comment. + if ($line =~ /\bdata_race\s*\(/) { + if (!ctx_has_comment($first_line, $linenr)) { + WARN("DATA_RACE", + "data_race without comment\n" . $herecurr); + } + } + # check for smp_read_barrier_depends and read_barrier_depends if (!$file && $line =~ /\b(smp_|)read_barrier_depends\s*\(/) { WARN("READ_BARRIER_DEPENDS",
Do we still want to do this? Which tree can pick this up? Or was there anything left that we missed?
Quoted 3 lines
Sensible enough but it looks like
ctx_has_commentshould be updated to allow c99 comments too, but that should be a separate change from this patch.
AFAIK the C99 comment patch is in -mm now.
Quoted 6 lines
Otherwise, this style emits a message:
WARNING:
data_racewithout comment
#135: FILE:kernel/rcu/tasks.h:135:
+ int i =data_race(rtp->gp_state); // Let KCSAN detect update races
Thanks,
-- Marco