checkpatch: improve exit criterias
Subsystems (2)
cover checkpatch: improve exit criterias
When invoking checkpatch with the --mailback argument over a range of patches the tool unexpectedly exits successfully on the first clean patch. For example:
./scripts/checkpatch.pl --mailback --git v7.3-rc1..
Checks the single commit and then exits successfully. In contrast, omitting --mailback causes checkpatch to check the thousands of commits in the range.
The same behavior can be observed with --no-patch or when empty patches are involved, which exits successfully after the first non-patch has passed the checks, either skipping further checks or failing to return a non-zero exit value even though errors has been reported.
Lastly, checkpatch fails with a non-zero status when invoked on a missing patch file, but zero when invoked on a missing file.
---
Bjorn Andersson (4):
checkpatch: don't stop at the first clean patch with --mailback
checkpatch: don't stop at the first non-patch input with --no-patch
checkpatch: don't stop at the first empty input
checkpatch: fail on missing or unreadable files with --file
scripts/checkpatch.pl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
---
base-commit: ddfe51b0a0f5dc9e415cc2c8ad8db17532dd426b
change-id: 20261108-checkpatch-fixes-hash-0466f2c1d2e4
Best regards,
Signature · 1 line
Bjorn Andersson <[email protected]>
PATCH 1/4 checkpatch: don't stop at the first clean patch with --mailback
When checkpatch is given multiple patches, either as several files or as a --git range, --mailback causes process() to call exit(0) as soon as it encounters a clean patch. The remaining patches are never checked, and the run is reported as successful even if later patches contain errors or warnings.
E.g. with a clean patch followed by a patch with a bogus Fixes: tag:
$ ./scripts/checkpatch.pl -q --terse --mailback clean.patch bad.patch $ echo $? 0
Return from process() instead, so the clean patch is still silently accepted while the remaining patches are checked.
--- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
@@ -7880,7 +7880,7 @@ sub process { # In mailback mode only produce a report in the negative, for # things that appear to be patches. if ($mailback && ($clean == 1 || !$is_patch)) { - exit(0); + return 1; } # This is not a patch, and we are in 'no-patch' mode so
Signature · 1 line
2.55.0
PATCH 2/4 checkpatch: don't stop at the first non-patch input with --no-patch
In reply to Bjorn AnderssonWhen checkpatch is given multiple inputs with --no-patch, process() calls exit(0) as soon as it encounters an input that isn't a patch. The remaining inputs are never checked, and the run is reported as successful even if later inputs contain errors or warnings.
E.g. with a non-patch file followed by a patch with a bogus Fixes: tag:
$ ./scripts/checkpatch.pl -q --terse --no-patch notes.txt bad.patch $ echo $? 0
Return from process() instead, so the non-patch input is still silently skipped while the remaining inputs are checked.
--- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
@@ -7886,7 +7886,7 @@ sub process { # This is not a patch, and we are in 'no-patch' mode so # just keep quiet. if (!$chk_patch && !$is_patch) { - exit(0); + return 1; } if (!$is_patch && $filename !~ /cover-letter\.patch$/) {
Signature · 1 line
2.55.0
PATCH 3/4 checkpatch: don't stop at the first empty input
In reply to Bjorn AnderssonWhen checkpatch is given multiple inputs, process() calls exit(0) as soon as it encounters an empty one. This discards the failure status of inputs already checked, and the remaining inputs are never checked.
E.g. a patch with a bogus Fixes: tag followed by an empty file reports the warning, but the run is still reported as successful:
$ ./scripts/checkpatch.pl -q --terse bad.patch empty.patch bad.patch:9: WARNING: Unknown commit id '6393a36fe184', ... total: 0 errors, 1 warnings, 7 lines checked $ echo $? 0
With the order reversed, bad.patch is never checked at all.
The same happens with --file when one of the files doesn't exist, as the diff against /dev/null then produces no output. A mistyped file name therefore causes all following files to be silently skipped:
$ ./scripts/checkpatch.pl -q --terse -f missing.c existing.c diff: missing.c: No such file or directory $ echo $? 0
Return from process() instead, so the empty input is still silently skipped while the remaining inputs are checked and the exit status reflects all of them.
--- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/checkpatch.pl +1 -1
@@ -7874,7 +7874,7 @@ sub process { # If we have no input at all, then there is nothing to report on # so just keep quiet. if ($#rawlines == -1) { - exit(0); + return 1; } # In mailback mode only produce a report in the negative, for
Signature · 1 line
2.55.0
PATCH 4/4 checkpatch: fail on missing or unreadable files with --file
In reply to Bjorn AnderssonWith --file, checkpatch reads each input through "diff -u /dev/null" and doesn't check whether diff managed to read the file. A file that doesn't exist or can't be read therefore produces no output and is silently treated as an empty, and thereby clean, input. Only diff's own error message hints at the problem, and the exit status reports success:
$ ./scripts/checkpatch.pl -q --terse -f missing.c diff: missing.c: No such file or directory $ echo $? 0
This differs from patch mode, where an input that can't be opened is treated as a fatal error.
Open the file before running diff, and fail in the same way as patch mode does when that isn't possible:
$ ./scripts/checkpatch.pl -q --terse -f missing.c ./scripts/checkpatch.pl: missing.c: open failed - No such file or directory
--- scripts/checkpatch.pl | 6 ++++++ 1 file changed, 6 insertions(+)
scripts/checkpatch.pl +6 -0
@@ -1346,6 +1346,12 @@ for my $filename (@ARGV) { open($FILE, '-|', "git format-patch -M --stdout -1 $filename") || die "$P: $filename: git format-patch failed - $!\n"; } elsif ($file) { + # diff failing to read the file would look like an empty file + if ($filename ne '-') { + open(my $fh, '<', $filename) || + die "$P: $filename: open failed - $!\n"; + close($fh); + } open($FILE, '-|', "diff -u /dev/null $filename") || die "$P: $filename: diff failed - $!\n"; } elsif ($filename eq '-') {
Signature · 1 line
2.55.0
Joe Perches
maintainerQuoted 5 lines · Bjorn Andersson
When invoking checkpatch with the --mailback argument over a range of patches the tool unexpectedly exits successfully on the first clean patch. For example:
./scripts/checkpatch.pl--mailback --git v7.3-rc1..
Why is it useful to do this?
Quoted 9 lines · Joe Perches
Quoted 5 lines · Bjorn Andersson
When invoking checkpatch with the --mailback argument over a range of patches the tool unexpectedly exits successfully on the first clean patch. For example:
./scripts/checkpatch.pl--mailback --git v7.3-rc1..Why is it useful to do this?
My use case is that I create a maintainer branch off e.g. v7.3-rc1 (now v7.4-rc1), then apply a bunch of patches and before pushing that out I run "checkpatch.pl --strict v7.3-rc1..".
But this is quite noisy, and the compressed "b4 prep --check" output is more what I'm looking for. So, I borrowed the "checkpatch.pl -q --terse --no-summary --mailback --showfile" from there and it took me a while to realize the difference between:
--mailback only produce a report in case of warnings/errors
and "don't produce a report if the first commit is good".
So, might not be useful in itself, but the behavior tricked me and I pushed patches into linux-next with checkpatch errors.
Regards,
Bjorn
Joe Perches
maintainerQuoted 7 lines · Bjorn Andersson
Quoted 6 lines · Joe Perches
Quoted 4 lines · Bjorn Andersson
When invoking checkpatch with the --mailback argument over a range of patches the tool unexpectedly exits successfully on the first clean patch. For example:
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
./scripts/checkpatch.pl--mailback --git v7.3-rc1..Why is it useful to do this?
My use case is that I create a maintainer branch off e.g. v7.3-rc1 (now v7.4-rc1), then apply a bunch of patches and before pushing that out I run "checkpatch.pl --strict v7.3-rc1..".
I think the description for mailback should be changed to be used only for a single commit as this proposal would otherwise change the exit condition for the single use case no?
Quoted 2 lines
But this is quite noisy, and the compressed "b4 prep --check" output is more what I'm looking for.
My b4 version is 0.14.3 and the man b4 for prep doesn't include a --check option or description so I don't know what that output looks like.
Quoted 7 lines
So, I borrowed the "checkpatch.pl -q
--terse --no-summary --mailback --showfile" from there and it took me a while to realize the difference between:--mailback only produce a report in case of warnings/errors
and "don't produce a report if the first commit is good".
So perhaps just don't use --mailback?
And remove the --showfile so checkpatch adds the git commit id to the output and maybe add a front end little script to do the git commit id to commit subject to make it easier to detect what commit might need updating?
Quoted 12 lines · Joe Perches
Quoted 11 lines · Bjorn Andersson
Quoted 9 lines · Joe Perches
Quoted 5 lines · Bjorn Andersson
When invoking checkpatch with the --mailback argument over a range of patches the tool unexpectedly exits successfully on the first clean patch. For example:
./scripts/checkpatch.pl--mailback --git v7.3-rc1..Why is it useful to do this?
Quoted 8 lines
Quoted 3 lines
My use case is that I create a maintainer branch off e.g. v7.3-rc1 (now v7.4-rc1), then apply a bunch of patches and before pushing that out I run "checkpatch.pl --strict v7.3-rc1..".
I think the description for mailback should be changed to be used only for a single commit as this proposal would otherwise change the exit condition for the single use case no?
I don't see a problem with the description, but making --mailback reject cases where multiple inputs are provided sounds like an alternative solution to save others from being surprised by this.
That said, it's not clear to me why:
./scripts/checkpatch.pl --strict --git <hash-with-warnings>
exits with status 1, and:
./scripts/checkpatch.pl --strict --mailback --git <hash-with-warnings>
should exit with status 0.
Or why:
./scripts/checkpatch.pl --strict --terse -f missing Makefile
exits with status 0 and omits all the warnings from "Makefile".
The intent with my series was indeed to fix "the single use case"... all four of them.
Quoted 7 lines
Quoted 2 lines
But this is quite noisy, and the compressed "b4 prep --check" output is more what I'm looking for.
My b4 version is 0.14.3 and the man b4 for prep doesn't include a --check option or description so I don't know what that output looks like.
It effectively looks git "git log --oneline" mixed with the output of "checkpatch.pl --terse --no-summary".
Quoted 10 lines
Quoted 7 lines
So, I borrowed the "checkpatch.pl -q
--terse --no-summary --mailback --showfile" from there and it took me a while to realize the difference between:--mailback only produce a report in case of warnings/errors
and "don't produce a report if the first commit is good".
So perhaps just don't use --mailback?
Of course, I know that now.
Quoted 4 lines
And remove the --showfile so checkpatch adds the git commit id to the output and maybe add a front end little script to do the git commit id to commit subject to make it easier to detect what commit might need updating?
I'm now using "checkpatch.pl --strict --terse --no-summary --git <range>" and that gives me the compact output I was looking for.
Regards,
Bjorn