diff mbox series

[v2,2/2] checkpatch.pl: Make CONFIG_IS_ENABLED(CONFIG_*) an error

Message ID 20201005065730.9768-2-alpernebiyasak@gmail.com
State Accepted
Commit b9cca2c57a7f3f51dc044030a2f1665e517edb51
Delegated to: Tom Rini
Headers show
Series [v2,1/2] treewide: Fix wrong CONFIG_IS_ENABLED() handling | expand

Commit Message

Alper Nebi Yasak Oct. 5, 2020, 6:57 a.m. UTC
CONFIG_IS_ENABLED() takes the kconfig name without the CONFIG_ prefix,
e.g. CONFIG_IS_ENABLED(CLK) for CONFIG_CLK. Make including the prefix
an error in checkpatch.pl so calls in the wrong format aren't
accidentally reintroduced.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
---

Changes in v2:
- Add patman test

v1: https://patchwork.ozlabs.org/project/uboot/patch/20200930114612.22319-2-alpernebiyasak@gmail.com/

 scripts/checkpatch.pl           | 6 ++++++
 tools/patman/test_checkpatch.py | 6 ++++++
 2 files changed, 12 insertions(+)

Comments

Simon Glass Oct. 5, 2020, 10:56 a.m. UTC | #1
On Mon, 5 Oct 2020 at 00:57, Alper Nebi Yasak <alpernebiyasak@gmail.com> wrote:
>
> CONFIG_IS_ENABLED() takes the kconfig name without the CONFIG_ prefix,
> e.g. CONFIG_IS_ENABLED(CLK) for CONFIG_CLK. Make including the prefix
> an error in checkpatch.pl so calls in the wrong format aren't
> accidentally reintroduced.
>
> Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
> ---
>
> Changes in v2:
> - Add patman test
>
> v1: https://patchwork.ozlabs.org/project/uboot/patch/20200930114612.22319-2-alpernebiyasak@gmail.com/
>
>  scripts/checkpatch.pl           | 6 ++++++
>  tools/patman/test_checkpatch.py | 6 ++++++
>  2 files changed, 12 insertions(+)
>

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Oct. 14, 2020, 5:43 p.m. UTC | #2
On Mon, Oct 05, 2020 at 09:57:30AM +0300, Alper Nebi Yasak wrote:

> CONFIG_IS_ENABLED() takes the kconfig name without the CONFIG_ prefix,
> e.g. CONFIG_IS_ENABLED(CLK) for CONFIG_CLK. Make including the prefix
> an error in checkpatch.pl so calls in the wrong format aren't
> accidentally reintroduced.
> 
> Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4bed2b0cdc..4ed7e124c9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2365,6 +2365,12 @@  sub u_boot_line {
 		ERROR("DISABLE_FDT_OR_INITRD_RELOC",
 		     "fdt or initrd relocation disabled at boot time\n" . $herecurr);
 	}
+
+	# Do not use CONFIG_ prefix in CONFIG_IS_ENABLED() calls
+	if ($line =~ /^\+.*CONFIG_IS_ENABLED\(CONFIG_\w*\).*/) {
+		ERROR("CONFIG_IS_ENABLED_CONFIG",
+		      "CONFIG_IS_ENABLED() takes values without the CONFIG_ prefix\n" . $herecurr);
+	}
 }
 
 sub process {
diff --git a/tools/patman/test_checkpatch.py b/tools/patman/test_checkpatch.py
index 792196e689..f71c70fb13 100644
--- a/tools/patman/test_checkpatch.py
+++ b/tools/patman/test_checkpatch.py
@@ -405,6 +405,12 @@  index 0000000..2234c87
         pm.add_line('include/myfile.h', '#include <dm.h>')
         self.checkSingleMessage(pm, 'BARRED_INCLUDE_IN_HDR', 'error')
 
+    def testConfigIsEnabledConfig(self):
+        """Test for accidental CONFIG_IS_ENABLED(CONFIG_*) calls"""
+        pm = PatchMaker()
+        pm.add_line('common/main.c', 'if (CONFIG_IS_ENABLED(CONFIG_CLK))')
+        self.checkSingleMessage(pm, 'CONFIG_IS_ENABLED_CONFIG', 'error')
+
 
 if __name__ == "__main__":
     unittest.main()