Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754232AbbERNdv (ORCPT ); Mon, 18 May 2015 09:33:51 -0400 Received: from mail-wg0-f51.google.com ([74.125.82.51]:32770 "EHLO mail-wg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754208AbbERNdn (ORCPT ); Mon, 18 May 2015 09:33:43 -0400 From: Alex Dowad To: Andy Whitcroft , Joe Perches , linux-kernel@vger.kernel.org (open list) Subject: [PATCH] checkpatch: types found in one source file do not affect processing of others Date: Mon, 18 May 2015 15:33:29 +0200 Message-Id: <1431956009-16076-1-git-send-email-alexinbeijing@gmail.com> X-Mailer: git-send-email 2.0.0.GIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2964 Lines: 90 checkpatch uses various cues in its input files to discover the names of user-defined types. It then uses that information when processing expressions, to discover more style issues. Unfortunately, in rare cases, this means that checkpatch may give different results if you run it on several files at the same time, or one by one! The reason is that it may identify a type (or something that looks like a type) in one file, and then carry this information over when processing a different file. As an example, drivers/staging/media/bcm2048/radio-bcm2048.c contains this line (in a macro): size value; Then drivers/staging/media/davinci_vpfe/vpfe_video.c has this line: while (size * *nbuffers > vpfe_dev->video_limit) If checkpatch processes these 2 files together, the (spurious) "size" type detected in the first file will cause it to flag the second file for improper use of the pointer dereference operator! Therefore, keep user-defined types in a separate array from built-in ones, and reset the array of user-defined types at the beginning of each new source file. Signed-off-by: Alex Dowad --- Dear patch checkers, I am not a Perl programmer -- please let me know if there is a better way to accomplish what I am trying to do here. Your feedback will be appreciated, Alex Dowad scripts/checkpatch.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 89b1df4..5a5668f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -424,6 +424,10 @@ our @typeListWithAttr = ( qr{union\s+$InitAttribute\s+$Ident}, ); +# includes user-defined types discovered in the code +# reset at the beginning of each source file +our @allTypeList = (@typeList); + our @modifierList = ( qr{fastcall}, ); @@ -511,7 +515,7 @@ $misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; sub build_types { my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; - my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; + my $all = "(?x: \n" . join("|\n ", @allTypeList) . "\n)"; my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)"; my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; @@ -745,6 +749,7 @@ for my $filename (@ARGV) { @fixed = (); @fixed_inserted = (); @fixed_deleted = (); + @allTypeList = (@typeList); $fixlinenr = -1; } @@ -1616,7 +1621,7 @@ sub possible { } else { warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible); - push(@typeList, $possible); + push(@allTypeList, $possible); } build_types(); } else { -- 2.0.0.GIT -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/