projects/linux·commit 551d4420

default_gfp(): avoid using the "newfangled" __VA_OPT__ trick

551d4420 · Linus Torvalds <[email protected]> · 2026-02-23 09:33:08 -08:00

The default_gfp() helper that I added is not wrong, but it turns out
that it causes unnecessary headaches for 'sparse' which doesn't support
the use of __VA_OPT__ (introduced in C++20 and C23, and supported by gcc
and clang for a long time).

We do already use __VA_OPT__ in some other cases in the kernel (drm/xe
and btrfs), but it has been fairly limited.  Now it triggers for pretty
much everything, and sparse ends up not working at all.

We can use the traditional gcc ',##__VA_ARGS__' syntax instead: it may
not be the "C standard" way and is slightly less natural in this
context, but it is the traditional model for this and avoids the sparse
problem.

Reported-and-tested-by: Ricardo Ribalda <[email protected]>
Reported-and-tested-by: Richard Fitzgerald <[email protected]>
Reported-by: Ben Dooks <[email protected]>
Fixes: e19e1b480ac7 ("add default_gfp() helper macro and use it in the new *alloc_obj() helpers")
Signed-off-by: Linus Torvalds <[email protected]>
Commit
551d44200152cb26f75d2ef990aeb6185b7e37fd
Parents
6de23f81

Changes

1 files changed · +2 −2

FileStatusAddDelContent
include/linux/gfp.hmodified+2−2View file

include/linux/gfp.h

View file
diff --git a/include/linux/gfp.h b/include/linux/gfp.h
index 2b30a05..90536b2 100644
--- a/include/linux/gfp.h
+++ b/include/linux/gfp.h
@@ -14,8 +14,8 @@ struct vm_area_struct;
struct mempolicy;
/* Helper macro to avoid gfp flags if they are the default one */
-#define __default_gfp(a,...) a
-#define default_gfp(...) __default_gfp(__VA_ARGS__ __VA_OPT__(,) GFP_KERNEL)
+#define __default_gfp(a,b,...) b
+#define default_gfp(...) __default_gfp(,##__VA_ARGS__,GFP_KERNEL)
/* Convert GFP flags to their corresponding migrate type */
#define GFP_MOVABLE_MASK (__GFP_RECLAIMABLE|__GFP_MOVABLE)