scripts/kernel-doc: Avoid new Perl precedence warning
PATCH 1/1 scripts/kernel-doc: Avoid new Perl precedence warning
Newer versions of Perl (5.41.x and up) emit a warning for code in
kernel-doc:
Possible precedence problem between ! and pattern match (m//) at /scripts/kernel-doc line 1597.
This is because the code does:
if (!$param =~ /\w\.\.\.$/) {In Perl, the ! operator has higher precedence than the =~ pattern-match binding, so the effect of this condition is to first logically-negate the string $param into a true-or-false value and then try to pattern match it against the regex, which in this case will always fail. This is almost certainly not what the author intended.
In the new Python version of kernel-doc in the Linux kernel, the equivalent code is written:
if KernRe(r'\w\.\.\.$').search(param):
# For named variable parameters of the form x..., # remove the dots
param = param[:-3]
else:
# Handles unnamed variable parameters param = "..."
which is a more sensible way of writing the behaviour you would get if you put in brackets to make the regex match first and then negate the result.
Take this as the intended behaviour, and update the Perl to match.
For QEMU, this produces no change in output, presumably because we never used the "unnamed variable parameters" syntax.
---
This obviously will clash with the "import the python script" patchseries, but I figured it was worth providing the minimal fix for the benefit of stable backports.
The kernel's copy of kernel-doc.pl still has this bug.
--- scripts/kernel-doc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
scripts/kernel-doc +4 -5
@@ -1594,13 +1594,12 @@ sub push_parameter($$$$$) { if ($type eq "" && $param =~ /\.\.\.$/) { - if (!$param =~ /\w\.\.\.$/) { - # handles unnamed variable parameters - $param = "..."; - } - elsif ($param =~ /\w\.\.\.$/) { + if ($param =~ /\w\.\.\.$/) { # for named variable parameters of the form `x...`, remove the dots $param =~ s/\.\.\.$//; + } else { + # handles unnamed variable parameters + $param = "..."; } if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { $parameterdescs{$param} = "variable arguments";
Signature · 1 line
2.43.0
Quoted 51 lines · Peter Maydell
Newer versions of Perl (5.41.x and up) emit a warning for code in
kernel-doc:
Possible precedence problem between ! and pattern match (m//) at /scripts/kernel-doc line 1597.This is because the code does:
if (!$param =~ /\w\.\.\.$/) {In Perl, the ! operator has higher precedence than the =~ pattern-match binding, so the effect of this condition is to first logically-negate the string $param into a true-or-false value and then try to pattern match it against the regex, which in this case will always fail. This is almost certainly not what the author intended.
In the new Python version of kernel-doc in the Linux kernel, the equivalent code is written:
if KernRe(r'\w\.\.\.$').search(param):
# For named variable parameters of the formx..., # remove the dots
param = param[:-3]
else:
# Handles unnamed variable parameters param = "..."which is a more sensible way of writing the behaviour you would get if you put in brackets to make the regex match first and then negate the result.
Take this as the intended behaviour, and update the Perl to match.
For QEMU, this produces no change in output, presumably because we never used the "unnamed variable parameters" syntax.
Signed-off-by Peter Maydell <[email protected]>---
This obviously will clash with the "import the python script" patchseries, but I figured it was worth providing the minimal fix for the benefit of stable backports.The kernel's copy of kernel-doc.pl still has this bug.
--- scripts/kernel-doc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)scripts/kernel-doc +0
-0
scripts/kernel-doc sub push_parameter($$$$$) { · line 1597
Quoted 4 lines
scripts/kernel-doc +0
-1@@ -1594,13 +1594,12 @@ sub push_parameter($$$$$) { if ($type eq "" && $param =~ /\.\.\.$/) { - if (!$param =~ /\w\.\.\.$/) {
I think it would be possible to change this only line to collapse the ! and =~ into the !~ operator:
if ($param !~ /\w\.\.\.$/) {Quoted 17 lines
scripts/kernel-doc +4
-4- # handles unnamed variable parameters - $param = "..."; - } - elsif ($param =~ /\w\.\.\.$/) { + if ($param =~ /\w\.\.\.$/) { # for named variable parameters of the form `x...`, remove the dots $param =~ s/\.\.\.$//; + } else { + # handles unnamed variable parameters + $param = "..."; } if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { $parameterdescs{$param} = "variable arguments";Signature · 1 line
2.43.0
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 54 lines · Daniel P. Berrangé
Quoted 52 lines · Peter Maydell
Newer versions of Perl (5.41.x and up) emit a warning for code in
kernel-doc:
Possible precedence problem between ! and pattern match (m//) at /scripts/kernel-doc line 1597.This is because the code does:
if (!$param =~ /\w\.\.\.$/) {In Perl, the ! operator has higher precedence than the =~ pattern-match binding, so the effect of this condition is to first logically-negate the string $param into a true-or-false value and then try to pattern match it against the regex, which in this case will always fail. This is almost certainly not what the author intended.
In the new Python version of kernel-doc in the Linux kernel, the equivalent code is written:
if KernRe(r'\w\.\.\.$').search(param):
# For named variable parameters of the formx..., # remove the dots
param = param[:-3]
else:
# Handles unnamed variable parameters param = "..."which is a more sensible way of writing the behaviour you would get if you put in brackets to make the regex match first and then negate the result.
Take this as the intended behaviour, and update the Perl to match.
For QEMU, this produces no change in output, presumably because we never used the "unnamed variable parameters" syntax.
Signed-off-by Peter Maydell <[email protected]>---
This obviously will clash with the "import the python script" patchseries, but I figured it was worth providing the minimal fix for the benefit of stable backports.The kernel's copy of kernel-doc.pl still has this bug.
--- scripts/kernel-doc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)scripts/kernel-doc +0
-0@@ -1594,13 +1594,12 @@ sub push_parameter($$$$$) {
Quoted 8 lines
scripts/kernel-doc sub push_parameter($$$$$) { · line 1597
Quoted 3 lines
scripts/kernel-doc +0
-1if ($type eq "" && $param =~ /\.\.\.$/) { - if (!$param =~ /\w\.\.\.$/) {I think it would be possible to change this only line to collapse the ! and =~ into the !~ operator:
if ($param !~ /\w\.\.\.$/) {
Yes, it would, but then the code would be:
if ($param !~ /\w\.\.\.$/) {
stuff... } elsif (param =~ /\w\.\.\.$/){
other stuff...
}
where we check the condition twice rather than using "else". So I favoured:
* "if C then {A} else {B}" is faster and more obvious as a way to say "do A or B depending on C" than "if !C {B} elsif C {A}".
* match the logic that the Python script uses
over "smallest possible change to resolve the warning".
thanks
-- PMM
Daniel P. Berrangé
Reviewed-byQuoted 72 lines · Peter Maydell
Quoted 54 lines · Daniel P. Berrangé
Quoted 52 lines · Peter Maydell
Newer versions of Perl (5.41.x and up) emit a warning for code in
kernel-doc:
Possible precedence problem between ! and pattern match (m//) at /scripts/kernel-doc line 1597.This is because the code does:
if (!$param =~ /\w\.\.\.$/) {In Perl, the ! operator has higher precedence than the =~ pattern-match binding, so the effect of this condition is to first logically-negate the string $param into a true-or-false value and then try to pattern match it against the regex, which in this case will always fail. This is almost certainly not what the author intended.
In the new Python version of kernel-doc in the Linux kernel, the equivalent code is written:
if KernRe(r'\w\.\.\.$').search(param):
# For named variable parameters of the formx..., # remove the dots
param = param[:-3]
else:
# Handles unnamed variable parameters param = "..."which is a more sensible way of writing the behaviour you would get if you put in brackets to make the regex match first and then negate the result.
Take this as the intended behaviour, and update the Perl to match.
For QEMU, this produces no change in output, presumably because we never used the "unnamed variable parameters" syntax.
Signed-off-by Peter Maydell <[email protected]>---
This obviously will clash with the "import the python script" patchseries, but I figured it was worth providing the minimal fix for the benefit of stable backports.The kernel's copy of kernel-doc.pl still has this bug.
--- scripts/kernel-doc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)scripts/kernel-doc +0
-0@@ -1594,13 +1594,12 @@ sub push_parameter($$$$$) {Quoted 8 lines
scripts/kernel-doc sub push_parameter($$$$$) { · line 1597
Quoted 3 lines
scripts/kernel-doc +0
-1if ($type eq "" && $param =~ /\.\.\.$/) { - if (!$param =~ /\w\.\.\.$/) {I think it would be possible to change this only line to collapse the ! and =~ into the !~ operator:
if ($param !~ /\w\.\.\.$/) {Yes, it would, but then the code would be:
if ($param !~ /\w\.\.\.$/) { stuff...} elsif (param =~ /\w\.\.\.$/){
other stuff...
}
Quoted 7 lines
where we check the condition twice rather than using "else". So I favoured:
* "if C then {A} else {B}" is faster and more obvious as a way to say "do A or B depending on C" than "if !C {B} elsif C {A}".
* match the logic that the Python script usesover "smallest possible change to resolve the warning".
Ok, I'm not that fussed so to your patch
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Mauro Carvalho Chehab
Reviewed-byQuoted 64 lines · Peter Maydell
Quoted 54 lines · Daniel P. Berrangé
Quoted 52 lines · Peter Maydell
Newer versions of Perl (5.41.x and up) emit a warning for code in
kernel-doc:
Possible precedence problem between ! and pattern match (m//) at /scripts/kernel-doc line 1597.This is because the code does:
if (!$param =~ /\w\.\.\.$/) {In Perl, the ! operator has higher precedence than the =~ pattern-match binding, so the effect of this condition is to first logically-negate the string $param into a true-or-false value and then try to pattern match it against the regex, which in this case will always fail. This is almost certainly not what the author intended.
In the new Python version of kernel-doc in the Linux kernel, the equivalent code is written:
if KernRe(r'\w\.\.\.$').search(param):
# For named variable parameters of the formx..., # remove the dots
param = param[:-3]
else:
# Handles unnamed variable parameters param = "..."which is a more sensible way of writing the behaviour you would get if you put in brackets to make the regex match first and then negate the result.
Take this as the intended behaviour, and update the Perl to match.
For QEMU, this produces no change in output, presumably because we never used the "unnamed variable parameters" syntax.
Signed-off-by Peter Maydell <[email protected]>---
This obviously will clash with the "import the python script" patchseries, but I figured it was worth providing the minimal fix for the benefit of stable backports.The kernel's copy of kernel-doc.pl still has this bug.
--- scripts/kernel-doc | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)scripts/kernel-doc +0
-0@@ -1594,13 +1594,12 @@ sub push_parameter($$$$$) {Quoted 8 lines
scripts/kernel-doc sub push_parameter($$$$$) { · line 1597
Quoted 3 lines
scripts/kernel-doc +0
-1if ($type eq "" && $param =~ /\.\.\.$/) { - if (!$param =~ /\w\.\.\.$/) {I think it would be possible to change this only line to collapse the ! and =~ into the !~ operator:
if ($param !~ /\w\.\.\.$/) {
Quoted 7 lines
Yes, it would, but then the code would be:
if ($param !~ /\w\.\.\.$/) { stuff...} elsif (param =~ /\w\.\.\.$/){
other stuff...
}
Yes, the intention there is to negate the regular expression match, e.g. either ~(expr) or $param !~ regex would equally work.
Quoted 7 lines
where we check the condition twice rather than using "else". So I favoured:
* "if C then {A} else {B}" is faster and more obvious as a way to say "do A or B depending on C" than "if !C {B} elsif C {A}".
* match the logic that the Python script usesover "smallest possible change to resolve the warning".
True, but, on the other hand, this will get replaced at the next merge window, so, it won't do much difference betwenn picking the smalllest change or the if/then/else variant.
The Python version uses if/then/else:
if dtype == "" and param.endswith("..."):
if KernRe(r'\w\.\.\.$').search(param):
# For named variable parameters of the form `x...`,
# remove the dots
param = param[:-3]
else:
# Handles unnamed variable parameters
param = "..."So, either way:
Quoted 3 lines
thanks
-- PMM
Signature · 2 lines
Thanks, Mauro