All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] checkpatch: do not allow using -f/--file option without a filename
@ 2021-06-05 19:17 Dwaipayan Ray
  2021-06-05 19:32 ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Dwaipayan Ray @ 2021-06-05 19:17 UTC (permalink / raw)
  To: joe; +Cc: linux-kernel, lukas.bulwahn, 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:
$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.

Link: https://lore.kernel.org/lkml/294bb4a2c3f5f8cf4a744cf59bfd37562653afb9.camel@perches.com/T/#t
Suggested-by: Joe Perches <joe@perches.com>
Signed-off-by: Dwaipayan Ray <dwaipayanray1@gmail.com>
---
 scripts/checkpatch.pl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 3e1795311c87..7dff9206f9f0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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;
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] checkpatch: do not allow using -f/--file option without a filename
  2021-06-05 19:17 [PATCH] checkpatch: do not allow using -f/--file option without a filename Dwaipayan Ray
@ 2021-06-05 19:32 ` Joe Perches
  2021-06-07  5:11   ` Lukas Bulwahn
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2021-06-05 19:32 UTC (permalink / raw)
  To: Dwaipayan Ray, Andrew Morton; +Cc: linux-kernel, lukas.bulwahn

On Sun, 2021-06-06 at 00:47 +0530, Dwaipayan Ray wrote:
> 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.

That's a reasonable commit message, thanks.

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -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;



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] checkpatch: do not allow using -f/--file option without a filename
  2021-06-05 19:32 ` Joe Perches
@ 2021-06-07  5:11   ` Lukas Bulwahn
  2021-06-07  5:53     ` Dwaipayan Ray
  0 siblings, 1 reply; 4+ messages in thread
From: Lukas Bulwahn @ 2021-06-07  5:11 UTC (permalink / raw)
  To: Joe Perches; +Cc: Dwaipayan Ray, Andrew Morton, Linux Kernel Mailing List

On Sat, Jun 5, 2021 at 9:32 PM Joe Perches <joe@perches.com> wrote:
>
> On Sun, 2021-06-06 at 00:47 +0530, Dwaipayan Ray wrote:
> > 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...

> > 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.
>
> 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

> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> []
> > @@ -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;
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] checkpatch: do not allow using -f/--file option without a filename
  2021-06-07  5:11   ` Lukas Bulwahn
@ 2021-06-07  5:53     ` Dwaipayan Ray
  0 siblings, 0 replies; 4+ messages in thread
From: Dwaipayan Ray @ 2021-06-07  5:53 UTC (permalink / raw)
  To: Lukas Bulwahn; +Cc: Joe Perches, Andrew Morton, Linux Kernel Mailing List

On Mon, Jun 7, 2021 at 10:41 AM Lukas Bulwahn <lukas.bulwahn@gmail.com> wrote:
>
> On Sat, Jun 5, 2021 at 9:32 PM Joe Perches <joe@perches.com> wrote:
> >
> > On Sun, 2021-06-06 at 00:47 +0530, Dwaipayan Ray wrote:
> > > 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...
>
> > > 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.
> >
> > 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?
>

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-06-07  5:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-05 19:17 [PATCH] checkpatch: do not allow using -f/--file option without a filename Dwaipayan Ray
2021-06-05 19:32 ` Joe Perches
2021-06-07  5:11   ` Lukas Bulwahn
2021-06-07  5:53     ` Dwaipayan Ray

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.