[Linux-kernel-mentees] [PATCH] checkpatch: add --fix option to IS_ENABLED_CONFIG check

Joe Perches joe at perches.com
Thu Dec 10 14:36:06 UTC 2020


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)





More information about the Linux-kernel-mentees mailing list