Skip to content

Commit 2fdbf2f

Browse files
james-c-linaroctmarinas
authored andcommitted
arm64/sysreg: Enforce whole word match for open/close tokens
Opening and closing tokens can also match on words with common prefixes like "Endsysreg" vs "EndsysregFields". This could potentially make the script go wrong in weird ways so make it fall through to the fatal unhandled statement catcher if it doesn't fully match the current block. Closing ones also get expect_fields(1) to ensure nothing other than whitespace follows. Signed-off-by: James Clark <james.clark@linaro.org> Acked-by: Will Deacon <will@kernel.org> Acked-by: Mark Rutland <mark.rutland@arm.com> Link: https://lore.kernel.org/r/20250115162600.2153226-3-james.clark@linaro.org Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
1 parent 00cb1e0 commit 2fdbf2f

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

arch/arm64/tools/gen-sysreg.awk

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ END {
111111
/^$/ { next }
112112
/^[\t ]*#/ { next }
113113

114-
/^SysregFields/ && block_current() == "Root" {
114+
$1 == "SysregFields" && block_current() == "Root" {
115115
block_push("SysregFields")
116116

117117
expect_fields(2)
@@ -127,7 +127,8 @@ END {
127127
next
128128
}
129129

130-
/^EndSysregFields/ && block_current() == "SysregFields" {
130+
$1 == "EndSysregFields" && block_current() == "SysregFields" {
131+
expect_fields(1)
131132
if (next_bit > 0)
132133
fatal("Unspecified bits in " reg)
133134

@@ -145,7 +146,7 @@ END {
145146
next
146147
}
147148

148-
/^Sysreg/ && block_current() == "Root" {
149+
$1 == "Sysreg" && block_current() == "Root" {
149150
block_push("Sysreg")
150151

151152
expect_fields(7)
@@ -177,7 +178,8 @@ END {
177178
next
178179
}
179180

180-
/^EndSysreg/ && block_current() == "Sysreg" {
181+
$1 == "EndSysreg" && block_current() == "Sysreg" {
182+
expect_fields(1)
181183
if (next_bit > 0)
182184
fatal("Unspecified bits in " reg)
183185

@@ -206,7 +208,7 @@ END {
206208

207209
# Currently this is effectivey a comment, in future we may want to emit
208210
# defines for the fields.
209-
(/^Fields/ || /^Mapping/) && block_current() == "Sysreg" {
211+
($1 == "Fields" || $1 == "Mapping") && block_current() == "Sysreg" {
210212
expect_fields(2)
211213

212214
if (next_bit != 63)
@@ -224,7 +226,7 @@ END {
224226
}
225227

226228

227-
/^Res0/ && (block_current() == "Sysreg" || block_current() == "SysregFields") {
229+
$1 == "Res0" && (block_current() == "Sysreg" || block_current() == "SysregFields") {
228230
expect_fields(2)
229231
parse_bitdef(reg, "RES0", $2)
230232
field = "RES0_" msb "_" lsb
@@ -234,7 +236,7 @@ END {
234236
next
235237
}
236238

237-
/^Res1/ && (block_current() == "Sysreg" || block_current() == "SysregFields") {
239+
$1 == "Res1" && (block_current() == "Sysreg" || block_current() == "SysregFields") {
238240
expect_fields(2)
239241
parse_bitdef(reg, "RES1", $2)
240242
field = "RES1_" msb "_" lsb
@@ -244,7 +246,7 @@ END {
244246
next
245247
}
246248

247-
/^Unkn/ && (block_current() == "Sysreg" || block_current() == "SysregFields") {
249+
$1 == "Unkn" && (block_current() == "Sysreg" || block_current() == "SysregFields") {
248250
expect_fields(2)
249251
parse_bitdef(reg, "UNKN", $2)
250252
field = "UNKN_" msb "_" lsb
@@ -254,7 +256,7 @@ END {
254256
next
255257
}
256258

257-
/^Field/ && (block_current() == "Sysreg" || block_current() == "SysregFields") {
259+
$1 == "Field" && (block_current() == "Sysreg" || block_current() == "SysregFields") {
258260
expect_fields(3)
259261
field = $3
260262
parse_bitdef(reg, field, $2)
@@ -265,14 +267,14 @@ END {
265267
next
266268
}
267269

268-
/^Raz/ && (block_current() == "Sysreg" || block_current() == "SysregFields") {
270+
$1 == "Raz" && (block_current() == "Sysreg" || block_current() == "SysregFields") {
269271
expect_fields(2)
270272
parse_bitdef(reg, field, $2)
271273

272274
next
273275
}
274276

275-
/^SignedEnum/ && (block_current() == "Sysreg" || block_current() == "SysregFields") {
277+
$1 == "SignedEnum" && (block_current() == "Sysreg" || block_current() == "SysregFields") {
276278
block_push("Enum")
277279

278280
expect_fields(3)
@@ -285,7 +287,7 @@ END {
285287
next
286288
}
287289

288-
/^UnsignedEnum/ && (block_current() == "Sysreg" || block_current() == "SysregFields") {
290+
$1 == "UnsignedEnum" && (block_current() == "Sysreg" || block_current() == "SysregFields") {
289291
block_push("Enum")
290292

291293
expect_fields(3)
@@ -298,7 +300,7 @@ END {
298300
next
299301
}
300302

301-
/^Enum/ && (block_current() == "Sysreg" || block_current() == "SysregFields") {
303+
$1 == "Enum" && (block_current() == "Sysreg" || block_current() == "SysregFields") {
302304
block_push("Enum")
303305

304306
expect_fields(3)
@@ -310,7 +312,8 @@ END {
310312
next
311313
}
312314

313-
/^EndEnum/ && block_current() == "Enum" {
315+
$1 == "EndEnum" && block_current() == "Enum" {
316+
expect_fields(1)
314317

315318
field = null
316319
msb = null

0 commit comments

Comments
 (0)