Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp61509ybt; Tue, 23 Jun 2020 15:19:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxN4ONKzpZaHhyuyxZrr7PBphsRUtmjqvHiWnIRx/SKFpXg80HBAyiKmLr78oHfY+7YKWrR X-Received: by 2002:a50:f1d9:: with SMTP id y25mr23062493edl.292.1592950771988; Tue, 23 Jun 2020 15:19:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592950771; cv=none; d=google.com; s=arc-20160816; b=oNW3ZDsAaNX5jmNrIs0SuMK7xVnwvaciAHxlnq/g246hY3QS4V9I/QydCmc1Lo9Zdu CV1tnAo106ScPEfxpyg5J1hJ6krh0nzE/13KX3jjat7Z2cC+4y1yrSm6uII6k3yYLZec BQuBDwdfH833d0tjLXVr8+NGeV9wpqLsN2KquJZq6Tk7Hc9K9/FG4Sb8q/zGQwIKm+yx TM/NHUIGoq8fXE9POeETiFcCZVjVEQmk9D+DQX2l/nVVG5XhhcQ8T2sE1+AUX0YBPSCI /lPQ+5z9LG/bSXI2nTYyUDlgneFr8LEvXlAkvAAd3PcA4KFckxbfAGhxNJU0SupIjJhV sr+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=EDoDzgwzXvn64FM+iS8jSPBiWeuVTBlMDJ+h6gF0/y4=; b=eUJ6Ht3EgrcQe/n8IlmVU5ODHh+vjj7epn/kt9luY3A/3kgfuowC8KSD4IVgQzGQUN p0/dropr1YOgZABp4lgCSR+Nt7zUvD6w5gWYaq5+QgRLxDwt1hP/dn0lZ5xpIB5I7WtX ajft02fo0wbPT5C2IjVhHkhYBVlY5vkTMieJHO4sRYOoY6bnU2RwjqxC2fW5UIk9FkzX +NkXr1rcjLdwiT5xaV65WFeLxygRQ9GG2ySPCy5fYC7E2E4EcwjXsPTt6hRA1dy6M24X SKO0O45Eayf3dBSeZdnGrhBLulLtOG1/F+2imxfvzgXxXQSf7PknAqfKXySDCv3ccTXE B7eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@isovalent-com.20150623.gappssmtp.com header.s=20150623 header.b=koEyrONJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b19si1401937edj.598.2020.06.23.15.19.09; Tue, 23 Jun 2020 15:19:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@isovalent-com.20150623.gappssmtp.com header.s=20150623 header.b=koEyrONJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388563AbgFWWSh (ORCPT + 99 others); Tue, 23 Jun 2020 18:18:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387609AbgFWWSg (ORCPT ); Tue, 23 Jun 2020 18:18:36 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3B57C061573 for ; Tue, 23 Jun 2020 15:18:34 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id o8so307929wmh.4 for ; Tue, 23 Jun 2020 15:18:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EDoDzgwzXvn64FM+iS8jSPBiWeuVTBlMDJ+h6gF0/y4=; b=koEyrONJcEQIC2wAovjNrJWAovupzZdarkutAOOx5yvhbte5+hQYIe7v1KJq5XaHSS keNxlHwwopHOl7l9QVqdqvfFIsboZ1pkilBayyAL+sBkomcL9Ocu6AW9LoenF4Q9eSL4 ol3vA5hYPTjO2wJlyum/CqeypM7MXhT2Xb4c6gptcLQOp+92fp+GvcvoMJHaq9s3zMcg E+O7kzrUuuKkI6vhco6b0kB4xOxGnzSruDDMPssp18ZGZYhp6+ixgQM4EaBXQC6WVvPO n+QyT4mPAuGT6TpvUx07gRo4hsxf3HECBY/pVmslsC4ZHKAMrzkQ6H2sGH1MCgmHOvG/ MZqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=EDoDzgwzXvn64FM+iS8jSPBiWeuVTBlMDJ+h6gF0/y4=; b=Sdv/YAPAcjA//WJf2q9Qw2R+onomI0CSdSUjL2U0GuRfAE2R0ED6OyQefJyCEUep0q M4NfF6CMM9w1fEkORUJHeTl1d0NPMujJ3cZjQNAtM1O5FQ8bAX/vVhKUeAlx7QqI6QgR AgH+9ySN+52JxcXg6vstR4lya8se0M0RXTXPRHpPoWV3ZmQswwLjYo0MeCAkJ94fbMDw 4b9jdNvWuC08h2IGHhrWcY5CregMzlUa7N/bnm0amXt5DI/zXanTRiCD/mTdurILnjjt tjpjmrTwALbXjBfaOZjvHQe6JDDGw/wbGMONgJGjQPxbTlR/Yl8lSmnJA22FINo5rRQF 2auQ== X-Gm-Message-State: AOAM530VwU7t05Jez6A5wHA5Z17Gg4fMrpy+TTzzQ575qv2wpVaIeOVg ZD4vUo2/90oBKqmbMmxDkh5ErQ== X-Received: by 2002:a1c:bb43:: with SMTP id l64mr25082188wmf.151.1592950713399; Tue, 23 Jun 2020 15:18:33 -0700 (PDT) Received: from localhost.localdomain ([194.53.184.63]) by smtp.gmail.com with ESMTPSA id x7sm24822120wrr.72.2020.06.23.15.18.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2020 15:18:32 -0700 (PDT) From: Quentin Monnet To: Andy Whitcroft , Joe Perches , Andrew Morton Cc: linux-kernel@vger.kernel.org, Quentin Monnet Subject: [PATCH v3] checkpatch: fix CONST_STRUCT when const_structs.checkpatch is missing Date: Tue, 23 Jun 2020 23:18:22 +0100 Message-Id: <20200623221822.3727-1-quentin@isovalent.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Checkpatch reports warnings when some specific structs are not declared as const in the code. The list of structs to consider was initially defined in the checkpatch.pl script itself, but it was later moved to an external file (scripts/const_structs.checkpatch), in commit bf1fa1dae68e ("checkpatch: externalize the structs that should be const"). This introduced two minor issues: - When file scripts/const_structs.checkpatch is not present (for example, if checkpatch is run outside of the kernel directory with the "--no-tree" option), a warning is printed to stderr to tell the user that "No structs that should be const will be found". This is fair, but the warning is printed unconditionally, even if the option "--ignore CONST_STRUCT" is passed. In the latter case, we explicitly ask checkpatch to skip this check, so no warning should be printed. - When scripts/const_structs.checkpatch is missing, or even when trying to silence the warning by adding an empty file, $const_structs is set to "", and the regex used for finding structs that should be const, "$line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/)", matches all structs found in the code, thus reporting a number of false positives. Let's fix the first item by skipping scripts/const_structs.checkpatch processing if "CONST_STRUCT" checks are ignored, and the second one by skipping the test if $const_structs is not defined. Since we modify the read_words() function a little bit, update the checks for $typedefsfile/$typeOtherTypedefs as well. Signed-off-by: Quentin Monnet --- v3: - Remove comparison to empty string in read_words() and update checks on $typedefsfile/$typeOtherTypedefs in a similar way. v2: - Check if $const_structs is defined instead of non-empty. - Remove "Fixes" tag. --- scripts/checkpatch.pl | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index db9d94f90431..3804f88c3e15 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -62,7 +62,7 @@ my $spelling_file = "$D/spelling.txt"; my $codespell = 0; my $codespellfile = "/usr/share/codespell/dictionary.txt"; my $conststructsfile = "$D/const_structs.checkpatch"; -my $typedefsfile = ""; +my $typedefsfile; my $color = "auto"; my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE # git output parsing needs US English output, so first set backtick child process LANGUAGE @@ -770,7 +770,7 @@ sub read_words { next; } - $$wordsRef .= '|' if ($$wordsRef ne ""); + $$wordsRef .= '|' if (defined $$wordsRef); $$wordsRef .= $line; } close($file); @@ -780,16 +780,18 @@ sub read_words { return 0; } -my $const_structs = ""; -read_words(\$const_structs, $conststructsfile) - or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; +my $const_structs; +if (show_type("CONST_STRUCT")) { + read_words(\$const_structs, $conststructsfile) + or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; +} -my $typeOtherTypedefs = ""; -if (length($typedefsfile)) { +if (defined($typedefsfile)) { + my $typeOtherTypedefs; read_words(\$typeOtherTypedefs, $typedefsfile) or warn "No additional types will be considered - file '$typedefsfile': $!\n"; + $typeTypedefs .= '|' . $typeOtherTypedefs if (defined $typeOtherTypedefs); } -$typeTypedefs .= '|' . $typeOtherTypedefs if ($typeOtherTypedefs ne ""); sub build_types { my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; @@ -6656,7 +6658,8 @@ sub process { # check for various structs that are normally const (ops, kgdb, device_tree) # and avoid what seem like struct definitions 'struct foo {' - if ($line !~ /\bconst\b/ && + if (defined($const_structs) && + $line !~ /\bconst\b/ && $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) { WARN("CONST_STRUCT", "struct $1 should normally be const\n" . $herecurr); -- 2.20.1