Skip to content

tools/kernel-pr-check: a checkpatch that can't run fails the check instead of passing it - #288

Merged
derekross merged 5 commits into
derekross:mainfrom
only21mil:build/c052-checkpatch-failure
Nov 3, 2026
Merged

derekross merged 5 commits into
derekross:mainfrom
only21mil:build/c052-checkpatch-failure

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

What and why

If checkpatch couldn't run, tools/kernel-pr-check reported "checkpatch --strict: no errors". It threw away checkpatch's stderr and never read its exit status, so only : ERROR: lines could fail the check. A checker missing from the merge base, one that didn't compile, or one that died or was killed produced an empty report, and that empty report passed. Example: the real checkpatch dies with "--root does not point at a valid tree" (exit 2) when the tree it checks against isn't a kernel tree.

The check now reads checkpatch's exit status as checkpatch sets it: 0 when it reports nothing, 1 when it reports something. Anything else, or a 1 with no diagnostic in the report, fails as "checkpatch --strict didn't run to the end". The failure names the commit and the exit status, and shows what checkpatch said: its stderr and any non-diagnostic stdout line. Clean commits, warnings and errors read as before. --help also prints the header's last line again, which it had been cutting off.

Device and build

  • Phone: none: tools only (tools/kernel-pr-check runs on the laptop and in CI, never on a phone; CONTRIBUTING §6.5)
  • Kernel release (uname -r): n/a
  • Packages changed, with versions: none

Checks (no phone needed)

  • tools/pr-check origin/main passes
  • tests/all passes
  • tests/packages passes: not run, no package touched
  • Each changed package has its version bumped: n/a, no package changed
  • Commits have area prefixes and bodies that say why; any AI help is a Co-Authored-By: or Assisted-by: trailer, never a Signed-off-by:

tests/kernel-pr-check covers each of these:

  • a warning-only commit, which still passes with its warnings listed;
  • a checker that crashes, doesn't compile, exits 1 without reporting anything, or dies on a signal;
  • a merge base that has no checker.

Its stand-in checkpatch now exits as the real one does. Run against the old tool, the new tests fail at the first new case: "a crashing checker: exit 0, expected 1".

I also checked against upstream's own scripts/checkpatch.pl on a stand-in kernel tree, without committing it:

  • clean, warning and error commits give the same results as before;
  • a run where checkpatch dies on --root now fails, where it used to pass as "no errors".

On the phone

  • I ran this on my own phone, booted into this build: not applicable, the tool never runs on a phone
  • What I did not test: a real kernel tree and the --build path (unchanged by this PR)
  • Nothing in this change writes outside slot B and userdata, weakens the storage guard, or reads registers from userspace (AGENTS.md §1)

Found by Opus 5.5 High, Terra 6.1 Max, Kimi K3.1 High and Sol 6.1 xhigh (OPUS-S14-005; TERRA-BUILD_INSTALL-016; KIMI-S02-011; SOL-XHIGH-R2:release_build:SOL61XH-R2-RB-018).

Generated with Claude Opus 5.5 and GPT-6.1 Sol in T3 Code Nightly

