* [PATCH] checkpatch: add --fix option to IS_ENABLED_CONFIG check
@ 2020-12-10 14:19 Dwaipayan Ray
2020-12-10 14:36 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: Dwaipayan Ray @ 2020-12-10 14:19 UTC (permalink / raw)
To: joe; +Cc: linux-kernel-mentees, dwaipayanray1, linux-kernel, lukas.bulwahn
Documentation/process/coding-style.rst specifies the use of
IS_ENABLED macro:
Within code, where possible, use the IS_ENABLED macro to convert a Kconfig
symbol into a C boolean expression, and use it in a normal C conditional:
if (IS_ENABLED(CONFIG_SOMETHING)) {
...
}
checkpatch correspondingly has a check for IS_ENABLED() without
CONFIG_<FOO>.
Add a --fix option to the check to automatically correct the argument.
Macros like:
#if IS_ENABLED(THERMAL)
is corrected to:
#if IS_ENABLED(CONFIG_THERMAL)
Signed-off-by: Dwaipayan Ray <dwaipayanray1@gmail.com>
---
scripts/checkpatch.pl | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7b086d1cd6c2..751cd13622b9 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6877,8 +6877,11 @@ sub process {
# check for IS_ENABLED() without CONFIG_<FOO> ($rawline for comments too)
if ($rawline =~ /\bIS_ENABLED\s*\(\s*(\w+)\s*\)/ && $1 !~ /^${CONFIG_}/) {
- WARN("IS_ENABLED_CONFIG",
- "IS_ENABLED($1) is normally used as IS_ENABLED(${CONFIG_}$1)\n" . $herecurr);
+ if (WARN("IS_ENABLED_CONFIG",
+ "IS_ENABLED($1) is normally used as IS_ENABLED(${CONFIG_}$1)\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\bIS_ENABLED\s*\(\s*(\w+)\s*\)/IS_ENABLED(${CONFIG_}$1)/;
+ }
}
# check for #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE
--
2.27.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] checkpatch: add --fix option to IS_ENABLED_CONFIG check
2020-12-10 14:19 [PATCH] checkpatch: add --fix option to IS_ENABLED_CONFIG check Dwaipayan Ray
@ 2020-12-10 14:36 ` Joe Perches
2020-12-10 14:54 ` Dwaipayan Ray
0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2020-12-10 14:36 UTC (permalink / raw)
To: Dwaipayan Ray; +Cc: linux-kernel-mentees, linux-kernel, lukas.bulwahn
On Thu, 2020-12-10 at 19:49 +0530, Dwaipayan Ray wrote:
> Documentation/process/coding-style.rst specifies the use of
> IS_ENABLED macro:
>
> Within code, where possible, use the IS_ENABLED macro to convert a Kconfig
> symbol into a C boolean expression, and use it in a normal C conditional:
>
> if (IS_ENABLED(CONFIG_SOMETHING)) {
> ...
> }
>
> checkpatch correspondingly has a check for IS_ENABLED() without
> CONFIG_<FOO>.
> Add a --fix option to the check to automatically correct the argument.
>
> Macros like:
> #if IS_ENABLED(THERMAL)
>
> is corrected to:
> #if IS_ENABLED(CONFIG_THERMAL)
I think adding a --fix option here is not a good option.
Look at the existing uses without CONFIG and tell me
the majority of them need to have CONFIG added.
$ git grep -P '\bIS_ENABLED\s*\(\s*(?!CONFIG_)'
arch/arc/include/asm/asserts.h: chk_opt_strict(#opt_name, hw_exists, IS_ENABLED(opt_name)); \
arch/arc/include/asm/asserts.h: chk_opt_weak(#opt_name, hw_exists, IS_ENABLED(opt_name)); \
arch/arc/include/asm/setup.h:#define IS_USED_CFG(cfg) IS_USED_RUN(IS_ENABLED(cfg))
arch/arm64/include/asm/alternative-macros.h: __ALTERNATIVE_CFG(oldinstr, newinstr, feature, IS_ENABLED(cfg))
arch/arm64/include/asm/alternative-macros.h: alternative_insn insn1, insn2, cap, IS_ENABLED(cfg)
arch/arm64/include/asm/cpufeature.h: (IS_ENABLED(config) ? FTR_VISIBLE : FTR_HIDDEN)
arch/x86/mm/numa.c: if (IS_ENABLED(NODE_NOT_IN_PAGE_FLAGS)) {
drivers/gpu/drm/exynos/exynos_drm_drv.c:#define DRV_PTR(drv, cond) (IS_ENABLED(cond) ? &drv : NULL)
drivers/gpu/drm/i915/i915_utils.h: * This is a lookalike for IS_ENABLED() that takes a kconfig value,
drivers/gpu/drm/i915/i915_utils.h: * Sadly IS_ENABLED() itself does not work with kconfig values.
drivers/gpu/drm/rockchip/rockchip_drm_drv.c: if (IS_ENABLED(cond) && \
drivers/net/wireguard/allowedips.c: WARN_ON(IS_ENABLED(DEBUG) && *len >= 128);
drivers/net/wireguard/allowedips.c: WARN_ON(IS_ENABLED(DEBUG) && len >= 128); \
drivers/net/wireguard/noise.c: WARN_ON(IS_ENABLED(DEBUG) &&
drivers/net/wireguard/selftest/allowedips.c: if (IS_ENABLED(DEBUG_PRINT_TRIE_GRAPHVIZ)) {
drivers/net/wireguard/selftest/allowedips.c: if (IS_ENABLED(DEBUG_PRINT_TRIE_GRAPHVIZ)) {
drivers/net/wireguard/selftest/allowedips.c: if (IS_ENABLED(DEBUG_RANDOM_TRIE) && success)
drivers/phy/broadcom/phy-brcm-usb-init.h: if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(__BIG_ENDIAN))
drivers/phy/broadcom/phy-brcm-usb-init.h: if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(__BIG_ENDIAN))
include/asm-generic/vmlinux.lds.h:#define OF_TABLE(cfg, name) __OF_TABLE(IS_ENABLED(cfg), name)
include/crypto/blake2s.h: WARN_ON(IS_ENABLED(DEBUG) && (!outlen || outlen > BLAKE2S_HASH_SIZE ||
include/crypto/blake2s.h: WARN_ON(IS_ENABLED(DEBUG) && ((!in && inlen > 0) || !out || !outlen ||
include/linux/init.h: int var = IS_ENABLED(config); \
include/linux/kconfig.h: * This is similar to IS_ENABLED(), but returns false when invoked from
include/linux/kconfig.h:#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
include/linux/page-flags-layout.h: * the IS_ENABLED() macro.
include/linux/raid/pq.h:#define IS_ENABLED(x) (x)
lib/crypto/blake2s-generic.c: WARN_ON(IS_ENABLED(DEBUG) &&
lib/crypto/blake2s.c: WARN_ON(IS_ENABLED(DEBUG) && !out);
lib/crypto/chacha20poly1305-selftest.c: for (total_len = POLY1305_DIGEST_SIZE; IS_ENABLED(DEBUG_CHACHA20POLY1305_SLOW_CHUNK_TEST)
lib/test_ubsan.c: #config, IS_ENABLED(config) ? "y" : "n"); \
scripts/checkpatch.pl:# check for IS_ENABLED() without CONFIG_<FOO> ($rawline for comments too)
scripts/checkpatch.pl: "IS_ENABLED($1) is normally used as IS_ENABLED(${CONFIG_}$1)\n" . $herecurr);
scripts/checkpatch.pl: "Prefer IS_ENABLED(<FOO>) to ${CONFIG_}<FOO> || ${CONFIG_}<FOO>_MODULE\n" . $herecurr) &&
scripts/checkpatch.pl: $fixed[$fixlinenr] = "\+#if IS_ENABLED($config)";
tools/testing/scatterlist/linux/mm.h:#define IS_ENABLED(x) (0)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] checkpatch: add --fix option to IS_ENABLED_CONFIG check
2020-12-10 14:36 ` Joe Perches
@ 2020-12-10 14:54 ` Dwaipayan Ray
0 siblings, 0 replies; 3+ messages in thread
From: Dwaipayan Ray @ 2020-12-10 14:54 UTC (permalink / raw)
To: Joe Perches; +Cc: linux-kernel-mentees, linux-kernel, Lukas Bulwahn
> > checkpatch correspondingly has a check for IS_ENABLED() without
> > CONFIG_<FOO>.
> > Add a --fix option to the check to automatically correct the argument.
> >
> > Macros like:
> > #if IS_ENABLED(THERMAL)
> >
> > is corrected to:
> > #if IS_ENABLED(CONFIG_THERMAL)
>
> I think adding a --fix option here is not a good option.
>
> Look at the existing uses without CONFIG and tell me
> the majority of them need to have CONFIG added.
>
> $ git grep -P '\bIS_ENABLED\s*\(\s*(?!CONFIG_)'
> arch/arc/include/asm/asserts.h: chk_opt_strict(#opt_name, hw_exists, IS_ENABLED(opt_name)); \
> arch/arc/include/asm/asserts.h: chk_opt_weak(#opt_name, hw_exists, IS_ENABLED(opt_name)); \
> arch/arc/include/asm/setup.h:#define IS_USED_CFG(cfg) IS_USED_RUN(IS_ENABLED(cfg))
> arch/arm64/include/asm/alternative-macros.h: __ALTERNATIVE_CFG(oldinstr, newinstr, feature, IS_ENABLED(cfg))
> arch/arm64/include/asm/alternative-macros.h: alternative_insn insn1, insn2, cap, IS_ENABLED(cfg)
> arch/arm64/include/asm/cpufeature.h: (IS_ENABLED(config) ? FTR_VISIBLE : FTR_HIDDEN)
> arch/x86/mm/numa.c: if (IS_ENABLED(NODE_NOT_IN_PAGE_FLAGS)) {
> drivers/gpu/drm/exynos/exynos_drm_drv.c:#define DRV_PTR(drv, cond) (IS_ENABLED(cond) ? &drv : NULL)
> drivers/gpu/drm/i915/i915_utils.h: * This is a lookalike for IS_ENABLED() that takes a kconfig value,
> drivers/gpu/drm/i915/i915_utils.h: * Sadly IS_ENABLED() itself does not work with kconfig values.
> drivers/gpu/drm/rockchip/rockchip_drm_drv.c: if (IS_ENABLED(cond) && \
> drivers/net/wireguard/allowedips.c: WARN_ON(IS_ENABLED(DEBUG) && *len >= 128);
> drivers/net/wireguard/allowedips.c: WARN_ON(IS_ENABLED(DEBUG) && len >= 128); \
> drivers/net/wireguard/noise.c: WARN_ON(IS_ENABLED(DEBUG) &&
> drivers/net/wireguard/selftest/allowedips.c: if (IS_ENABLED(DEBUG_PRINT_TRIE_GRAPHVIZ)) {
> drivers/net/wireguard/selftest/allowedips.c: if (IS_ENABLED(DEBUG_PRINT_TRIE_GRAPHVIZ)) {
> drivers/net/wireguard/selftest/allowedips.c: if (IS_ENABLED(DEBUG_RANDOM_TRIE) && success)
> drivers/phy/broadcom/phy-brcm-usb-init.h: if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(__BIG_ENDIAN))
> drivers/phy/broadcom/phy-brcm-usb-init.h: if (IS_ENABLED(CONFIG_MIPS) && IS_ENABLED(__BIG_ENDIAN))
> include/asm-generic/vmlinux.lds.h:#define OF_TABLE(cfg, name) __OF_TABLE(IS_ENABLED(cfg), name)
> include/crypto/blake2s.h: WARN_ON(IS_ENABLED(DEBUG) && (!outlen || outlen > BLAKE2S_HASH_SIZE ||
> include/crypto/blake2s.h: WARN_ON(IS_ENABLED(DEBUG) && ((!in && inlen > 0) || !out || !outlen ||
> include/linux/init.h: int var = IS_ENABLED(config); \
> include/linux/kconfig.h: * This is similar to IS_ENABLED(), but returns false when invoked from
> include/linux/kconfig.h:#define IS_ENABLED(option) __or(IS_BUILTIN(option), IS_MODULE(option))
> include/linux/page-flags-layout.h: * the IS_ENABLED() macro.
> include/linux/raid/pq.h:#define IS_ENABLED(x) (x)
> lib/crypto/blake2s-generic.c: WARN_ON(IS_ENABLED(DEBUG) &&
> lib/crypto/blake2s.c: WARN_ON(IS_ENABLED(DEBUG) && !out);
> lib/crypto/chacha20poly1305-selftest.c: for (total_len = POLY1305_DIGEST_SIZE; IS_ENABLED(DEBUG_CHACHA20POLY1305_SLOW_CHUNK_TEST)
> lib/test_ubsan.c: #config, IS_ENABLED(config) ? "y" : "n"); \
> scripts/checkpatch.pl:# check for IS_ENABLED() without CONFIG_<FOO> ($rawline for comments too)
> scripts/checkpatch.pl: "IS_ENABLED($1) is normally used as IS_ENABLED(${CONFIG_}$1)\n" . $herecurr);
> scripts/checkpatch.pl: "Prefer IS_ENABLED(<FOO>) to ${CONFIG_}<FOO> || ${CONFIG_}<FOO>_MODULE\n" . $herecurr) &&
> scripts/checkpatch.pl: $fixed[$fixlinenr] = "\+#if IS_ENABLED($config)";
> tools/testing/scatterlist/linux/mm.h:#define IS_ENABLED(x) (0)
>
>
That's true.
The following looks okay to me:
IS_ENABLED(DEBUG)
IS_ENABLED(cfg)
IS_ENABLED(opt_name)
IS_ENABLED(option)
IS_ENABLED(DEBUG_PRINT_TRIE_GRAPHVIZ)
IS_ENABLED(config)
IS_ENABLED(cond)
IS_ENABLED(__BIG_ENDIAN)
IS_ENABLED(x)
IS_ENABLED(DEBUG_CHACHA20POLY1305_SLOW_CHUNK_TEST)
Adding a CONFIG_ in these would be wrong I think.
I will drop this patch.
Thank you,
Dwaipayan.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-10 16:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-10 14:19 [PATCH] checkpatch: add --fix option to IS_ENABLED_CONFIG check Dwaipayan Ray
2020-12-10 14:36 ` Joe Perches
2020-12-10 14:54 ` Dwaipayan Ray
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).