From patchwork Sun Jun 14 16:54:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 242331 List-Id: U-Boot discussion From: sjg at chromium.org (Simon Glass) Date: Sun, 14 Jun 2020 10:54:08 -0600 Subject: [PATCH 5/5] checkpatch: Don't warn about PREFER_IF in headers/DT files In-Reply-To: <20200614165409.158795-1-sjg@chromium.org> References: <20200614165409.158795-1-sjg@chromium.org> Message-ID: <20200614165409.158795-6-sjg@chromium.org> This warning should only be displayed for C files. Fix it and update the test. Signed-off-by: Simon Glass --- scripts/checkpatch.pl | 2 +- tools/patman/test_checkpatch.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index edba365651..5731cd221e 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2263,7 +2263,7 @@ sub u_boot_line { } # use if instead of #if - if ($line =~ /^\+#if.*CONFIG.*/) { + if ($realfile =~ /\.c$/ && $line =~ /^\+#if.*CONFIG.*/) { WARN("PREFER_IF", "Use 'if (IS_ENABLED(CONFIG...))' instead of '#if or #ifdef' where possible\n" . $herecurr); } diff --git a/tools/patman/test_checkpatch.py b/tools/patman/test_checkpatch.py index 710b4a7d88..c9580adb54 100644 --- a/tools/patman/test_checkpatch.py +++ b/tools/patman/test_checkpatch.py @@ -388,6 +388,8 @@ index 0000000..2234c87 """Test for Use the livetree API""" pm = PatchMaker() pm.add_line('common/main.c', '#ifdef CONFIG_YELLOW') + pm.add_line('common/init.h', '#ifdef CONFIG_YELLOW') + pm.add_line('fred.dtsi', '#ifdef CONFIG_YELLOW') self.checkSingleMessage(pm, "PREFER_IF") def testCommandUseDefconfig(self):