[PATCH v2 07/10] arm64: sysreg: Reject an enum value not written at its field's width
Fuad Tabba
fuad.tabba at linux.dev
Thu Nov 26 23:44:23 PST 2026
The generator emits each enum value as written and doesn't check it
against the width of its field, so a value wider than the field defines
a constant the field can't hold. The duplicate value check compares the
strings as written, so 0b01 and 0b001 in the same field pass as distinct
values, and the rule's pattern, an unanchored /0b[01]+/, accepts 0b12
too.
Require each value to be 0b followed by exactly as many binary digits as
its field has bits. Test it in the rule's action rather than by
tightening the pattern, so that a value such as 0b12 is reported with
its field's width, instead of falling to the generic "unhandled
statement" error.
Reviewed-by: Mark Brown <broonie at kernel.org>
Signed-off-by: Fuad Tabba <fuad.tabba at linux.dev>
---
arch/arm64/tools/gen-sysreg.awk | 3 +++
1 file changed, 3 insertions(+)
diff --git a/arch/arm64/tools/gen-sysreg.awk b/arch/arm64/tools/gen-sysreg.awk
index 1843d283192d2..cde526896ed96 100755
--- a/arch/arm64/tools/gen-sysreg.awk
+++ b/arch/arm64/tools/gen-sysreg.awk
@@ -367,6 +367,9 @@ $1 == "EndEnum" && block_current() == "Enum" {
val = $1
name = $2
+ if (val !~ /^0b[01]+$/ || length(val) - 2 != msb - lsb + 1)
+ fatal("Enum value " val " for " name " is not " (msb - lsb + 1) " binary digits")
+
if (val in seen_enum_vals)
fatal("Duplicate Enum value " val " for " name)
seen_enum_vals[val] = 1
--
2.47.3
More information about the linux-arm-kernel
mailing list