Skip to content

Fix various clippy warnings in the code base - #95

Open
bchalios wants to merge 7 commits into
mainfrom
fix/clippy-warnings
Open

bchalios wants to merge 7 commits into
mainfrom
fix/clippy-warnings

Conversation

@bchalios

@bchalios bchalios commented Oct 18, 2026 •

Copy link
Copy Markdown

Fixes all cargo clippy --all-targets warnings, so CI can later run clippy with -D warnings.

  • Implement Default for UffdBuilder (new_without_default). It's written by hand rather than derived, because #[derive(Default)]would setuser_mode_onlytofalseinstead oftrue. A new unit test checks the defaults of UffdBuilder::new(). FeatureFlagsandIoctlFlagsalso deriveDefault`.
  • Add # Safety sections to Uffd::copy and Uffd::zeropage: they write into the caller's address space, so the caller must make sure it is safe for the contents of the destination range to change.
  • Use c_int::MAX instead of the deprecated libc::INT_MAX.
  • Small style fixes: match Err(Errno::EAGAIN) directly instead of using a guard, pass Event::from_uffd_msg to .map() without a closure, use assert! instead of assert_eq! with a literal bool, and drop a needless borrow in the manpage test.

No behavior change. The only API additions are the Default impls.

This also adds a CI job for testing style (rustfmt and clippy for every PR)

Fix a new without default warning in `UffdBuilder` new() implementation.
Implement `Default` for `UffdBuilder` by hand and make
`UffdBuilder::new()` return `UffdBuilder::default()`.

`#[derive(Default)]` can't be used here: it would set `user_mode_only`
to `false`, while `new()` has always defaulted it to `true`. Add a unit
test that checks the defaults of `UffdBuilder::new()`.

Also derive `Default` for `FeatureFlags` and `IoctlFlags`; the default
value is the empty set of flags.

Signed-off-by: Babis Chalios <mail@bchalios.io>
`Uffd::copy` and `Uffd::zeropage` write to a memory range of the calling
process behind Rust's back. Document that the caller must ensure it is
sound for the contents of that range to change, e.g. that no Rust
references to it are live.

The other requirements on the arguments (page alignment, the range being
registered with the Uffd object, `src` being readable) are checked by
the kernel, which returns an error if they don't hold, so they are not
safety requirements.

Signed-off-by: Babis Chalios <mail@bchalios.io>
Apply pattern match directly on the Errno variant (Errno::EAGAIN)
instead of using a guard.

Signed-off-by: Babis Chalios <mail@bchalios.io>
Drop the closure and pass the associated function itself, directly.

Signed-off-by: Babis Chalios <mail@bchalios.io>
Use c_int::MAX instead.

Signed-off-by: Babis Chalios <mail@bchalios.io>
Use `assert!` instead of `assert_eq!` with a literal bool, and drop a
needless borrow of the arguments passed to `Command::args()`.

Signed-off-by: Babis Chalios <mail@bchalios.io>
@bchalios bchalios self-assigned this Oct 18, 2026
@bchalios
bchalios requested a review from alsrdn October 18, 2026 15:02
Check formatting with `cargo fmt --check` and run clippy on all targets
for every kernel feature level, failing on any warning. This keeps the
codebase warning-free now that the existing clippy warnings are fixed.

Signed-off-by: Babis Chalios <mail@bchalios.io>
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.

1 participant