checkpatch: do not allow using -f/--file option without a filename
PATCH 1/1 checkpatch: do not allow using -f/--file option without a filename
When checkpatch is run without a filename, it reads from stdin. But if --file option is used along with that, it may generate false positives.
Consider the following test file:
$cat test.c
int x = a - b;
$cat test.c | ./scripts/checkpatch.pl -f
WARNING: It's generally not useful to have the filename in the file +int x = a - b;
This is a false positive and occurs because $realfile is set to "-". Also since checkpatch relies on the file's extension to run specific checks for c files, assembly files, etc, most of the checks are not run as well.
So it is better to disable -f/--file option when checkpatch is run without a filename.
--- scripts/checkpatch.pl | 1 + 1 file changed, 1 insertion(+)
scripts/checkpatch.pl +1 -0
@@ -331,6 +331,7 @@ help(0) if ($help); die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix)); die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse); +die "$P: -f/--file requires at least one filename\n" if ($file && $#ARGV < 0); if ($color =~ /^[01]$/) { $color = !$color;
Signature · 1 line
2.28.0
Joe Perches
maintainerQuoted 12 lines · Dwaipayan Ray
When checkpatch is run without a filename, it reads from stdin. But if --file option is used along with that, it may generate false positives.
Consider the following test file:
$cattest.c
int x = a - b;$cat
test.c|./scripts/checkpatch.pl-f
WARNING: It's generally not useful to have the filename in the file +int x = a - b;
Quoted 7 lines
This is a false positive and occurs because $realfile is set to "-". Also since checkpatch relies on the file's extension to run specific checks for c files, assembly files, etc, most of the checks are not run as well.
So it is better to disable -f/--file option when checkpatch is run without a filename.
That's a reasonable commit message, thanks.
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0
[]
Quoted 9 lines
scripts/checkpatch.pl +0
-0@@ -331,6 +331,7 @@ help(0) if ($help);die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix)); die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse); +die "$P: -f/--file requires at least one filename\n" if ($file && $#ARGV < 0);
if ($color =~ /^[01]$/) {
$color = !$color;
Quoted 4 lines · Joe Perches
Quoted 2 lines · Dwaipayan Ray
When checkpatch is run without a filename, it reads from stdin. But if --file option is used along with that, it may generate
But if the --file option is used...
Quoted 15 lines
Quoted 15 lines
false positives.
Consider the following test file:
$cattest.c
int x = a - b;$cat
test.c|./scripts/checkpatch.pl-f
WARNING: It's generally not useful to have the filename in the file +int x = a - b;This is a false positive and occurs because $realfile is set to "-". Also since checkpatch relies on the file's extension to run specific checks for c files, assembly files, etc, most of the checks are not run as well.
Quoted 5 lines
Quoted 2 lines
So it is better to disable -f/--file option when checkpatch is run without a filename.
That's a reasonable commit message, thanks.
That can be shortened to:
Disable -f/--file option when checkpatch is run without a filename.
How about adding a description in the checkpatch Documentation on this topic as well, as part of this patch?
Lukas
Quoted 13 lines
scripts/checkpatch.pl
Quoted 1 line
scripts/checkpatch.pl +0
-0[]
Quoted 9 lines
scripts/checkpatch.pl +1
-0@@ -331,6 +331,7 @@ help(0) if ($help); die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix)); die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse); +die "$P: -f/--file requires at least one filename\n" if ($file && $#ARGV < 0); if ($color =~ /^[01]$/) {$color = !$color;
Quoted 30 lines · Lukas Bulwahn
Quoted 4 lines · Joe Perches
Quoted 2 lines · Dwaipayan Ray
When checkpatch is run without a filename, it reads from stdin. But if --file option is used along with that, it may generate
But if the --file option is used...
Quoted 15 lines
Quoted 15 lines
false positives.
Consider the following test file:
$cattest.c
int x = a - b;$cat
test.c|./scripts/checkpatch.pl-f
WARNING: It's generally not useful to have the filename in the file +int x = a - b;This is a false positive and occurs because $realfile is set to "-". Also since checkpatch relies on the file's extension to run specific checks for c files, assembly files, etc, most of the checks are not run as well.
Quoted 5 lines
Quoted 2 lines
So it is better to disable -f/--file option when checkpatch is run without a filename.
That's a reasonable commit message, thanks.
Quoted 7 lines
That can be shortened to:
Disable -f/--file option when checkpatch is run without a filename.
How about adding a description in the checkpatch Documentation on this topic as well, as part of this patch?
I can also add it to the next batch of the documentation updates I am working on. That can list all the flag combinations that's not allowed. And we can let this patch go independently for now...
Thanks,
Dwaipayan.