checkpatch's stderr went to /dev/null and its exit status was never read:
only ": ERROR:" lines in its report could fail the check. So a checker the
merge base didn't have, one that didn't compile, died (as the real one does
when --root isn't a kernel tree) or was killed printed nothing, and the
empty report passed as "checkpatch --strict: no errors".

Read the status as checkpatch sets it: 0 when it reports nothing, 1 when it
reports something. Anything else, or a 1 with no diagnostic in the report,
fails the check as "didn't run to the end", with the commit, the exit
status and what checkpatch said: its stderr, and any stdout line that isn't
a diagnostic (it prints some of its own failures there, such as a perl too
old). Clean commits, warnings and errors read as before.

tests/kernel-pr-check's stand-in now exits as checkpatch does, and covers a
warning-only commit (still a pass) and a checker that crashes, doesn't
compile, exits 1 with no report, dies on a signal or isn't in the merge
base. --help prints the whole header again: it stopped a line short.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…deletes

The builds delete and rewrite OUT/src, OUT/src-base, OUT/build and
OUT/build-base, but --build was only refused inside the kernel tree. An
OUT one level above a tree named src (-C /x/src --build /x) passed, and
the builds' rm -rf of OUT/src deleted the checkout the tool promises
never to touch. An OUT/src that holds a worktree's git directory went
the same way, and a symlink at OUT/build into the tree had make build in
the tree and the device-tree step delete its arch/arm64/boot/dts.

Resolve every directory the builds delete or rewrite, symlinks included,
and refuse an OUT where one of them is the tree or its git directory,
holds it or lies inside it. The tree's own path is now resolved
physically too, so a symlinked -C is compared by what it points at. An
OUT beside the tree, or holding a tree under another name, still builds.
The guard and the deletes share one list of what is deleted, so a new
delete can't slip past it. The header says where the builds go, and
--help now prints all of it (it stopped a line short before).

tests/kernel-pr-check covers these layouts, and a symlink deeper in
OUT/build, with an rm that records what it is asked to delete under the
fixtures and deletes none of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derekross

Copy link
Copy Markdown
Owner

Thank you. Reading checkpatch's exit status and showing its stderr only on failure is a clear improvement: a checker that never ran shouldn't read as "no errors".

I checked the assumption it rests on against the real scripts/checkpatch.pl from our published branch, on our last 40 commits. Every run exited 0 with no diagnostics or 1 with at least one ERROR/WARNING/CHECK line, so the new failure path can't fire on a normal commit. Real runs do print a Python traceback from spdxcheck.py (no ply) on stderr, and with your change that shows only when the check fails, which is what we want. I also ran the tool from this branch against a real four-commit range: same result as main's. tests/kernel-pr-check passes.

Because linux-omarchy-mobile's CI runs this tool from our main, this change gates every kernel PR from the moment it merges. I'll watch the next kernel CI run after merging.

As I said on #287: the two PRs each add a header line and both set --help to 3,37p. Whichever merges second needs 3,38p, or a range worked out from the file. I'll fix it at merge if you don't get to it first.

@derekross

Copy link
Copy Markdown
Owner

Thanks. #310 changed this tool on main after I reviewed this, so there are two conflicts now:

Your checkpatch changes merged cleanly into main's new if ((checkpatch)) block. On the resolved tree tests/kernel-pr-check passes, 20 checks. tools/publish-kernel runs with --no-checkpatch, so publishing isn't affected. Kernel pull request CI is, as I said before. I'll resolve both conflicts at merge, so no need to rebase.

…tions, --help 3,49p; tests: main's --no-checkpatch and trailer tests before the checker tests)
@derekross
derekross merged commit 95b8f52 into derekross:main Nov 3, 2026
2 checks passed
derekross pushed a commit that referenced this pull request Nov 9, 2026
--help printed a hard-coded line range of the header comment, so every
change to the header had to move the range by hand: #287 and #288 each
added a header line and both set it to '3,37p', and with #310 on main
the merged ranges became '3,46p' and '3,47p'. Whichever change missed
the update cut the header's last line. On #287 the maintainer suggested
working the range out from the file instead.

--help now prints from line 3 to the first line that isn't a comment,
with the awk line tools/nv-backup and tools/phone-provision already use
(without their "# " stripping, so the output keeps its current form).
On today's header its output is byte for byte what '3,49p' printed.

tests/kernel-pr-check gains a check that runs --help on a copy of the
tool with one more header line, and compares it with the header up to
the line before `set -uo pipefail`. It failed with the old range (the
last header line was missing) and passes with this change.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
derekross added a commit that referenced this pull request Nov 9, 2026
Fourteen tools printed --help as a hard-coded line range of their
header comment (sed -n '3,NNp'), the pattern that cut kernel-pr-check's
header after #287, #288 and #310 each edited it. On #287 the maintainer
suggested working the range out from the file; #529 did that for
kernel-pr-check alone. This moves all of them onto one helper,
tools/lib/usage.sh: usage_from_header prints the comment lines from
line 3 up to the first line that isn't a comment (#529's awk line), with
"# " taken off or, with --raw, kept. Tools load it only for --help, so
the copies the tests make of a tool, with only the lib files it needs,
still run. kernel-pr-check moves onto it too.

Ten tools print byte for byte what they printed before (cmp of stdout,
stderr and exit status, and of phone-demo's and phone-mirror's error
usage). Five ranges were already wrong, and print the header now:
fetch-toolchain and build-flame-probe printed two lines of code after
it; install-phone cut --reinstall, --unsigned and its last paragraph,
build-rootfs cut --channel, and release cut its check-bundle stage.
build-packages, phone-demo and release print only the start of a longer
header, so the helper takes a paragraph count (a bare "#" line ends
one) and their output stays what the range meant.

