* [PATCH] x86/mm: Fix void/int conditional in pgd_clear()
@ 2026-09-23 21:27 Jose A. Perez de Azpillaga
2026-09-24 19:24 ` [tip: x86/mm] " tip-bot2 for Jose A. Perez de Azpillaga
0 siblings, 1 reply; 2+ messages in thread
From: Jose A. Perez de Azpillaga @ 2026-09-23 21:27 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
Andrew Morton, David Hildenbrand (Arm),
Rohan McLure, Pasha Tatashin, Baolin Wang, Kiryl Shutsemau (Meta),
Tejun Heo, Jose A. Perez de Azpillaga, Mike Rapoport (Microsoft)
Cc: H. Peter Anvin, Ingo Molnar, linux-kernel
sparse building mm/ reports an error for every pgd_clear() caller:
mm/pgtable-generic.c:30:9: error: incompatible types in conditional expression (different base types):
mm/pgtable-generic.c:30:9: void
mm/pgtable-generic.c:30:9: int
pgtable_l5_enabled() ? native_pgd_clear(pgd) : 0 mixes a void function
call with an int constant. C11 6.5.15 requires the second and third
operands of a conditional expression to both have arithmetic type, both
have the same structure or union type, both have void type, or to be
compatible pointer types. void and int are none of those, so this is a
type error, not just a style issue. GCC accepts it as an extension, and
the result type is void, so there is no runtime effect today.
The macro only exists when the p4d level is not folded, that is, when
CONFIG_PGTABLE_LEVELS > 4; with a folded p4d, asm-generic/pgtable-nop4d.h
defines pgd_clear() as a no-op.
All callers use pgd_clear() as a statement (mm/memory.c and friends), so
use the do { } while (0) form, matching the paravirt definition in
asm/paravirt.h.
Found by running sparse 0.6.5-rc1 over mm/. No functional change.
Signed-off-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
---
arch/x86/include/asm/pgtable.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index d551120a7c88..c79554dac5f7 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -66,7 +66,11 @@ extern pmdval_t early_pmd_flags;
#ifndef __PAGETABLE_P4D_FOLDED
#define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
-#define pgd_clear(pgd) (pgtable_l5_enabled() ? native_pgd_clear(pgd) : 0)
+#define pgd_clear(pgdp) \
+do { \
+ if (pgtable_l5_enabled()) \
+ native_pgd_clear(pgdp); \
+} while (0)
#endif
#ifndef set_p4d
--
2.55.0
^ permalink raw reply [flat|nested] 2+ messages in thread* [tip: x86/mm] x86/mm: Fix void/int conditional in pgd_clear()
2026-09-23 21:27 [PATCH] x86/mm: Fix void/int conditional in pgd_clear() Jose A. Perez de Azpillaga
@ 2026-09-24 19:24 ` tip-bot2 for Jose A. Perez de Azpillaga
0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Jose A. Perez de Azpillaga @ 2026-09-24 19:24 UTC (permalink / raw)
To: linux-tip-commits
Cc: Jose A. Perez de Azpillaga, Dave Hansen, x86, linux-kernel
The following commit has been merged into the x86/mm branch of tip:
Commit-ID: 4f8c177caac8ecdedeb95caa673214fc3f6a75cb
Gitweb: https://git.kernel.org/tip/4f8c177caac8ecdedeb95caa673214fc3f6a75cb
Author: Jose A. Perez de Azpillaga <azpijr@gmail.com>
AuthorDate: Wed, 23 Sep 2026 23:27:25 +02:00
Committer: Dave Hansen <dave.hansen@linux.intel.com>
CommitterDate: Thu, 24 Sep 2026 12:19:01 -07:00
x86/mm: Fix void/int conditional in pgd_clear()
sparse building mm/ reports an error for every pgd_clear() caller:
mm/pgtable-generic.c:30:9: error: incompatible types in conditional expression (different base types):
mm/pgtable-generic.c:30:9: void
mm/pgtable-generic.c:30:9: int
pgtable_l5_enabled() ? native_pgd_clear(pgd) : 0 mixes a void function
call with an int constant. C11 6.5.15 requires the second and third
operands of a conditional expression to both have arithmetic type, both
have the same structure or union type, both have void type, or to be
compatible pointer types. void and int are none of those, so this is a
type error, not just a style issue. GCC accepts it as an extension, and
the result type is void, so there is no runtime effect today.
The macro only exists when the p4d level is not folded, that is, when
CONFIG_PGTABLE_LEVELS > 4; with a folded p4d, asm-generic/pgtable-nop4d.h
defines pgd_clear() as a no-op.
All callers use pgd_clear() as a statement (mm/memory.c and friends), so
use the do { } while (0) form, matching the paravirt definition in
asm/paravirt.h.
Found by running sparse 0.6.5-rc1 over mm/. No functional change.
Signed-off-by: Jose A. Perez de Azpillaga <azpijr@gmail.com>
Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
Link: https://patch.msgid.link/20260923212731.19599-1-azpijr@gmail.com
---
arch/x86/include/asm/pgtable.h | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index d5f4917..153cb62 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -66,7 +66,11 @@ extern pmdval_t early_pmd_flags;
#ifndef __PAGETABLE_P4D_FOLDED
#define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
-#define pgd_clear(pgd) (pgtable_l5_enabled() ? native_pgd_clear(pgd) : 0)
+#define pgd_clear(pgdp) \
+do { \
+ if (pgtable_l5_enabled()) \
+ native_pgd_clear(pgdp); \
+} while (0)
#endif
#ifndef set_p4d
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-24 19:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-23 21:27 [PATCH] x86/mm: Fix void/int conditional in pgd_clear() Jose A. Perez de Azpillaga
2026-09-24 19:24 ` [tip: x86/mm] " tip-bot2 for Jose A. Perez de Azpillaga
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®