mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] checkpatch: Fix check for embedded filename
@ 2021-06-05 16:12 Dwaipayan Ray
  2021-06-05 17:21 ` Joe Perches
  0 siblings, 1 reply; 6+ messages in thread
From: Dwaipayan Ray @ 2021-06-05 16:12 UTC (permalink / raw)
  To: joe; +Cc: linux-kernel, lukas.bulwahn, Dwaipayan Ray

When checkpatch is run on file contents piped through stdin,
it may generate false EMBEDDED_FILENAME warnings if the
--file flag is used.

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;

So any instance of "-" in the file contents will trigger
an EMBEDDED_FILENAME warning.

Fix it by checking if $realfile is not "-".

Signed-off-by: Dwaipayan Ray <dwaipayanray1@gmail.com>
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 3e1795311c87..2f50fafa0ac1 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3619,7 +3619,7 @@ sub process {
 		}
 
 # check for embedded filenames
-		if ($rawline =~ /^\+.*\Q$realfile\E/) {
+		if ($realfile ne "-" && $rawline =~ /^\+.*\Q$realfile\E/) {
 			WARN("EMBEDDED_FILENAME",
 			     "It's generally not useful to have the filename in the file\n" . $herecurr);
 		}
-- 
2.28.0


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

* Re: [PATCH] checkpatch: Fix check for embedded filename
  2021-06-05 16:12 [PATCH] checkpatch: Fix check for embedded filename Dwaipayan Ray
@ 2021-06-05 17:21 ` Joe Perches
  2021-06-05 17:33   ` Dwaipayan Ray
  0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2021-06-05 17:21 UTC (permalink / raw)
  To: Dwaipayan Ray; +Cc: linux-kernel, lukas.bulwahn

On Sat, 2021-06-05 at 21:42 +0530, Dwaipayan Ray wrote:
> When checkpatch is run on file contents piped through stdin,
> it may generate false EMBEDDED_FILENAME warnings if the
> --file flag is used.

I think this is a "don't do that" scenario and this change
is not necessary.




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

* Re: [PATCH] checkpatch: Fix check for embedded filename
  2021-06-05 17:21 ` Joe Perches
@ 2021-06-05 17:33   ` Dwaipayan Ray
  2021-06-05 18:33     ` Joe Perches
  0 siblings, 1 reply; 6+ messages in thread
From: Dwaipayan Ray @ 2021-06-05 17:33 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-kernel, Lukas Bulwahn

On Sat, Jun 5, 2021 at 10:51 PM Joe Perches <joe@perches.com> wrote:
>
> On Sat, 2021-06-05 at 21:42 +0530, Dwaipayan Ray wrote:
> > When checkpatch is run on file contents piped through stdin,
> > it may generate false EMBEDDED_FILENAME warnings if the
> > --file flag is used.
>
> I think this is a "don't do that" scenario and this change
> is not necessary.
>

Okay then. I will drop this.
Sorry for the noise.

Thanks & Regards,
Dwaipayan.

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

* Re: [PATCH] checkpatch: Fix check for embedded filename
  2021-06-05 17:33   ` Dwaipayan Ray
@ 2021-06-05 18:33     ` Joe Perches
  2021-06-05 18:44       ` Dwaipayan Ray
  0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2021-06-05 18:33 UTC (permalink / raw)
  To: Dwaipayan Ray; +Cc: linux-kernel, Lukas Bulwahn

On Sat, 2021-06-05 at 23:03 +0530, Dwaipayan Ray wrote:
> On Sat, Jun 5, 2021 at 10:51 PM Joe Perches <joe@perches.com> wrote:
> > 
> > On Sat, 2021-06-05 at 21:42 +0530, Dwaipayan Ray wrote:
> > > When checkpatch is run on file contents piped through stdin,
> > > it may generate false EMBEDDED_FILENAME warnings if the
> > > --file flag is used.
> > 
> > I think this is a "don't do that" scenario and this change
> > is not necessary.
> > 
> 
> Okay then. I will drop this.
> Sorry for the noise.

I think you want something like this:
---
 scripts/checkpatch.pl | 1 +
 1 file changed, 1 insertion(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index dad87c3686326..582f8e07d32d5 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;


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

* Re: [PATCH] checkpatch: Fix check for embedded filename
  2021-06-05 18:33     ` Joe Perches
