Re: [PATCH v2 2/4] arm64/sysreg: Enforce whole word match for open/close tokens

From: Will Deacon
Date: Fri Mar 14 2025 - 07:32:07 EST


On Fri, Mar 14, 2025 at 07:40:36AM +0000, Marc Zyngier wrote:
> On 2025-03-13 21:56, Will Deacon wrote:
> > On Wed, Jan 15, 2025 at 04:25:56PM +0000, James Clark wrote:
> > > 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@xxxxxxxxxx>
> > > ---
> > > arch/arm64/tools/gen-sysreg.awk | 31 +++++++++++++++++--------------
> > > 1 file changed, 17 insertions(+), 14 deletions(-)
> > >
> > > diff --git a/arch/arm64/tools/gen-sysreg.awk
> > > b/arch/arm64/tools/gen-sysreg.awk
> > > index 1a2afc9fdd42..f2a1732cb1f6 100755
> > > --- a/arch/arm64/tools/gen-sysreg.awk
> > > +++ b/arch/arm64/tools/gen-sysreg.awk
> > > @@ -111,7 +111,7 @@ END {
> > > /^$/ { next }
> > > /^[\t ]*#/ { next }
> > >
> > > -/^SysregFields/ && block_current() == "Root" {
> > > +$1 == "SysregFields" && block_current() == "Root" {
> >
> > Stylistic nit, but could you just do:
> >
> > /^SysregFields$/ && block_current() == "Root" {
> >
> > instead? That way the diff is smaller (well, same number of lines) and
> > you avoid the ugly $1.
>
> The code is trying to match the first field of a line such as:
>
> SysregFields ZCR_ELx
>
> while you seem to try and match a SysregFields all alone on a line.
>
> That being said, my perl-foo is sub-zero, so I may be very wrong myself.


Ah, and this is *awk* so $1 is the first field.

So my suggestion is totally broken and the original patch looks correct:

Acked-by: Will Deacon <will@xxxxxxxxxx>

Will