2020-07-14 09:42:43

by Thierry Reding

[permalink] [raw]
Subject: [PATCH] checkpatch.pl: Allow '+' in compatible strings

From: Thierry Reding <[email protected]>

The current checks will interpret a '+' character as special because
they use regular expression matching. Escape the '+' character if it
appears in a compatible string.

Signed-off-by: Thierry Reding <[email protected]>
---
scripts/checkpatch.pl | 1 +
1 file changed, 1 insertion(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4c820607540b..8104d0736e7f 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3145,6 +3145,7 @@ sub process {
my $vp_file = $dt_path . "vendor-prefixes.yaml";

foreach my $compat (@compats) {
+ $compat =~ s/\+/\\+/;
my $compat2 = $compat;
$compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
my $compat3 = $compat;
--
2.27.0


2020-07-14 11:15:48

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] checkpatch.pl: Allow '+' in compatible strings

On Tue, 2020-07-14 at 11:41 +0200, Thierry Reding wrote:
> From: Thierry Reding <[email protected]>
>
> The current checks will interpret a '+' character as special because
> they use regular expression matching. Escape the '+' character if it
> appears in a compatible string.
>
> Signed-off-by: Thierry Reding <[email protected]>

Thanks

> ---
> scripts/checkpatch.pl | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 4c820607540b..8104d0736e7f 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3145,6 +3145,7 @@ sub process {
> my $vp_file = $dt_path . "vendor-prefixes.yaml";
>
> foreach my $compat (@compats) {
> + $compat =~ s/\+/\\+/;

This changes the @compats array for each line
> my $compat2 = $compat;
> $compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
> my $compat3 = $compat;

2020-07-14 13:13:16

by Thierry Reding

[permalink] [raw]
Subject: Re: [PATCH] checkpatch.pl: Allow '+' in compatible strings

On Tue, Jul 14, 2020 at 04:14:36AM -0700, Joe Perches wrote:
> On Tue, 2020-07-14 at 11:41 +0200, Thierry Reding wrote:
> > From: Thierry Reding <[email protected]>
> >
> > The current checks will interpret a '+' character as special because
> > they use regular expression matching. Escape the '+' character if it
> > appears in a compatible string.
> >
> > Signed-off-by: Thierry Reding <[email protected]>
>
> Thanks
>
> > ---
> > scripts/checkpatch.pl | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index 4c820607540b..8104d0736e7f 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -3145,6 +3145,7 @@ sub process {
> > my $vp_file = $dt_path . "vendor-prefixes.yaml";
> >
> > foreach my $compat (@compats) {
> > + $compat =~ s/\+/\\+/;
>
> This changes the @compats array for each line

I'm not overly familiar with the internals of Perl. I was assuming that
$compat would be a copy of each of the strings in @compats. From what
you're saying it sounds like it's more like a pointer to them instead.

Irrespective, does that do any harm, though? I suppose we could add an
extra local variable like we do for compat2 and compat3 and modify that
instead. That way the contents would perhaps remain unmodified.

Is that what you were suggesting?

Thierry


Attachments:
(No filename) (1.38 kB)
signature.asc (849.00 B)
Download all attachments

2020-07-14 16:24:34

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH] checkpatch.pl: Allow '+' in compatible strings

On Tue, Jul 14, 2020 at 3:41 AM Thierry Reding <[email protected]> wrote:
>
> From: Thierry Reding <[email protected]>
>
> The current checks will interpret a '+' character as special because
> they use regular expression matching. Escape the '+' character if it
> appears in a compatible string.

Ugg, looks like c6x really liked using '+'. Might need to be added in
schema checks, too. Not sure offhand.

Rob

2020-07-14 17:15:12

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] checkpatch.pl: Allow '+' in compatible strings

On Tue, 2020-07-14 at 10:21 -0600, Rob Herring wrote:
> On Tue, Jul 14, 2020 at 3:41 AM Thierry Reding <[email protected]> wrote:
> > From: Thierry Reding <[email protected]>
> >
> > The current checks will interpret a '+' character as special because
> > they use regular expression matching. Escape the '+' character if it
> > appears in a compatible string.
>
> Ugg, looks like c6x really liked using '+'. Might need to be added in
> schema checks, too. Not sure offhand.

These are the non alphanumeric characters used in .dts and .dtsi files
with 'compatible=' strings

- 44115
, 32035
. 1131
_ 259
+ 46
/ 18
) 5
( 5

So it looks like

"("
")"

need to be added and escaped too

?


2020-07-14 17:43:29

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH] checkpatch.pl: Allow '+' in compatible strings

On Tue, Jul 14, 2020 at 11:12 AM Joe Perches <[email protected]> wrote:
>
> On Tue, 2020-07-14 at 10:21 -0600, Rob Herring wrote:
> > On Tue, Jul 14, 2020 at 3:41 AM Thierry Reding <[email protected]> wrote:
> > > From: Thierry Reding <[email protected]>
> > >
> > > The current checks will interpret a '+' character as special because
> > > they use regular expression matching. Escape the '+' character if it
> > > appears in a compatible string.
> >
> > Ugg, looks like c6x really liked using '+'. Might need to be added in
> > schema checks, too. Not sure offhand.
>
> These are the non alphanumeric characters used in .dts and .dtsi files
> with 'compatible=' strings
>
> - 44115
> , 32035
> . 1131
> _ 259
> + 46
> / 18
> ) 5
> ( 5
>
> So it looks like
>
> "("
> ")"
>
> need to be added and escaped too
>
> ?

No, those are 'regulator-compatible' AFAICT which is something else
and deprecated.

Rob

2020-07-15 07:26:12

by Thierry Reding

[permalink] [raw]
Subject: Re: [PATCH] checkpatch.pl: Allow '+' in compatible strings

On Tue, Jul 14, 2020 at 11:42:15AM -0600, Rob Herring wrote:
> On Tue, Jul 14, 2020 at 11:12 AM Joe Perches <[email protected]> wrote:
> >
> > On Tue, 2020-07-14 at 10:21 -0600, Rob Herring wrote:
> > > On Tue, Jul 14, 2020 at 3:41 AM Thierry Reding <[email protected]> wrote:
> > > > From: Thierry Reding <[email protected]>
> > > >
> > > > The current checks will interpret a '+' character as special because
> > > > they use regular expression matching. Escape the '+' character if it
> > > > appears in a compatible string.
> > >
> > > Ugg, looks like c6x really liked using '+'. Might need to be added in
> > > schema checks, too. Not sure offhand.
> >
> > These are the non alphanumeric characters used in .dts and .dtsi files
> > with 'compatible=' strings
> >
> > - 44115
> > , 32035
> > . 1131
> > _ 259
> > + 46
> > / 18
> > ) 5
> > ( 5
> >
> > So it looks like
> >
> > "("
> > ")"
> >
> > need to be added and escaped too
> >
> > ?
>
> No, those are 'regulator-compatible' AFAICT which is something else
> and deprecated.

Looks like we do need to escape the '.' character as well, although it
should be mostly harmless if we don't since '.' in the regex would also
match a literal '.' in the compatible string.

Thierry


Attachments:
(No filename) (1.27 kB)
signature.asc (849.00 B)
Download all attachments