diff options
author | Joe Perches <joe@perches.com> | 2016-05-20 17:04:08 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2016-05-20 17:58:30 -0700 |
commit | 481aea5c59a57123b66d5850be1be79f9f230c0e (patch) | |
tree | 5343816c79009d7c9427c3fbe27e7f6a24a402a9 /scripts/checkpatch.pl | |
parent | a91e8994f242a500bf05b9ee96fcd7ab0228f05f (diff) | |
download | linux-stable-481aea5c59a57123b66d5850be1be79f9f230c0e.tar.gz linux-stable-481aea5c59a57123b66d5850be1be79f9f230c0e.tar.bz2 linux-stable-481aea5c59a57123b66d5850be1be79f9f230c0e.zip |
checkpatch: whine about ACCESS_ONCE
Add a test for use of ACCESS_ONCE that could be written using READ_ONCE or
WRITE_ONCE.
--fix it too if desired.
The WRITE_ONCE fixes are less correct than the coccinelle script below as
checkpatch cannot have a completely correct "expression" mechanism because
checkpatch works on patches and not complete files.
$ cat access_once.cocci
@@
expression e1;
expression e2;
@@
- ACCESS_ONCE(e1) = e2
+ WRITE_ONCE(e1, e2)
@@
expression e1;
@@
- ACCESS_ONCE(e1)
+ READ_ONCE(e1)
Signed-off-by: Joe Perches <joe@perches.com>
Cc: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 6c1213cb32c4..1048672c22ee 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -5850,6 +5850,28 @@ sub process { } } +# whine about ACCESS_ONCE + if ($^V && $^V ge 5.10.0 && + $line =~ /\bACCESS_ONCE\s*$balanced_parens\s*(=(?!=))?\s*($FuncArg)?/) { + my $par = $1; + my $eq = $2; + my $fun = $3; + $par =~ s/^\(\s*(.*)\s*\)$/$1/; + if (defined($eq)) { + if (WARN("PREFER_WRITE_ONCE", + "Prefer WRITE_ONCE(<FOO>, <BAR>) over ACCESS_ONCE(<FOO>) = <BAR>\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\bACCESS_ONCE\s*\(\s*\Q$par\E\s*\)\s*$eq\s*\Q$fun\E/WRITE_ONCE($par, $fun)/; + } + } else { + if (WARN("PREFER_READ_ONCE", + "Prefer READ_ONCE(<FOO>) over ACCESS_ONCE(<FOO>)\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\bACCESS_ONCE\s*\(\s*\Q$par\E\s*\)/READ_ONCE($par)/; + } + } + } + # check for lockdep_set_novalidate_class if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ || $line =~ /__lockdep_no_validate__\s*\)/ ) { |