checkpatch: Warn about sign offs if there's an accidental patch separator
Subsystems (4)
PATCH 1/1 checkpatch: Warn about sign offs if there's an accidental patch separator
The regex ^---$ to detect a patch separator, means a patch is considerd to have been separated only when the line is exactly just "---". git-mailinfo (and thus git am) treats any line starting with "---" as the start of a patch. This can mean a comment causes git-mailinfo to truncate the commit message if the line in the comment starts with "---". checkpatch won't warn about things like missing sign offs after the "---" started comment as it doesn't see the patch as having started yet. The recording of sign offs is made to ignore the case it is in a patch. This issue caused missing tags in commit 6528cdd61590 ("perf tests stat: Add test for error for an offline CPU") as reported by Stephen Rothwell <[email protected]> in:
https://lore.kernel.org/lkml/[email protected]/
Before:
$ ./scripts/checkpatch.pl v2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch total: 0 errors, 0 warnings, 39 lines checked
v2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch has no obvious style problems and is ready for submission.
After:
$ ./scripts/checkpatch.pl v2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch ERROR: Missing Signed-off-by: line(s)
total: 1 errors, 0 warnings, 39 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
v2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch has style problems, please review.
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.
--- scripts/checkpatch.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +7 -2
@@ -2819,6 +2819,11 @@ sub process { $is_patch = 1; } +# Once the patch separator is encountered git-mailinfo will treat the rest as a patch + if ($has_patch_separator) { + $is_patch = 1; + } + #extract the line range in the file after the patch is applied if (!$in_commit_log && $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
@@ -2989,7 +2994,7 @@ sub process { } # Check the patch for a signoff: - if ($line =~ /^\s*signed-off-by:\s*(.*)/i) { + if (!$is_patch && $line =~ /^\s*signed-off-by:\s*(.*)/i) { $signoff++; $in_commit_log = 0; if ($author ne '' && $authorsignoff != 1) {
@@ -3028,7 +3033,7 @@ sub process { } # Check for patch separator - if ($line =~ /^---$/) { + if ($line =~ /^---/) { $has_patch_separator = 1; $in_commit_log = 0; }
Signature · 1 line
2.52.0.223.gf5cc29aaa4-goog
Quoted 10 lines · Ian Rogers
The regex ^---$ to detect a patch separator, means a patch is considerd to have been separated only when the line is exactly just "---". git-mailinfo (and thus git am) treats any line starting with "---" as the start of a patch. This can mean a comment causes git-mailinfo to truncate the commit message if the line in the comment starts with "---". checkpatch won't warn about things like missing sign offs after the "---" started comment as it doesn't see the patch as having started yet. The recording of sign offs is made to ignore the case it is in a patch. This issue caused missing tags in commit
6528cdd61590("perf tests stat: Add test for error for an offline CPU")
I guess Namhyung might fix up this commit and force push the branch, meaning this specific sha id won't exist in Linus' tree later. Given that, I'm not sure it is appropriate to reference this sha id here?
Quoted 20 lines
as reported by Stephen Rothwell <[email protected]> in:
https://lore.kernel.org/lkml/[email protected]/Before:
$ ./scripts/checkpatch.pl v2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch total: 0 errors, 0 warnings, 39 lines checkedv2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch has no obvious style problems and is ready for submission.
After:
$ ./scripts/checkpatch.pl v2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch ERROR: Missing Signed-off-by: line(s)total: 1 errors, 0 warnings, 39 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.
Quoted 6 lines
v2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch has style problems, please review.
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH inMAINTAINERS.Signed-off-by Ian Rogers <[email protected]>
FWIW:
Regards,
Kuan-Wei
Quoted 42 lines
--- scripts/checkpatch.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)scripts/checkpatch.pl +7
-2@@ -2819,6 +2819,11 @@ sub process { $is_patch = 1; } +# Once the patch separator is encountered git-mailinfo will treat the rest as a patch + if ($has_patch_separator) { + $is_patch = 1; + } + #extract the line range in the file after the patch is applied if (!$in_commit_log && $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {@@ -2989,7 +2994,7 @@ sub process { } # Check the patch for a signoff: - if ($line =~ /^\s*signed-off-by:\s*(.*)/i) { + if (!$is_patch && $line =~ /^\s*signed-off-by:\s*(.*)/i) { $signoff++; $in_commit_log = 0; if ($author ne '' && $authorsignoff != 1) {@@ -3028,7 +3033,7 @@ sub process { } # Check for patch separator - if ($line =~ /^---$/) { + if ($line =~ /^---/) { $has_patch_separator = 1; $in_commit_log = 0; }Signature · 1 line
2.52.0.223.gf5cc29aaa4-goog
Quoted 39 lines · Kuan-Wei Chiu
Quoted 10 lines · Ian Rogers
The regex ^---$ to detect a patch separator, means a patch is considerd to have been separated only when the line is exactly just "---". git-mailinfo (and thus git am) treats any line starting with "---" as the start of a patch. This can mean a comment causes git-mailinfo to truncate the commit message if the line in the comment starts with "---". checkpatch won't warn about things like missing sign offs after the "---" started comment as it doesn't see the patch as having started yet. The recording of sign offs is made to ignore the case it is in a patch. This issue caused missing tags in commit
6528cdd61590("perf tests stat: Add test for error for an offline CPU")I guess Namhyung might fix up this commit and force push the branch, meaning this specific sha id won't exist in Linus' tree later. Given that, I'm not sure it is appropriate to reference this sha id here?
Quoted 22 lines
as reported by Stephen Rothwell <[email protected]> in:
https://lore.kernel.org/lkml/[email protected]/Before:
$ ./scripts/checkpatch.pl v2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch total: 0 errors, 0 warnings, 39 lines checkedv2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch has no obvious style problems and is ready for submission.
After:
$ ./scripts/checkpatch.pl v2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch ERROR: Missing Signed-off-by: line(s)total: 1 errors, 0 warnings, 39 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.v2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch has style problems, please review.
Quoted 8 lines
Quoted 4 lines
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH inMAINTAINERS.Signed-off-by Ian Rogers <[email protected]>FWIW:
Tested-by Kuan-Wei Chiu <[email protected]>
Thanks Kuan-Wei! Is there anything else I need to do for this improvement to land?
Thanks,
Ian
Quoted 45 lines
Regards,
Kuan-WeiQuoted 42 lines
--- scripts/checkpatch.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)scripts/checkpatch.pl +7
-3@@ -2819,6 +2819,11 @@ sub process { $is_patch = 1; } +# Once the patch separator is encountered git-mailinfo will treat the rest as a patch + if ($has_patch_separator) { + $is_patch = 1; + } + #extract the line range in the file after the patch is applied if (!$in_commit_log && $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {@@ -2989,7 +2994,7 @@ sub process { } # Check the patch for a signoff: - if ($line =~ /^\s*signed-off-by:\s*(.*)/i) { + if (!$is_patch && $line =~ /^\s*signed-off-by:\s*(.*)/i) { $signoff++; $in_commit_log = 0; if ($author ne '' && $authorsignoff != 1) {@@ -3028,7 +3033,7 @@ sub process { } # Check for patch separator - if ($line =~ /^---$/) { + if ($line =~ /^---/) { $has_patch_separator = 1; $in_commit_log = 0; } --2.52.0.223.gf5cc29aaa4-goog
+Cc Andrew Morton,
Quoted 43 lines · Ian Rogers
Quoted 42 lines · Kuan-Wei Chiu
Quoted 10 lines · Ian Rogers
The regex ^---$ to detect a patch separator, means a patch is considerd to have been separated only when the line is exactly just "---". git-mailinfo (and thus git am) treats any line starting with "---" as the start of a patch. This can mean a comment causes git-mailinfo to truncate the commit message if the line in the comment starts with "---". checkpatch won't warn about things like missing sign offs after the "---" started comment as it doesn't see the patch as having started yet. The recording of sign offs is made to ignore the case it is in a patch. This issue caused missing tags in commit
6528cdd61590("perf tests stat: Add test for error for an offline CPU")I guess Namhyung might fix up this commit and force push the branch, meaning this specific sha id won't exist in Linus' tree later. Given that, I'm not sure it is appropriate to reference this sha id here?
Quoted 25 lines
as reported by Stephen Rothwell <[email protected]> in:
https://lore.kernel.org/lkml/[email protected]/Before:
$ ./scripts/checkpatch.pl v2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch total: 0 errors, 0 warnings, 39 lines checkedv2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch has no obvious style problems and is ready for submission.
After:
$ ./scripts/checkpatch.pl v2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch ERROR: Missing Signed-off-by: line(s)total: 1 errors, 0 warnings, 39 lines checked
NOTE: For some of the reported defects, checkpatch may be able to
mechanically convert to the typical style using --fix or --fix-inplace.v2-0006-perf-tests-stat-Add-test-for-error-for-an-offline.patch has style problems, please review.
NOTE: If any of the errors are false positives, please report
them to the maintainer, see CHECKPATCH inMAINTAINERS.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Signed-off-by Ian Rogers <[email protected]>FWIW:
Tested-by Kuan-Wei Chiu <[email protected]>Thanks Kuan-Wei! Is there anything else I need to do for this improvement to land?
IIRC, most checkpatch.pl related patches are routed through the mm-nonmm branch, so I am Cc'ing Andrew for help picking this up.
That said, any Ack/Review or feedback from checkpatch.pl maintainers/reviewers would still be helpful and appreciated.
Regards,
Kuan-Wei
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
--- scripts/checkpatch.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)scripts/checkpatch.pl +7
-3@@ -2819,6 +2819,11 @@ sub process { $is_patch = 1; } +# Once the patch separator is encountered git-mailinfo will treat the rest as a patch + if ($has_patch_separator) { + $is_patch = 1; + } + #extract the line range in the file after the patch is applied if (!$in_commit_log && $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {@@ -2989,7 +2994,7 @@ sub process { } # Check the patch for a signoff: - if ($line =~ /^\s*signed-off-by:\s*(.*)/i) { + if (!$is_patch && $line =~ /^\s*signed-off-by:\s*(.*)/i) { $signoff++; $in_commit_log = 0; if ($author ne '' && $authorsignoff != 1) {@@ -3028,7 +3033,7 @@ sub process { } # Check for patch separator - if ($line =~ /^---$/) { + if ($line =~ /^---/) { $has_patch_separator = 1; $in_commit_log = 0; } --2.52.0.223.gf5cc29aaa4-goog
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines · Joe Perches
Quoted 1 line · Kuan-Wei Chiu
+Cc Andrew Morton,
[]
Quoted 7 lines
Quoted 2 lines
That said, any Ack/Review or feedback from checkpatch.pl maintainers/reviewers would still be helpful and appreciated.
I think most of this is pointless and incorrect besides. A patch separator is specifically 3 dashes not a line that starts with 3 or more dashes.
Thanks Joe, do you have a reference for this? I was going off-of git's behavior and I think the commit message covers that this patch is fixing checkpatch.pl's behavior to match that of git's wrt lines starting '---'. Or are you saying that git is broken and we should patch git? In this case it would still be a useful lint test for checkpatch.pl to warn about the '---' behavior for old versions of git
- at some future date when all gits have the patch then the checkpatch.pl behavior can switch from '^---' to '^---$' again. In summary, I think it is still the right thing for this patch to be carried unless you have other concerns - could you be more specific on what you mean by "most of this".
Thanks,
Ian
Quoted 2 lines
See the original problem
https://lore.kernel.org/lkml/[email protected]/
Joe Perches
maintainerQuoted 10 lines · Ian Rogers
Quoted 9 lines · Joe Perches
Quoted 1 line · Kuan-Wei Chiu
+Cc Andrew Morton,
[]
Quoted 2 lines
That said, any Ack/Review or feedback from checkpatch.pl maintainers/reviewers would still be helpful and appreciated.
Quoted 5 lines
Quoted 3 lines
I think most of this is pointless and incorrect besides. A patch separator is specifically 3 dashes not a line that starts with 3 or more dashes.
Thanks Joe, do you have a reference for this?
[]
Quoted 2 lines
Quoted 2 lines
See the original problem
https://lore.kernel.org/lkml/[email protected]/
Did you look at this?
Quoted 16 lines · Joe Perches
Quoted 14 lines · Ian Rogers
Quoted 12 lines · Joe Perches
Quoted 1 line · Kuan-Wei Chiu
+Cc Andrew Morton,
[]
Quoted 2 lines
That said, any Ack/Review or feedback from checkpatch.pl maintainers/reviewers would still be helpful and appreciated.
I think most of this is pointless and incorrect besides. A patch separator is specifically 3 dashes not a line that starts with 3 or more dashes.
Quoted 6 lines
Quoted 1 line
Thanks Joe, do you have a reference for this?
[]
Quoted 2 lines
Quoted 2 lines
See the original problem
https://lore.kernel.org/lkml/[email protected]/Did you look at this?
I was the author of it. The patch passed checkpatch.pl but then created a commit with missing tags - ie it was broken. This patch is fixing this issue so that checkpatch.pl will warn about the missing tags prior to the patch being sent to LKML, which is kind of checkpatch.pl's purpose. This is all detailed in the commit message.
Thanks,
Ian Rogers
Joe Perches
maintainerQuoted 5 lines · Ian Rogers
I was the author of it. The patch passed checkpatch.pl but then created a commit with missing tags - ie it was broken. This patch is fixing this issue so that checkpatch.pl will warn about the missing tags prior to the patch being sent to LKML, which is kind of checkpatch.pl's purpose. This is all detailed in the commit message.
Whatever was the tool that applied the patch should be fixed instead.
Quoted 9 lines · Joe Perches
Quoted 5 lines · Ian Rogers
I was the author of it. The patch passed checkpatch.pl but then created a commit with missing tags - ie it was broken. This patch is fixing this issue so that checkpatch.pl will warn about the missing tags prior to the patch being sent to LKML, which is kind of checkpatch.pl's purpose. This is all detailed in the commit message.
Whatever was the tool that applied the patch should be fixed instead.
The tool was git. As I mentioned, we can patch git but old versions will still have the '^---' rather than '^---$' behavior and so these checkpatch.pl tests remain useful.
Thanks,
Ian
Quoted 9 lines · On Mon, 5 Jan 2026 09:13:49 -0800 Ian Rogers <[email protected]> wrote:
Quoted 8 lines · Joe Perches
Quoted 5 lines · Ian Rogers
I was the author of it. The patch passed checkpatch.pl but then created a commit with missing tags - ie it was broken. This patch is fixing this issue so that checkpatch.pl will warn about the missing tags prior to the patch being sent to LKML, which is kind of checkpatch.pl's purpose. This is all detailed in the commit message.
Quoted 6 lines
Quoted 1 line
Whatever was the tool that applied the patch should be fixed instead.
The tool was git. As I mentioned, we can patch git but old versions will still have the '^---' rather than '^---$' behavior and so these checkpatch.pl tests remain useful.
I was bitten by this recently. Someone's changelog had
----------- stuff here
and git-quiltimport remove half the changelog and all the metadata.
git is wrong. I say so coz I invented the --- convention. submitting-patches.rst says
- A marker line containing simply ``---``.
The astonishingly old https://www.ozlabs.org/~akpm/stuff/tpp.txt says "... scripts will treat a ^--- string as ...". I regret not explicitly using "^---$".
I'd like checkpatch to emit a warning in this case. If a line starts with --- then please let's warn the user that downstream tooling will screw this up.
Hi Andrew,
Quoted 6 lines · On Tue, 13 Jan 2026 19:33:19 -0800 Andrew Morton <[email protected]>…
git is wrong. I say so coz I invented the --- convention.
submitting-patches.rstsays- A marker line containing simply ``---``.
Quoted 7 lines
The astonishingly old https://www.ozlabs.org/~akpm/stuff/tpp.txt says "... scripts will treat a ^--- string as ...". I regret not explicitly using "^---$".
I'd like checkpatch to emit a warning in this case. If a line starts with --- then please let's warn the user that downstream tooling will screw this up.
https://en.wikipedia.org/wiki/Signature_block#Standard_delimiter
I have used dash-dash-space for as long as I can remember (which varies these days ;-) ).
Signature · 2 lines
Cheers, Stephen Rothwell
Joe Perches
maintainerQuoted 11 lines · Andrew Morton
I was bitten by this recently. Someone's changelog had
----------- stuff here
and git-quiltimport remove half the changelog and all the metadata.
git is wrong. I say so coz I invented the --- convention.
submitting-patches.rstsays- A marker line containing simply ``---``.
Quoted 7 lines
The astonishingly old https://www.ozlabs.org/~akpm/stuff/tpp.txt says "... scripts will treat a ^--- string as ...". I regret not explicitly using "^---$".
I'd like checkpatch to emit a warning in this case. If a line starts with --- then please let's warn the user that downstream tooling will screw this up.
Maybe something like this:
--- scripts/checkpatch.pl | 8 ++++++++ 1 file changed, 8 insertions(+)
scripts/checkpatch.pl +8 -0
@@ -3035,6 +3035,14 @@ sub process { } } +# Check for invalid patch separator + if ($in_commit_log && + $line =~ /^---.+/) { + ERROR("BAD_PATCH_SEPARATOR", + "Invalid patch separator - some tools may have problems applying this\n" . $herecurr) + } + + # Check for patch separator if ($line =~ /^---$/) { $has_patch_separator = 1;
Quoted 35 lines · Joe Perches
Quoted 11 lines · Andrew Morton
I was bitten by this recently. Someone's changelog had
----------- stuff here
and git-quiltimport remove half the changelog and all the metadata.
git is wrong. I say so coz I invented the --- convention.
submitting-patches.rstsays- A marker line containing simply ``---``.
Quoted 7 lines
The astonishingly old https://www.ozlabs.org/~akpm/stuff/tpp.txt says "... scripts will treat a ^--- string as ...". I regret not explicitly using "^---$".
I'd like checkpatch to emit a warning in this case. If a line starts with --- then please let's warn the user that downstream tooling will screw this up.
Maybe something like this:
--- scripts/checkpatch.pl | 8 ++++++++ 1 file changed, 8 insertions(+)scripts/checkpatch.pl +1
-0@@ -3035,6 +3035,14 @@ sub process { } } +# Check for invalid patch separator
scripts/checkpatch.pl sub process { · line 3048
Quoted 10 lines
scripts/checkpatch.pl +7
-0+ if ($in_commit_log && + $line =~ /^---.+/) { + ERROR("BAD_PATCH_SEPARATOR", + "Invalid patch separator - some tools may have problems applying this\n" . $herecurr) + } + + # Check for patch separator if ($line =~ /^---$/) { $has_patch_separator = 1;
Sgtm, it still seems potentially error prone that sign offs are counted even when not in the commit message. ie this bit of this patch:
```
# Check the patch for a signoff:
- if ($line =~ /^\s*signed-off-by:\s*(.*)/i) {
+ if (!$is_patch && $line =~ /^\s*signed-off-by:\s*(.*)/i) {
$signoff++;
$in_commit_log = 0;
if ($author ne '' && $authorsignoff != 1) {
```Thanks,
Ian
Joe Perches
maintainerPATCH 1/1 checkpatch: Add an invalid patch separator test
In reply to Andrew MortonSome versions of tools that apply patches incorrectly allow lines that start with 3 dashes and have additional content on the same line.
Checkpatch will now emit an ERROR on these lines and optionally convert those lines from dashes to equals with --fix.
--- Documentation/dev-tools/checkpatch.rst | 5 +++++ scripts/checkpatch.pl | 10 ++++++++++ 2 files changed, 15 insertions(+)
Documentation/dev-tools/checkpatch.rst +5 -0
@@ -601,6 +601,11 @@ Commit message See: https://www.kernel.org/doc/html/latest/process/submitting-patches.html#describe-your-changes + **BAD_COMMIT_SEPARATOR** + The commit separator is a single line with 3 dashes. + The regex match is '^---$' + Lines that start with 3 dashes and have more content on the same line + may confuse tools that apply patches. Comparison style ----------------
scripts/checkpatch.pl +10 -0
@@ -3035,6 +3035,16 @@ sub process { } } +# Check for invalid patch separator + if ($in_commit_log && + $line =~ /^---.+/) { + if (ERROR("BAD_COMMIT_SEPARATOR", + "Invalid commit separator - some tools may have problems applying this\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/-/=/g; + } + } + # Check for patch separator if ($line =~ /^---$/) { $has_patch_separator = 1;
Re: [PATCH] checkpatch: Add an invalid patch separator test
Quoted 6 lines · On Fri, 16 Jan 2026 09:42:52 -0800 Joe Perches <[email protected]> wrote:
Some versions of tools that apply patches incorrectly allow lines that start with 3 dashes and have additional content on the same line.
Checkpatch will now emit an ERROR on these lines and optionally convert those lines from dashes to equals with --fix.
lgtm, thanks. I think Suggested-by:Ian is appropriate.