@ 2021-06-05 18:44       ` Dwaipayan Ray
  2021-06-05 18:52         ` Joe Perches
  0 siblings, 1 reply; 6+ messages in thread
From: Dwaipayan Ray @ 2021-06-05 18:44 UTC (permalink / raw)
  To: Joe Perches; +Cc: linux-kernel, Lukas Bulwahn

On Sun, Jun 6, 2021 at 12:03 AM Joe Perches <joe@perches.com> wrote:
>
> On Sat, 2021-06-05 at 23:03 +0530, Dwaipayan Ray wrote:
> > On Sat, Jun 5, 2021 at 10:51 PM Joe Perches <joe@perches.com> wrote:
> > >
> > > On Sat, 2021-06-05 at 21:42 +0530, Dwaipayan Ray wrote:
> > > > When checkpatch is run on file contents piped through stdin,
> > > > it may generate false EMBEDDED_FILENAME warnings if the
> > > > --file flag is used.
> > >
> > > I think this is a "don't do that" scenario and this change
> > > is not necessary.
> > >
> >
> > Okay then. I will drop this.
> > Sorry for the noise.
>
> I think you want something like this:
> ---
>  scripts/checkpatch.pl | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index dad87c3686326..582f8e07d32d5 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;
>

Yes, that's nice.
Most of the checks don't work with piped input when --file
is specified. So disabling it will avoid any confusion.

I can send in a patch if it's okay with you.

Thanks,
Dwaipayan.

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

* Re: [PATCH] checkpatch: Fix check for embedded filename
  2021-06-05 18:44       ` Dwaipayan Ray
@ 2021-06-05 18:52         ` Joe Perches
  0 siblings, 0 replies; 6+ messages in thread
From: Joe Perches @ 2021-06-05 18:52 UTC (permalink / raw)
  To: Dwaipayan Ray; +Cc: linux-kernel, Lukas Bulwahn

On Sun, 2021-06-06 at 00:14 +0530, Dwaipayan Ray wrote:
> On Sun, Jun 6, 2021 at 12:03 AM Joe Perches <joe@perches.com> wrote:
> > On Sat, 2021-06-05 at 23:03 +0530, Dwaipayan Ray wrote:
> > > On Sat, Jun 5, 2021 at 10:51 PM Joe Perches <joe@perches.com> wrote:
> > > > On Sat, 2021-06-05 at 21:42 +0530, Dwaipayan Ray wrote:
> > > > > When checkpatch is run on file contents piped through stdin,
> > > > > it may generate false EMBEDDED_FILENAME warnings if the
> > > > > --file flag is used.
> > > > 
> > > > I think this is a "don't do that" scenario and this change
> > > > is not necessary.
> > > > 
> > > 
> > > Okay then. I will drop this.
> > > Sorry for the noise.
> > 
> > I think you want something like this:
> > ---
> > 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;
> > 
> 
> Yes, that's nice.
> Most of the checks don't work with piped input when --file
> is specified. So disabling it will avoid any confusion.
> 
> I can send in a patch if it's okay with you.

Fine by me.  You noticed, your patch...



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

end of thread, other threads:[~2021-06-05 18:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-05 16:12 [PATCH] checkpatch: Fix check for embedded filename Dwaipayan Ray
2021-06-05 17:21 ` Joe Perches
2021-06-05 17:33   ` Dwaipayan Ray
2021-06-05 18:33     ` Joe Perches
2021-06-05 18:44       ` Dwaipayan Ray
2021-06-05 18:52         ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®