From: "Jose A. Perez de Azpillaga" <azpijr@gmail.com>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, Andrew Morton <akpm@linux-foundation.org>,
"David Hildenbrand (Arm)" <david@kernel.org>,
Rohan McLure <rmclure@linux.ibm.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
"Kiryl Shutsemau (Meta)" <kas@kernel.org>,
Tejun Heo <tj@kernel.org>,
"Jose A. Perez de Azpillaga" <azpijr@gmail.com>,
"Mike Rapoport (Microsoft)" <rppt@kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH] x86/mm: Fix void/int conditional in pgd_clear()
Date: Wed, 23 Sep 2026 23:27:25 +0200 [thread overview]
Message-ID: <20260923212731.19599-1-azpijr@gmail.com> (raw)
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
next reply other threads:[~2026-09-23 21:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 21:27 Jose A. Perez de Azpillaga [this message]
2026-09-24 19:24 ` [tip: x86/mm] " tip-bot2 for Jose A. Perez de Azpillaga
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260923212731.19599-1-azpijr@gmail.com \
--to=azpijr@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=hpa@zytor.com \
--cc=kas@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=pasha.tatashin@soleen.com \
--cc=rmclure@linux.ibm.com \
--cc=rppt@kernel.org \
--cc=tglx@kernel.org \
--cc=tj@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®