public inbox for workflows@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] checkpatch: allow correctly handle full files on stdin
@ 2026-03-26  6:20 Dmitry Torokhov
  2026-03-26  8:46 ` Joe Perches
  0 siblings, 1 reply; 11+ messages in thread
From: Dmitry Torokhov @ 2026-03-26  6:20 UTC (permalink / raw)
  To: Dwaipayan Ray, Lukas Bulwahn, Joe Perches, Andy Whitcroft
  Cc: Jonathan Corbet, Shuah Khan, workflows, linux-doc, linux-kernel

checkpatch does not handle full files well when they are passed on
stdin, because it does not know how to treat the text, and whether it is
a C file, or a DTS file, or something else, and so it assumes that when
it works with stdin it should be a unified diff. For full files it
expects to have a file name as an argument and read the contents from
disk. Unfortunately this does not well when trying to use checkpatch as
an online linter and feed it contents of an editor buffer that have not
made it to the disk yet.

To solve the above introduce a new optional argument --stdin-filename=FILE
that allows tell checkpatch the kind of file it is dealing with and
apply appropriate set of checks and rules to it.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 Documentation/dev-tools/checkpatch.rst |  4 ++++
 scripts/checkpatch.pl                  | 11 +++++++++++
 2 files changed, 15 insertions(+)

diff --git a/Documentation/dev-tools/checkpatch.rst b/Documentation/dev-tools/checkpatch.rst
index dccede68698c..b521e3ca6ebf 100644
--- a/Documentation/dev-tools/checkpatch.rst
+++ b/Documentation/dev-tools/checkpatch.rst
@@ -68,6 +68,10 @@ Available options:
 
    Show the diffed file position instead of the input file position.
 
+ - --stdin-filename
+
+   When using stdin, identify the file as FILE.
+
  - -g,  --git
 
    Treat FILE as a single commit or a git revision range.
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e56374662ff7..e26951ceb36b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -57,6 +57,7 @@ my %ignore_type = ();
 my @ignore = ();
 my $help = 0;
 my $configuration_file = ".checkpatch.conf";
+my $stdin_filename;
 my $max_line_length = 100;
 my $ignore_perl_version = 0;
 my $minimum_perl_version = 5.10.0;
@@ -94,6 +95,7 @@ Options:
   --emacs                    emacs compile window format
   --terse                    one line per report
   --showfile                 emit diffed file position, not input file position
+  --stdin-filename=FILE      when using stdin, identify the file as FILE
   -g, --git                  treat FILE as a single commit or git revision range
                              single git commit with:
                                <rev>
@@ -323,6 +325,7 @@ GetOptions(
 	'showfile!'	=> \$showfile,
 	'f|file!'	=> \$file,
 	'g|git!'	=> \$git,
+	'stdin-filename=s' => \$stdin_filename,
 	'subjective!'	=> \$check,
 	'strict!'	=> \$check,
 	'ignore=s'	=> \@ignore,
@@ -2652,6 +2655,10 @@ sub is_userspace {
 sub process {
 	my $filename = shift;
 
+	if ($filename eq '-' && defined($stdin_filename)) {
+		$filename = $stdin_filename;
+	}
+
 	my $linenr=0;
 	my $prevline="";
 	my $prevrawline="";
@@ -2891,6 +2898,10 @@ sub process {
 			$realfile =~ s@^([^/]*)/@@ if (!$file);
 			$in_commit_log = 0;
 
+			if ($realfile eq "-" && defined($stdin_filename)) {
+				$realfile = $stdin_filename;
+			}
+
 			$p1_prefix = $1;
 			if (!$file && $tree && $p1_prefix ne '' &&
 			    -e "$root/$p1_prefix") {
-- 
2.53.0.1018.g2bb0e51243-goog


-- 
Dmitry

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

* Re: [PATCH] checkpatch: allow correctly handle full files on stdin
  2026-03-26  6:20 [PATCH] checkpatch: allow correctly handle full files on stdin Dmitry Torokhov
@ 2026-03-26  8:46 ` Joe Perches
  2026-03-26 14:53   ` Dmitry Torokhov
  0 siblings, 1 reply; 11+ messages in thread
From: Joe Perches @ 2026-03-26  8:46 UTC (permalink / raw)
  To: Dmitry Torokhov, Dwaipayan Ray, Lukas Bulwahn, Andy Whitcroft
  Cc: Jonathan Corbet, Shuah Khan, workflows, linux-doc, linux-kernel

On Wed, 2026-03-25 at 23:20 -0700, Dmitry Torokhov wrote:
> checkpatch does not handle full files well when they are passed on
> stdin, because it does not know how to treat the text, and whether it is
> a C file, or a DTS file, or something else, and so it assumes that when
> it works with stdin it should be a unified diff. For full files it
> expects to have a file name as an argument and read the contents from
> disk. Unfortunately this does not well when trying to use checkpatch as
> an online linter and feed it contents of an editor buffer that have not
> made it to the disk yet.

Why is this useful?
Why not save the buffer and then feed the file?

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

* Re: [PATCH] checkpatch: allow correctly handle full files on stdin
  2026-03-26  8:46 ` Joe Perches
