checkpatch: add --fix option to IS_ENABLED_CONFIG check
PATCH 1/1 checkpatch: add --fix option to IS_ENABLED_CONFIG check
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)
--- scripts/checkpatch.pl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +5 -2
@@ -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
Signature · 6 lines
2.27.0 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Joe Perches
maintainerQuoted 14 lines · Dwaipayan Ray
Documentation/process/coding-style.rstspecifies the use ofIS_ENABLEDmacro:Within code, where possible, use the
IS_ENABLEDmacro to convert aKconfigsymbol 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.
Quoted 5 lines
Macros like:
#ifIS_ENABLED(THERMAL)is corrected to:
#ifIS_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)_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Quoted 44 lines
Quoted 9 lines
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:
#ifIS_ENABLED(THERMAL)is corrected to:
#ifIS_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) &&
Quoted 10 lines
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.
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees