Repository navigation
Suggest device logging when a device is in scope - #19
Open
herdem-herdem wants to merge 1 commit into
Open
herdem-herdem wants to merge 1 commit into
herdem-herdem wants to merge 1 commit into
Conversation
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.
There was a problem hiding this comment.
🟡 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); | ||
| } | ||
| } | ||
| _ => (), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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.