@ 2026-03-26 14:53   ` Dmitry Torokhov
  2026-03-26 21:36     ` Joe Perches
  0 siblings, 1 reply; 11+ messages in thread
From: Dmitry Torokhov @ 2026-03-26 14:53 UTC (permalink / raw)
  To: Joe Perches
  Cc: Dwaipayan Ray, Lukas Bulwahn, Andy Whitcroft, Jonathan Corbet,
	Shuah Khan, workflows, linux-doc, linux-kernel

On Thu, Mar 26, 2026 at 01:46:49AM -0700, Joe Perches wrote:
> On Wed, 2026-03-25 at 23:20 -0700, Dmitry Torokhov wrote:
> > checkpatch does not handle full files well when they are passed on
> > stdin, because it does not know how to treat the text, and whether it is
> > a C file, or a DTS file, or something else, and so it assumes that when
> > it works with stdin it should be a unified diff. For full files it
> > expects to have a file name as an argument and read the contents from
> > disk. Unfortunately this does not well when trying to use checkpatch as
> > an online linter and feed it contents of an editor buffer that have not
> > made it to the disk yet.
> 
> Why is this useful?
> Why not save the buffer and then feed the file?

Because when I am editing a file I am not saving it all that often. I
want to have buffer diagnostic updated when I leave insert mode in vim.

Thanks.

-- 
Dmitry

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

* Re: [PATCH] checkpatch: allow correctly handle full files on stdin
  2026-03-26 14:53   ` Dmitry Torokhov
@ 2026-03-26 21:36     ` Joe Perches
  2026-03-26 21:42       ` Dmitry Torokhov
  0 siblings, 1 reply; 11+ messages in thread
From: Joe Perches @ 2026-03-26 21:36 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Dwaipayan Ray, Lukas Bulwahn, Andy Whitcroft, Jonathan Corbet,
	Shuah Khan, workflows, linux-doc, linux-kernel

On Thu, 2026-03-26 at 07:53 -0700, Dmitry Torokhov wrote:
> On Thu, Mar 26, 2026 at 01:46:49AM -0700, Joe Perches wrote:
> On Wed, 2026-03-25 at 23:20 -0700, Dmitry Torokhov wrote:
> checkpatch does not handle full files well when they are passed on
> > > stdin, because it does not know how to treat the text, and whether it is
> > > a C file, or a DTS file, or something else, and so it assumes that when
> > > it works with stdin it should be a unified diff. For full files it
> > > expects to have a file name as an argument and read the contents from
> > > disk. Unfortunately this does not well when trying to use checkpatch as
> > > an online linter and feed it contents of an editor buffer that have not
> > > made it to the disk yet.
> > 
> > Why is this useful?
> > Why not save the buffer and then feed the file?
> 
> Because when I am editing a file I am not saving it all that often. I
> want to have buffer diagnostic updated when I leave insert mode in vim.

I believe you are able to keep your own version of checkpatch.

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

* Re: [PATCH] checkpatch: allow correctly handle full files on stdin
  2026-03-26 21:36     ` Joe Perches
@ 2026-03-26 21:42       ` Dmitry Torokhov
  2026-03-26 22:56         ` Joe Perches
  0 siblings, 1 reply; 11+ messages in thread
From: Dmitry Torokhov @ 2026-03-26 21:42 UTC (permalink / raw)
  To: Joe Perches
  Cc: Dwaipayan Ray, Lukas Bulwahn, Andy Whitcroft, Jonathan Corbet,
	Shuah Khan, workflows, linux-doc, linux-kernel

On Thu, Mar 26, 2026 at 02:36:35PM -0700, Joe Perches wrote:
> On Thu, 2026-03-26 at 07:53 -0700, Dmitry Torokhov wrote:
> > On Thu, Mar 26, 2026 at 01:46:49AM -0700, Joe Perches wrote:
> > On Wed, 2026-03-25 at 23:20 -0700, Dmitry Torokhov wrote:
> > checkpatch does not handle full files well when they are passed on
> > > > stdin, because it does not know how to treat the text, and whether it is
> > > > a C file, or a DTS file, or something else, and so it assumes that when
> > > > it works with stdin it should be a unified diff. For full files it
> > > > expects to have a file name as an argument and read the contents from
> > > > disk. Unfortunately this does not well when trying to use checkpatch as
> > > > an online linter and feed it contents of an editor buffer that have not
> > > > made it to the disk yet.
> > > 
> > > Why is this useful?
> > > Why not save the buffer and then feed the file?
> > 
> > Because when I am editing a file I am not saving it all that often. I
> > want to have buffer diagnostic updated when I leave insert mode in vim.
> 
> I believe you are able to keep your own version of checkpatch.

As well as my version of the kernel, gcc, clang, editor, git and so on.

Do you have any constructive feedback? Right now checkpatch is broken
when using "-f" with stdin and I offer a fix. If you have a better way
in mind by all means share it.

Thanks.

-- 
Dmitry

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

* Re: [PATCH] checkpatch: allow correctly handle full files on stdin
  2026-03-26 21:42       ` Dmitry Torokhov
@ 2026-03-26 22:56         ` Joe Perches
  2026-03-26 23:04           ` Dmitry Torokhov
  0 siblings, 1 reply; 11+ messages in thread
From: Joe Perches @ 2026-03-26 22:56 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Dwaipayan Ray, Lukas Bulwahn, Andy Whitcroft, Jonathan Corbet,
	Shuah Khan, workflows, linux-doc, linux-kernel

On Thu, 2026-03-26 at 14:42 -0700, Dmitry Torokhov wrote:
> > > Because when I am editing a file I am not saving it all that often. I
> > > want to have buffer diagnostic updated when I leave insert mode in vim.
> > 
> > I believe you are able to keep your own version of checkpatch.
> 
> As well as my version of the kernel, gcc, clang, editor, git and so on.
> 
> Do you have any constructive feedback?

I gave you feedback.  You elided it.

> Right now checkpatch is broken
> when using "-f" with stdin and I offer a fix. If you have a better way
> in mind by all means share it.

Note the name.  Feed it a patch.  It works fine.  It's not broken.

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

* Re: [PATCH] checkpatch: allow correctly handle full files on stdin
  2026-03-26 22:56         ` Joe Perches
@ 2026-03-26 23:04           ` Dmitry Torokhov
  2026-03-26 23:10             ` Joe Perches
  2026-03-26 23:19             ` Joe Perches
  0 siblings, 2 replies; 11+ messages in thread
From: Dmitry Torokhov @ 2026-03-26 23:04 UTC (permalink / raw)
  To: Joe Perches
  Cc: Dwaipayan Ray, Lukas Bulwahn, Andy Whitcroft, Jonathan Corbet,
	Shuah Khan, workflows, linux-doc, linux-kernel

On Thu, Mar 26, 2026 at 03:56:27PM -0700, Joe Perches wrote:
> On Thu, 2026-03-26 at 14:42 -0700, Dmitry Torokhov wrote:
> > > > Because when I am editing a file I am not saving it all that often. I
> > > > want to have buffer diagnostic updated when I leave insert mode in vim.
> > > 
> > > I believe you are able to keep your own version of checkpatch.
> > 
> > As well as my version of the kernel, gcc, clang, editor, git and so on.
> > 
> > Do you have any constructive feedback?
> 
> I gave you feedback.  You elided it.

Could you please point me to it? All I saw is "just save it" and "keep
your own copy". Neither of this suggestions are particularly useful.

> 
> > Right now checkpatch is broken
> > when using "-f" with stdin and I offer a fix. If you have a better way
> > in mind by all means share it.
> 
> Note the name.  Feed it a patch.  It works fine.  It's not broken.

This option is a bug then and should be removed:

"-f, --file                 treat FILE as regular source file"

right?

In all seriousness, if you will not make use of this mode it's fine. But
it allows keeping the source cleaner as one makes edits, so why not
enable this?

-- 
Dmitry

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

* Re: [PATCH] checkpatch: allow correctly handle full files on stdin
  2026-03-26 23:04           ` Dmitry Torokhov
@ 2026-03-26 23:10             ` Joe Perches
  2026-03-26 23:19               ` Dmitry Torokhov
  2026-03-26 23:19             ` Joe Perches
  1 sibling, 1 reply; 11+ messages in thread
From: Joe Perches @ 2026-03-26 23:10 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Dwaipayan Ray, Lukas Bulwahn, Andy Whitcroft, Jonathan Corbet,
	Shuah Khan, workflows, linux-doc, linux-kernel

On Thu, 2026-03-26 at 16:04 -0700, Dmitry Torokhov wrote:
> On Thu, Mar 26, 2026 at 03:56:27PM -0700, Joe Perches wrote:
> > I gave you feedback.  You elided it.
> Could you please point me to it? All I saw is "just save it"

Seems constructive to me.

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

* Re: [PATCH] checkpatch: allow correctly handle full files on stdin
  2026-03-26 23:10             ` Joe Perches
@ 2026-03-26 23:19               ` Dmitry Torokhov
  2026-03-26 23:27                 ` Joe Perches
  0 siblings, 1 reply; 11+ messages in thread
From: Dmitry Torokhov @ 2026-03-26 23:19 UTC (permalink / raw)
  To: Joe Perches, Andrew Morton
  Cc: Dwaipayan Ray, Lukas Bulwahn, Andy Whitcroft, Jonathan Corbet,
	Shuah Khan, workflows, linux-doc, linux-kernel

On Thu, Mar 26, 2026 at 04:10:05PM -0700, Joe Perches wrote:
> On Thu, 2026-03-26 at 16:04 -0700, Dmitry Torokhov wrote:
> > On Thu, Mar 26, 2026 at 03:56:27PM -0700, Joe Perches wrote:
> > > I gave you feedback.  You elided it.
> > Could you please point me to it? All I saw is "just save it"
> 
> Seems constructive to me.

As constructive as "You're holding it wrong". I want to be able to run
checkpatch as I am typing, not at some later time. My editor shows
diagnostics as a virtual text, so it is quite confusing that the error
is still shown even after I fixed the issue.

It looks like I forgot to add akpm to CC, let me add him...

Thanks.

-- 
Dmitry

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

* Re: [PATCH] checkpatch: allow correctly handle full files on stdin
  2026-03-26 23:04           ` Dmitry Torokhov
  2026-03-26 23:10             ` Joe Perches
@ 2026-03-26 23:19             ` Joe Perches
  1 sibling, 0 replies; 11+ messages in thread
From: Joe Perches @ 2026-03-26 23:19 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Dwaipayan Ray, Lukas Bulwahn, Andy Whitcroft, Jonathan Corbet,
	Shuah Khan, workflows, linux-doc, linux-kernel

On Thu, 2026-03-26 at 16:04 -0700, Dmitry Torokhov wrote:
> In all seriousness, if you will not make use of this mode it's fine. But
> it allows keeping the source cleaner as one makes edits, so why not
> enable this?

Unnecessary complication.

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

* Re: [PATCH] checkpatch: allow correctly handle full files on stdin
  2026-03-26 23:19               ` Dmitry Torokhov
@ 2026-03-26 23:27                 ` Joe Perches
  0 siblings, 0 replies; 11+ messages in thread
From: Joe Perches @ 2026-03-26 23:27 UTC (permalink / raw)
  To: Dmitry Torokhov, Andrew Morton
  Cc: Dwaipayan Ray, Lukas Bulwahn, Andy Whitcroft, Jonathan Corbet,
	Shuah Khan, workflows, linux-doc, linux-kernel

On Thu, 2026-03-26 at 16:19 -0700, Dmitry Torokhov wrote:
> On Thu, Mar 26, 2026 at 03:56:27PM -0700, Joe Perches wrote:
> I gave you feedback.  You elided it.
> > > Could you please point me to it? All I saw is "just save it"
> > Seems constructive to me.
> As constructive as "You're holding it wrong". I want to be able to run
> checkpatch as I am typing, not at some later time. My editor shows
> diagnostics as a virtual text, so it is quite confusing that the error
> is still shown even after I fixed the issue.
> 
> It looks like I forgot to add akpm to CC, let me add him...

No worries.  nak.

It's not something I want to support.

cheers, Joe

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

end of thread, other threads:[~2026-03-26 23:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-26  6:20 [PATCH] checkpatch: allow correctly handle full files on stdin Dmitry Torokhov
2026-03-26  8:46 ` Joe Perches
2026-03-26 14:53   ` Dmitry Torokhov
2026-03-26 21:36     ` Joe Perches
2026-03-26 21:42       ` Dmitry Torokhov
2026-03-26 22:56         ` Joe Perches
2026-03-26 23:04           ` Dmitry Torokhov
2026-03-26 23:10             ` Joe Perches
2026-03-26 23:19               ` Dmitry Torokhov
2026-03-26 23:27                 ` Joe Perches
2026-03-26 23:19             ` Joe Perches

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