Messages in this thread Patch in this message | | | From | Joe Perches <> | Subject | [PATCH] checkpatch: Add PREFER_IS_ENABLED test | Date | Sun, 27 Mar 2016 19:52:18 -0700 |
| |
Using #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE is more verbose than necessary and IS_ENABLED(CONFIG_<FOO>) is preferred.
So add a test and a message for it.
--fix it to if desired.
Signed-off-by: Joe Perches <joe@perches.com> --- scripts/checkpatch.pl | 10 ++++++++++ 1 file changed, 10 insertions(+)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d574d13..eb8f887 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -5637,6 +5637,16 @@ sub process { } } +# check for #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE + if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(CONFIG_[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) { + my $config = $1; + if (WARN("PREFER_IS_ENABLED", + "Prefer IS_ENABLED(<FOO>) to CONFIG_<FOO> || CONFIG_<FOO>_MODULE\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] = "\+#if IS_ENABLED($config)"; + } + } + # check for case / default statements not preceded by break/fallthrough/switch if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) { my $has_break = 0; -- 2.7.4
| |