From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754165AbcCMTTo (ORCPT ); Sun, 13 Mar 2016 15:19:44 -0400 Received: from smtprelay0109.hostedemail.com ([216.40.44.109]:45628 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751048AbcCMTTf (ORCPT ); Sun, 13 Mar 2016 15:19:35 -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:1437:1534:1542:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3354:3653:3865:3866:3867:3868:3870:3871:3872:3874:4321:5007:6119:6120:6261:10004:10848:11026:11658:11914:12043:12291:12296:12517:12519:12555:12683:13870:14721:21080:21324:30030:30054: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: river56_70796120b3053 X-Filterd-Recvd-Size: 3163 From: Joe Perches To: Andrew Morton , Andy Whitcroft Cc: Dan Carpenter , Julia Lawall , kernel-janitors , linux-kernel@vger.kernel.org Subject: [RFC PATCH] checkpatch: check formatting of __func__ output uses Date: Sun, 13 Mar 2016 12:19:30 -0700 Message-Id: <83a6236111861645daa6dee9ae7f7aeb03cd7b14.1457896085.git.joe@perches.com> X-Mailer: git-send-email 2.6.3.368.gf34be46 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Loggng messages that emit function names have many different forms. Right now, grep shows these mixtures of forms: 13704 "%s:" 3839 "%s " 2787 "%s()" Some of these are in macros. Perhaps it'd be better for grep and consistency to exclusively use "%s:" Unfortunately, checkpatch isn't an ideal tool to find all these uses. It seems difficult to handle the possible macro definition styles. Maybe coccinelle might be better at it, but here's a possible patch to find the non-macro definition uses. Signed-off-by: Joe Perches --- scripts/checkpatch.pl | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 75ce6d0..727ab64 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1415,6 +1415,22 @@ sub raw_line { return $line; } +sub cooked_line { + my ($linenr, $cnt) = @_; + + my $offset = $linenr - 1; + $cnt++; + + my $line; + while ($cnt) { + $line = $lines[$offset++]; + next if (defined($line) && $line =~ /^-/); + $cnt--; + } + + return $line; +} + sub cat_vet { my ($vet) = @_; my ($res, $coded); @@ -5681,6 +5697,33 @@ sub process { } } +# check how __func__ is formatted, prefer "%s:...', __func__ + if ($^V && $^V ge 5.10.0 && + defined $stat && + $stat =~ /\b__func__\b/ && + $stat =~ /^\+\s*$logFunctions\s*\(\s*[^"]*$String\s*,\s*__func__\b/m && + (() = $stat =~ /^\+|\n\+/g) == 1 && + (() = $stat =~ /;/g) <= 1) { + my $herectx = $here . "\n"; + my $cooked_linenr = -1; + my $cooked_line = ""; + my $raw_line = ""; + my $cnt = statement_rawlines($stat); + for (my $n = 0; $n < $cnt; $n++) { + $herectx .= raw_line($linenr, $n) . "\n"; + if ($cooked_linenr == -1 && cooked_line($linenr, $n) =~ /$String/) { + $cooked_linenr = $linenr + $n; + $cooked_line = cooked_line($linenr, $n); + $raw_line = raw_line($linenr, $n); + } + } + my $qs = get_quoted_string($cooked_line, $raw_line); + if ($qs !~ /^"%s:/) { + WARN("FUNC_STYLE", + "Prefer using formatting style '%s:' for __func__\n" . $herectx); + } + } + # check for uses of __DATE__, __TIME__, __TIMESTAMP__ while ($line =~ /\b(__(?:DATE|TIME|TIMESTAMP)__)\b/g) { ERROR("DATE_TIME", -- 2.6.3.368.gf34be46