Re: [PATCH] checkpatch: Warn about data_race() without comment

From: Joe Perches
Date: Wed Apr 01 2020 - 11:19:54 EST


On Wed, 2020-04-01 at 12:17 +0200, Marco Elver wrote:
> Warn about applications of data_race() without a comment, to encourage
> documenting the reasoning behind why it was deemed safe.
[]
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -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",

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