mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-01 10:45:49 +00:00
db4f72c904
Checking that we are not missing any `// SAFETY` comments in our `unsafe` blocks is something we have wanted to do for a long time, as well as cleaning up the remaining cases that were not documented [1]. Back when Rust for Linux started, this was something that could have been done via a script, like Rust's `tidy`. Soon after, in Rust 1.58.0, Clippy implemented the `undocumented_unsafe_blocks` lint [2]. Even though the lint has a few false positives, e.g. in some cases where attributes appear between the comment and the `unsafe` block [3], there are workarounds and the lint seems quite usable already. Thus enable the lint now. We still have a few cases to clean up, so just allow those for the moment by writing a `TODO` comment -- some of those may be good candidates for new contributors. Link: https://github.com/Rust-for-Linux/linux/issues/351 [1] Link: https://rust-lang.github.io/rust-clippy/master/#/undocumented_unsafe_blocks [2] Link: https://github.com/rust-lang/rust-clippy/issues/13189 [3] Reviewed-by: Alice Ryhl <aliceryhl@google.com> Reviewed-by: Trevor Gross <tmgross@umich.edu> Tested-by: Gary Guo <gary@garyguo.net> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://lore.kernel.org/r/20240904204347.168520-5-ojeda@kernel.org Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
53 lines
1.5 KiB
Rust
53 lines
1.5 KiB
Rust
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
//! Bindings.
|
|
//!
|
|
//! Imports the generated bindings by `bindgen`.
|
|
//!
|
|
//! This crate may not be directly used. If you need a kernel C API that is
|
|
//! not ported or wrapped in the `kernel` crate, then do so first instead of
|
|
//! using this crate.
|
|
|
|
#![no_std]
|
|
// See <https://github.com/rust-lang/rust-bindgen/issues/1651>.
|
|
#![cfg_attr(test, allow(deref_nullptr))]
|
|
#![cfg_attr(test, allow(unaligned_references))]
|
|
#![cfg_attr(test, allow(unsafe_op_in_unsafe_fn))]
|
|
#![allow(
|
|
clippy::all,
|
|
missing_docs,
|
|
non_camel_case_types,
|
|
non_upper_case_globals,
|
|
non_snake_case,
|
|
improper_ctypes,
|
|
unreachable_pub,
|
|
unsafe_op_in_unsafe_fn
|
|
)]
|
|
|
|
#[allow(dead_code)]
|
|
#[allow(clippy::undocumented_unsafe_blocks)]
|
|
mod bindings_raw {
|
|
// Use glob import here to expose all helpers.
|
|
// Symbols defined within the module will take precedence to the glob import.
|
|
pub use super::bindings_helper::*;
|
|
include!(concat!(
|
|
env!("OBJTREE"),
|
|
"/rust/bindings/bindings_generated.rs"
|
|
));
|
|
}
|
|
|
|
// When both a directly exposed symbol and a helper exists for the same function,
|
|
// the directly exposed symbol is preferred and the helper becomes dead code, so
|
|
// ignore the warning here.
|
|
#[allow(dead_code)]
|
|
mod bindings_helper {
|
|
// Import the generated bindings for types.
|
|
use super::bindings_raw::*;
|
|
include!(concat!(
|
|
env!("OBJTREE"),
|
|
"/rust/bindings/bindings_helpers_generated.rs"
|
|
));
|
|
}
|
|
|
|
pub use bindings_raw::*;
|