[PATCH 5/9] arm64: sysreg: Reject a Fields or Mapping line with an undefined target

From: Fuad Tabba

Date: Mon Nov 23 2026 - 02:53:30 EST


A Sysreg block can use another block's layout. "Fields X" names a
SysregFields block and "Mapping X" another Sysreg. The generator emits
the register's RESx and UNKN masks as X_RES0, X_RES1 and X_UNKN, but it
doesn't check that X exists. A misspelt or missing X gives macros that
expand to undefined names, and the build fails only once something uses
them. MPAM1_EL12 had such a line.

Check every Fields and Mapping target once the whole file is read, since
a target may be defined after the register that names it (MPAM1_EL1
follows MPAM1_EL12). Either kind of block defines the masks, so the
check accepts either kind as the target of a Fields or a Mapping line.
Give fatal() an optional line number, so that the error is reported at
the Fields or Mapping line.

Signed-off-by: Fuad Tabba <fuad.tabba@xxxxxxxxx>
---
arch/arm64/tools/gen-sysreg.awk | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/tools/gen-sysreg.awk b/arch/arm64/tools/gen-sysreg.awk
index c4fa27cd9beff..1843d283192d2 100755
--- a/arch/arm64/tools/gen-sysreg.awk
+++ b/arch/arm64/tools/gen-sysreg.awk
@@ -9,8 +9,8 @@ function block_current() {
}

# Log an error and terminate
-function fatal(msg) {
- print "Error at " NR ": " msg > "/dev/stderr"
+function fatal(msg, line) {
+ print "Error at " (line ? line : NR) ": " msg > "/dev/stderr"

printf "Current block nesting:"

@@ -124,6 +124,11 @@ END {
if (__current_block_depth != 0)
fatal("Missing terminator for " block_current() " block")

+ # A Fields or Mapping target may be defined after its user.
+ for (line in refs)
+ if (!(refs[line] in defined_regs))
+ fatal("Undefined Fields or Mapping target " refs[line], line)
+
print "#endif /* __ASM_SYSREG_DEFS_H */"
}

@@ -241,6 +246,8 @@ $1 == "EndSysreg" && block_current() == "Sysreg" {
print "/* For " reg " fields see " $2 " */"
print ""

+ refs[NR] = $2
+
next_bit = -1
res0 = $2 "_RES0"
res1 = $2 "_RES1"
--
2.47.3