Fix build error when CONFIG_NVME_AUTH=m (module): drivers/nvme/common/auth.c:158:13: error: redefinition of 'nvme_auth_extract_key' include/linux/nvme-auth.h:25:27: note: previous definition is here The issue occurs because when NVME_AUTH is built as a module (=m), the preprocessor symbol CONFIG_NVME_AUTH is not defined during compilation, but the object file auth.o is still compiled as part of nvme-auth.ko. With #ifdef CONFIG_NVME_AUTH, the header provides a static inline stub when the config is =m, while auth.c provides the real implementation, causing a redefinition conflict. Use IS_REACHABLE(CONFIG_NVME_AUTH) instead of #ifdef CONFIG_NVME_AUTH to properly handle both built-in (=y) and modular (=m) builds. IS_REACHABLE evaluates to true when the code is reachable, either because it's built-in or because we're building the same module. Fixes: e30cd923b3ed ("nvme-auth: switch to use 'struct key'") Signed-off-by: Chaitanya Kulkarni --- Hi, Please review this very carefully :- Broken scenario with #ifdef CONFIG_NVME_AUTH: make menuconfig --> NVMe over Fabrics In-Band Authentication --> * nvme (nvme-6.19) # grep NVME_AUTH .config CONFIG_NVME_AUTH_STATE=y CONFIG_NVME_AUTH=m nvme (nvme-6.19) # 1: Makefile compiles auth.c obj-$(CONFIG_NVME_AUTH) += nvme-auth.o nvme-auth-y += auth.o auth.c gets compiled as part of nvme-auth.ko module make[1]: Entering directory '/mnt/data/nvme/drivers/nvme' CC [M] common/auth.o CC [M] host/core.o CC [M] host/sysfs.o CC [M] target/configfs.o CC [M] host/auth.o CC [M] host/fabrics.o CC [M] target/fabrics-cmd-auth.o CC [M] target/auth.o common/auth.c:158:13: error: redefinition of ‘nvme_auth_extract_key’ 158 | struct key *nvme_auth_extract_key(struct key *keyring, const u8 *secret, | ^~~~~~~~~~~~~~~~~~~~~ 2: Preprocessor evaluates header guards in nvme-auth.h #ifdef CONFIG_NVME_AUTH <---- CONFIG_NVME_AUTH is NOT defined when =m Only CONFIG_NVME_AUTH_MODULE is defined! struct key *nvme_auth_extract_key(...); <--- Declaration (NOT reached) #else static inline struct key *nvme_auth_extract_key(...) { <---- This is used Static inline stub return ERR_PTR(-ENOKEY); } #endif 3: Compiler sees BOTH definitions when NVME_AUTH is enabled using make menuconfig NVMe over Fabrics In-Band Authentication = * - auth.c:158 has the real implementation: struct key *nvme_auth_extract_key(...) - Header provides static inline stub: static inline struct key *nvme_auth_extract_key(...) --- include/linux/nvme-auth.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/nvme-auth.h b/include/linux/nvme-auth.h index afc84a4cd94a..49a8afc16028 100644 --- a/include/linux/nvme-auth.h +++ b/include/linux/nvme-auth.h @@ -18,7 +18,7 @@ const char *nvme_auth_digest_name(u8 hmac_id); size_t nvme_auth_hmac_hash_len(u8 hmac_id); u8 nvme_auth_hmac_id(const char *hmac_name); -#ifdef CONFIG_NVME_AUTH +#if IS_REACHABLE(CONFIG_NVME_AUTH) struct key *nvme_auth_extract_key(struct key *keyring, const u8 *secret, size_t secret_len, bool *generated); #else -- 2.40.0