Received: by 10.223.164.202 with SMTP id h10csp2124271wrb; Thu, 16 Nov 2017 09:43:54 -0800 (PST) X-Google-Smtp-Source: AGs4zMb/OAs8lcXIXXXLbqOgjxB4u59D0127Gjl8fXNJUHcsy+5fx05TZy369pXidNjtt9uFFAfS X-Received: by 10.98.19.23 with SMTP id b23mr2618393pfj.63.1510854234550; Thu, 16 Nov 2017 09:43:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510854234; cv=none; d=google.com; s=arc-20160816; b=piCwjIXxJJhOQ1/h3YJuItoF0yLns8NkKciUtNBk4vJlvEvdJJg66kPdqW1salzL8L SV1BrWMN+hq8ZGchQq1fnko4XMlxUFlpLcJq9nHeKst7WZxKl23ZbWxj++ducafY7MC/ 9hKzKkbUX5rkGTC/y2z2fZUdcKPpaGIHMLu14s1ecdli3GIHWh/pSr2V/WZRUmV1w8yW xvFwiQzVpbwfq8xvWcX9eK09/xISoITktYtnmcJmw0awSJ8QAL5sO7ut5V2S9tLbzz1B skL1oxZeVvKSAdXYqk2apuVL6uqZ4qaO4RF1bNoaEy9aOCJ5qwBSt64hdgkJ9+EdbcWj ojgA== 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:references :in-reply-to:mime-version:message-id:date:subject:cc:to:from :arc-authentication-results; bh=f/z2vG4uErpIJQGxhtR9QLchcGVElolmwBbNVybkKgI=; b=eX44ivAGb+fizET+klRDTwyIe/XlTZijrswk4lzwpWx5/JQL2zoEdFJWZeEyjuHBqL r4JROfs6NDxU0RqblHF6e3EouPss3QNyW5Ua5vmo+EoJTx2hgnPX2O5z2fArhJNODiEN kyvwU8VdnU14G9GsQNuf1YvOsOsYNIra4wn4mXI5UFe8LFOCSQtIryqmj117HmQ95xqV AQ0kXV8mHoA+xtnmTcLc27B/xIhwtZyEfgBZw3WWvVhcQqtMWfm4aKqCDuAyN1hzhNmE XSH0uaf2e5w/5jlIyozPjokyp+OgV8QPEmkuIo2ubS0NNsI0agZkzRRK3nMfCVvdcEnr SfdA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j71si1192318pgc.290.2017.11.16.09.43.37; Thu, 16 Nov 2017 09:43:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965435AbdKPRDg (ORCPT + 92 others); Thu, 16 Nov 2017 12:03:36 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:50958 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936181AbdKPRCj (ORCPT ); Thu, 16 Nov 2017 12:02:39 -0500 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vAGH2XnE000809 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Nov 2017 17:02:33 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id vAGH2XEi008878 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 16 Nov 2017 17:02:33 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id vAGH2Wsw001727; Thu, 16 Nov 2017 17:02:32 GMT Received: from abi.no.oracle.com (/10.172.144.123) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 16 Nov 2017 09:02:31 -0800 From: Knut Omang To: linux-kernel@vger.kernel.org Cc: Knut Omang , Jonathan Corbet , Mauro Carvalho Chehab , =?UTF-8?q?=C3=85smund=20=C3=98stvold?= , John Haxby , Kees Cook , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , =?UTF-8?q?H=C3=A5kon=20Bugge?= , linux-doc@vger.kernel.org Subject: [PATCH 4/7] Documentation: Add documentation for the new P= Makefile option Date: Thu, 16 Nov 2017 18:01:44 +0100 Message-Id: <60bc6e36dd7cdc96b74ed1904355bf334263bc9c.1510840787.git-series.knut.omang@oracle.com> X-Mailer: git-send-email 2.13.6 MIME-Version: 1.0 In-Reply-To: References: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Knut Omang Reviewed-by: Håkon Bugge Reviewed-by: Åsmund Østvold Reviewed-by: John Haxby Signed-off-by: Knut Omang --- Documentation/dev-tools/index.rst | 1 +- Documentation/dev-tools/run-checkpatch.rst | 105 ++++++++++++++++++++++- 2 files changed, 106 insertions(+) create mode 100644 Documentation/dev-tools/run-checkpatch.rst diff --git a/Documentation/dev-tools/index.rst b/Documentation/dev-tools/index.rst index a81787c..b678a3a 100644 --- a/Documentation/dev-tools/index.rst +++ b/Documentation/dev-tools/index.rst @@ -16,6 +16,7 @@ whole; patches welcome! coccinelle sparse + run-checkpatch kcov gcov kasan diff --git a/Documentation/dev-tools/run-checkpatch.rst b/Documentation/dev-tools/run-checkpatch.rst new file mode 100644 index 0000000..c72f818 --- /dev/null +++ b/Documentation/dev-tools/run-checkpatch.rst @@ -0,0 +1,105 @@ +.. Copyright 2017 Knut Omang + +Makefile support for systematic checkpatch testing +================================================== + +The scripts/checkpatch.pl script is able to detect a lot of syntactic and +semantic issues with the code, and is also constantly evolving and detecting +more. In an ideal world, all source files should adhere to whatever rules +imposed by checkpatch.pl with all bells and whistles enabled, in a way that +checkpatch can be run as a reflex by developers (and by bots) from the top level +Makefile for every changing source file. In the real world however there's a +number of challenges: + +* Sometimes there are valid reasons for accepting violations of a checkpatch + rule, even if that rule is a sensible one in the general case. +* Some subsystems have different restrictions and requirements for checkpatch. + (Ideally, the number of subsystems with differing restrictions and + requirements will diminish over time.) +* Similarly, the kernel contains a lot of code that predates checkpatch, or at + least some of the newer rules, and we would like checkpatch to evolve without + requiring the need to fix all issues detected with it in the same commit. +* On the other hand, we want to make sure that files that are checkpatch clean + (to some well defined extent, such as passing checkpatch with checks only for + certain important types of issues) keep being so. + +This is the purpose of supplying the option ``--ignore-cfg checkpatch.cfg`` to +``scripts/checkpatch.pl``. It will then look for a file named ``checkpatch.cfg`` +in the current directory or alternatively in the directory of the source +file. If that file exists, checkpatch parses a set of rules from it, and use +them to determine how to invoke checkpatch for a particular file. The kernel +Makefile system supports using this feature as an integrated part of compiling +the code. + +The ignore configuration file +----------------------------- + +The ignore configuration file can be used to set policies and "rein in" +checkpatch errors piece by piece for a particular subsystem or driver. +The the following syntax is supported:: + + # comments + line_len + except checkpatch_type [files ...] + pervasive checkpatch_type1 [checkpatch_type2 ...] + +The ``line_len`` directive defines the upper bound of characters per line +tolerated in this directory. The ``except`` directive takes a checkpatch type +such as for example ``MACRO_ARG_REUSE``, and a set of files that should not be +subject to this particular check type. You can run ``scripts/checkpatch.pl +--list-types`` to see what types that are available. The ``pervasive`` directive +disables the listed types of checks for all the files in the directory. The +``except`` and ``pervasive`` directives can be used cumulatively to add more +exceptions. + +Running checkpatch from make +---------------------------- + +You can run checkpatch subject to rules defined in ``checkpatch.cfg`` in the +directory of the source file by using "make P=1" to run checkpatch on all files +that gets recompiled, or "make P=2" to run checkpatch on all source files. + +A make variable ``PF`` allows passing additional parameters to +checkpatch.pl. You can for instance use:: + + make P=2 PF="--fix-inplace" + +to have checkpatch trying to fix issues it finds - *make sure you have a clean +git tree and carefully review the output afterwards!* Combine this with +selectively enabling of types of errors via changes to the local +``checkpatch.cfg``, and you can focus on fixing up errors subsystem or driver by +driver on a type by type basis. + +By default checkpatch will skip all files in directories without a +checkpatch.cfg file when invoked with the --ignore-cfg parameter. This is to +allow builds with P=2 to pass even for subsystems that has not yet done anything +to rein in checkpatch errors. At some point when all subsystems and drivers +either have fixed all checkpatch errors or added proper checkpatch.cfg files, +this can be changed. + +To force checkpatch to run a full run in directories without a checkpatch.cfg +file as well, use:: + + make P=2 PF="--req-ignore-cfg" + +If you like to see all the warnings and errors produced by checkpatch, ignoring +any checkpatch.cfg files, you can use:: + + make -k P=2 PF="--no-ignore-cfg" + +or for a specific module directory:: + + make -k P=2 M=drivers/infiniband/core PF="--no-ignore-cfg" + +with the -k option to ``make`` to let it continue upon errors. + +Ever tightening checkpatch rules +-------------------------------- + +Commit the changes to checkpatch.cfg together with the code changes that fixes a +particular type of issue, this will allow automatic checkpatch testing. This way +we can ensure that new errors of that particular type do not inadvertently sneak +in again! This can be done at any subsystem or module maintainer's discretion +and at the right time without having to do it all at the same time. + +Before submitting your changes, verify that "make P=2" passes with no errors. -- git-series 0.9.1 From 1584327180066353371@xxx Fri Nov 17 15:22:20 +0000 2017 X-GM-THRID: 1584327180066353371 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread