Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3489980ybt; Tue, 23 Jun 2020 03:42:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQQDZvXSLdTry1MpZ/0b+U8cHJsrMZlq1LClGS0SpL6mZIBnag2aAr310dNZcEdzz7gvib X-Received: by 2002:a17:906:3653:: with SMTP id r19mr18635612ejb.246.1592908925063; Tue, 23 Jun 2020 03:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592908925; cv=none; d=google.com; s=arc-20160816; b=AHgKQdF/oQZ9KvT0HBY/KCr5DZahckon7aft6shrmJjb2Hq1pmZBSV//8PG/z/ilRN 9plLte7lIxJlfCGdvH5MCkG+0/b6ZRlv7j7JwCljH6+nn+ftXmVS0Z7f9g/F/qxey4Gq TfKMo3K1clsZvgYklgdB7np0HqXfHXSvDtzQyKMqgrAJJJffBnMFjCaZdys5xHocG3eu 1XIAwlVio9WN3bTgOQNrgie+uzdUgy2t1xcNxZPI/Pde+vTt1MkWMv/KwiHbl9kS89Ia yHtHAtSGocPd8yjZaeZFv1tjmihZz/n5xpZ58/gbDgARUdSMFH4A3AQLUTyEH3pBFK03 u9dA== 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=jSGtAZ68yCQRuX8DMTsJCURecPrk2ld6B92Ys0IUNTE=; b=FLl9U/FKJDPcaWp0abrGfF9UEP1dNpXfUMbhV8FaY0qeQOlIBJbA+6g4mdzb+kRYLC nOJca2Tt89jG7Pa0DW4ACOABS/GMCciBwD44/vdLzt9emuXqz1hoEAbSWdQ15/xH9p4N u3FRFcuFcJltVENUWK4V6eXz82n+9SwqjUVrCBkhZ+hrwp6lR6//r2NySeAv0PpIoBOS KOo3ut9IqYlkYnwtF/vTlPysOxuxPvDV76ICarh9emHowY9hrEaMN3K7LHSnlwB3vKIV B4ZCDYPYGL2ZoC4wXB336Ak4p3kf2tarwhia826MG1JiUtSgm05DOi1DLfVMFgPj8HOX /9tA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@isovalent-com.20150623.gappssmtp.com header.s=20150623 header.b=oCy6VBPq; 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 j10si6233669ejs.541.2020.06.23.03.41.41; Tue, 23 Jun 2020 03:42:05 -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=oCy6VBPq; 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 S1732196AbgFWKhw (ORCPT + 99 others); Tue, 23 Jun 2020 06:37:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731968AbgFWKhw (ORCPT ); Tue, 23 Jun 2020 06:37:52 -0400 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1BB34C061573 for ; Tue, 23 Jun 2020 03:37:52 -0700 (PDT) Received: by mail-wm1-x343.google.com with SMTP id g75so2482597wme.5 for ; Tue, 23 Jun 2020 03:37:52 -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=jSGtAZ68yCQRuX8DMTsJCURecPrk2ld6B92Ys0IUNTE=; b=oCy6VBPqVEM/fni40MjgDpQuwDrfvIWlZwyOUm7dmIn1XueTNAsWg/6lk7kNFZ3D0G K/BM4yxM+R7/HvzxfHGDimmafXrWFo4mAnlu2PpXym9fbw2/3sHkK25EO6jgYkMS0nfO dYE7gSqXJnc80DeEi/tA8vVQAqWhP6eFKaCDS/9qKzEDU9M28WE4SxDlsfU4Gtu3/fsW dH9TVX1pckgTBnaBT+KRRAj9KnEKdO6e0SdSkO2TggHPfQ9TAg5jiwrB9HFqILIZhddc +9y0G6tK2KM9tN5wtvLx6IaMUhbquQyXFfMocuY8HEeoMlka8nO0WEL0wZtJlHeDa31X /mSQ== 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=jSGtAZ68yCQRuX8DMTsJCURecPrk2ld6B92Ys0IUNTE=; b=H5J2Jw3ca426yb/CmOUP5hnIq5M8NFlrTsxT+AqzUZoZ/OhOjQUp+zikNE6KLo1NU8 S7Wk4IFb7kuf+0FQYjlZM6fxBHL60vKvMpEBrus5uWpfVUiu1TUMXbtvBriD6ZZupBBd sqnvIKHtunnpnWnXy9RYE/SF2kVsSCYj0FD59wIcD7PAN+5tKugQFPbVsuQjxdRzlMT3 m4K+i6Du6m04DWdySX7gIEy2ZbnoJQkxHarBCJs1Tc6hStKSmG85N2pfGhbOPjbnYuWH AYG91cP6zoiJZbgBgttva7RYLFd+7hgaXtBhZGsosO9srWIjxUnBV46TQ4AbUI9iHgOQ I0RA== X-Gm-Message-State: AOAM5331/ZKW2E+6SwREhc9Kh8iiZVWtLV5UEgwAMkCPN6PpOKx2o8Ao nEkfeZ8YOENdQ7Uz39SCxGPK0Q== X-Received: by 2002:a1c:4b0f:: with SMTP id y15mr24551390wma.83.1592908670822; Tue, 23 Jun 2020 03:37:50 -0700 (PDT) Received: from localhost.localdomain ([194.53.184.63]) by smtp.gmail.com with ESMTPSA id r10sm5283544wrm.17.2020.06.23.03.37.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jun 2020 03:37:49 -0700 (PDT) From: Quentin Monnet To: Andy Whitcroft , Joe Perches , Andrew Morton Cc: linux-kernel@vger.kernel.org, Quentin Monnet Subject: [PATCH v2] checkpatch: fix CONST_STRUCT when const_structs.checkpatch is missing Date: Tue, 23 Jun 2020 11:37:40 +0100 Message-Id: <20200623103740.25876-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. Signed-off-by: Quentin Monnet --- v2: - Check if $const_structs is defined instead of non-empty. - Remove "Fixes" tag. --- scripts/checkpatch.pl | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index db9d94f90431..3b14bf3e4d4e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -770,7 +770,7 @@ sub read_words { next; } - $$wordsRef .= '|' if ($$wordsRef ne ""); + $$wordsRef .= '|' if (defined($$wordsRef) && $$wordsRef ne ""); $$wordsRef .= $line; } close($file); @@ -780,9 +780,11 @@ 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)) { @@ -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