Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752005AbcDQR1H (ORCPT ); Sun, 17 Apr 2016 13:27:07 -0400 Received: from smtprelay0062.hostedemail.com ([216.40.44.62]:46042 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751986AbcDQR1E (ORCPT ); Sun, 17 Apr 2016 13:27:04 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:355:379:541:800:960:973:982:988:989:1260:1345:1359:1437:1534:1541:1711:1730:1747:1777:1792:2197:2199:2393:2559:2562:3138:3139:3140:3141:3142:3353:3653:3865:3866:3868:3871:3872:3874:4321:4605:5007:6261:6691:8957:10004:10226:10848:11026:11232:11473:11658:11914:12043:12291:12295:12296:12438:12517:12519:12555:12663:13069:13161:13229:13311:13357:14181:14384:14394:14721:21080:21221:30022:30054:30056:30070,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: toys39_32505d2fd157 X-Filterd-Recvd-Size: 2712 From: Joe Perches To: Andrew Morton , Andy Whitcroft Cc: Davidlohr Bueso , linux-kernel@vger.kernel.org Subject: [PATCH V2] checkpatch: Whine about ACCESS_ONCE Date: Sun, 17 Apr 2016 10:26:58 -0700 Message-Id: <74599c78fdf441a7dcecc744fef53a7979c8d055.1460913694.git.joe@perches.com> X-Mailer: git-send-email 2.8.0.rc4.16.g56331f8 In-Reply-To: <1460833453.19090.79.camel@perches.com> References: <1460833453.19090.79.camel@perches.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1911 Lines: 69 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 --- V2: Evolution 3.18 is a _really_ bad email client for sending patches. Improve the commit log a little and include a proper coccinelle script. scripts/checkpatch.pl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index e3d9c34..5e5d2a4 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -5837,6 +5837,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(, ) over ACCESS_ONCE() = \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() over ACCESS_ONCE()\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*\)/ ) { -- 2.8.0.rc4.16.g56331f8