install-phone keeps the awk line inline, as nv-backup and
phone-provision already do: make-bundle ships these three alone,
without tools/lib (review lesson L-497).

tests/tools-help fails if any tool still hard-codes the range, and runs
--help on every tool that prints its header (the helper's users and the
three inline ones): it must print the header, or whole paragraphs from
its start, and no code, and a copy whose header has grown by a line
must print that line too. It replaces #529's single-tool check in
tests/kernel-pr-check. On the base it fails on the range check, and the
per-tool check fails for 13 of the 15 tools.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Derek Ross <derekross@gmail.com>
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…stead of passing it (derekross#288)

checkpatch's stderr went to /dev/null and its exit status was never read:
only ": ERROR:" lines in its report could fail the check. So a checker the
merge base didn't have, one that didn't compile, died (as the real one does
when --root isn't a kernel tree) or was killed printed nothing, and the
empty report passed as "checkpatch --strict: no errors".

Read the status as checkpatch sets it: 0 when it reports nothing, 1 when it
reports something. Anything else, or a 1 with no diagnostic in the report,
fails the check as "didn't run to the end", with the commit, the exit
status and what checkpatch said: its stderr, and any stdout line that isn't
a diagnostic (it prints some of its own failures there, such as a perl too
old). Clean commits, warnings and errors read as before.

tests/kernel-pr-check's stand-in now exits as checkpatch does, and covers a
warning-only commit (still a pass) and a checker that crashes, doesn't
compile, exits 1 with no report, dies on a signal or isn't in the merge
base. --help prints the whole header again: it stopped a line short.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…ross#529)

--help printed a hard-coded line range of the header comment, so every
change to the header had to move the range by hand: derekross#287 and derekross#288 each
added a header line and both set it to '3,37p', and with derekross#310 on main
the merged ranges became '3,46p' and '3,47p'. Whichever change missed
the update cut the header's last line. On derekross#287 the maintainer suggested
working the range out from the file instead.

--help now prints from line 3 to the first line that isn't a comment,
with the awk line tools/nv-backup and tools/phone-provision already use
(without their "# " stripping, so the output keeps its current form).
On today's header its output is byte for byte what '3,49p' printed.

tests/kernel-pr-check gains a check that runs --help on a copy of the
tool with one more header line, and compares it with the header up to
the line before `set -uo pipefail`. It failed with the old range (the
last header line was missing) and passes with this change.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…ekross#559)

Fourteen tools printed --help as a hard-coded line range of their
header comment (sed -n '3,NNp'), the pattern that cut kernel-pr-check's
header after derekross#287, derekross#288 and derekross#310 each edited it. On derekross#287 the maintainer
suggested working the range out from the file; derekross#529 did that for
kernel-pr-check alone. This moves all of them onto one helper,
tools/lib/usage.sh: usage_from_header prints the comment lines from
line 3 up to the first line that isn't a comment (derekross#529's awk line), with
"# " taken off or, with --raw, kept. Tools load it only for --help, so
the copies the tests make of a tool, with only the lib files it needs,
still run. kernel-pr-check moves onto it too.

Ten tools print byte for byte what they printed before (cmp of stdout,
stderr and exit status, and of phone-demo's and phone-mirror's error
usage). Five ranges were already wrong, and print the header now:
fetch-toolchain and build-flame-probe printed two lines of code after
it; install-phone cut --reinstall, --unsigned and its last paragraph,
build-rootfs cut --channel, and release cut its check-bundle stage.
build-packages, phone-demo and release print only the start of a longer
header, so the helper takes a paragraph count (a bare "#" line ends
one) and their output stays what the range meant.

install-phone keeps the awk line inline, as nv-backup and
phone-provision already do: make-bundle ships these three alone,
without tools/lib (review lesson L-497).

tests/tools-help fails if any tool still hard-codes the range, and runs
--help on every tool that prints its header (the helper's users and the
three inline ones): it must print the header, or whole paragraphs from
its start, and no code, and a copy whose header has grown by a line
must print that line too. It replaces derekross#529's single-tool check in
tests/kernel-pr-check. On the base it fails on the range check, and the
per-tool check fails for 13 of the 15 tools.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Derek Ross <derekross@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants