Skip to content

Suggest device logging when a device is in scope - #19

Open
herdem-herdem wants to merge 1 commit into
Rust-for-Linux:trunkfrom
herdem-herdem:lint/prefer-device-logging
Open

herdem-herdem wants to merge 1 commit into
Rust-for-Linux:trunkfrom
herdem-herdem:lint/prefer-device-logging

Conversation

@herdem-herdem

Copy link
Copy Markdown

Related to #6.

This catches pr_* calls where a shared device reference is available
and suggests the matching dev_* macro. PCI wrappers work through AsRef.

The first version skips owned values, mutable references, struct fields
and logging generated by other macros. It doesn't suggest automatic fixes.

All 20 UI tests pass. Tested against Linux 7.4-rc3 in a Debian VM:
three positive cases trigger the lint, and six negative cases compile
without warnings. The built kernel boots in QEMU.

Both kernel builds had the same three existing objtool warnings.

Suggest dev_* instead of pr_* when a shared device reference is in scope. Handle AsRef wrappers, scopes and shadowing, with UI tests for local and external kernel crates.
Copilot AI balanced review requested due to automatic review settings November 18, 2026 16:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The lint overlooks block-local item/import shadowing and inline const capture boundaries, causing it to suggest device bindings that would make replacements fail to compile.

2 open issues
What changed in this PR

Adds the advisory klint::prefer_device_logging lint for issue #6. It recommends device-specific logging when a kernel pr_* call has a shared device reference in scope.

Changes:

  • Registers the lint and recognizes device wrappers through AsRef.
  • Adds UI coverage for scope handling, macro aliases, suppression, and excluded cases.
  • Documents supported patterns and limitations; no automatic fixes are offered.
File Description
tests/​ui/​prefer_device_logging.stderr Expected diagnostics for the main UI cases.
tests/​ui/​prefer_device_logging.rs Positive and negative lint coverage.
tests/​ui/​prefer_device_logging_local.stderr Expected diagnostic when checking the kernel crate itself.
tests/​ui/​prefer_device_logging_local.rs Tests locally defined kernel types and macros.
tests/​ui/​auxiliary/​kernel.rs Device, wrapper, and logging-macro test fixtures.
src/​main.rs Registers the lint and its late lint pass.
src/​hir_lints/​prefer_device_logging.rs Implements logging detection and device-scope analysis.
src/​hir_lints/​mod.rs Exposes the new lint module.
README.md Links to the device-logging documentation.
doc/​prefer_device_logging.md Explains usage, supported references, and exclusions.

Review effort: Balanced

Comment on lines +120 to +121
if let StmtKind::Let(local) = stmt.kind {
add_bindings(local.pat, &mut bindings);
add_bindings(param.pat, &mut bindings);
}
}
_ => (),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants