Commit b6cda913 authored by Valentin Obst's avatar Valentin Obst Committed by Miguel Ojeda

rust: kernel: fix multiple typos in documentation

Fixes multiple trivial typos in documentation and comments of the
kernel crate.

allocator:
- Fix a trivial list item alignment issue in the last SAFETY comment of
  `krealloc_aligned`.

init:
- Replace 'type' with 'trait' in the doc comments of the `PinInit` and
  `Init` traits.
- Add colons before starting lists.
- Add spaces between the type and equal sign to respect the code
  formatting rules in example code.
- End a sentence with a full stop instead of a colon.

ioctl:
- Replace 'an' with 'a' where appropriate.

str:
- Replace 'Return' with 'Returns' in the doc comment of `bytes_written`
  as the text describes what the function does.

sync/lock:
- Fix a trivial list item alignment issue in the Safety section of the
  `Backend` trait's description.

sync/lock/spinlock:
- The code in this module operates on spinlocks, not mutexes. Thus,
  replace 'mutex' with 'spinlock' in the SAFETY comment of `unlock`.

workqueue:
- Replace "wont" with "won't" in the doc comment of `__enqueue`.
Signed-off-by: default avatarValentin Obst <kernel@valentinobst.de>
Reviewed-by: default avatarTrevor Gross <tmgross@umich.edu>
Reviewed-by: default avatarMartin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: default avatarAlice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240131-doc-fixes-v3-v3-1-0c8af94ed7de@valentinobst.deSigned-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
parent 789809a3
...@@ -35,7 +35,7 @@ unsafe fn krealloc_aligned(ptr: *mut u8, new_layout: Layout, flags: bindings::gf ...@@ -35,7 +35,7 @@ unsafe fn krealloc_aligned(ptr: *mut u8, new_layout: Layout, flags: bindings::gf
// - `ptr` is either null or a pointer returned from a previous `k{re}alloc()` by the // - `ptr` is either null or a pointer returned from a previous `k{re}alloc()` by the
// function safety requirement. // function safety requirement.
// - `size` is greater than 0 since it's either a `layout.size()` (which cannot be zero // - `size` is greater than 0 since it's either a `layout.size()` (which cannot be zero
// according to the function safety requirement) or a result from `next_power_of_two()`. // according to the function safety requirement) or a result from `next_power_of_two()`.
unsafe { bindings::krealloc(ptr as *const core::ffi::c_void, size, flags) as *mut u8 } unsafe { bindings::krealloc(ptr as *const core::ffi::c_void, size, flags) as *mut u8 }
} }
......
...@@ -751,10 +751,10 @@ macro_rules! try_init { ...@@ -751,10 +751,10 @@ macro_rules! try_init {
/// ///
/// # Safety /// # Safety
/// ///
/// When implementing this type you will need to take great care. Also there are probably very few /// When implementing this trait you will need to take great care. Also there are probably very few
/// cases where a manual implementation is necessary. Use [`pin_init_from_closure`] where possible. /// cases where a manual implementation is necessary. Use [`pin_init_from_closure`] where possible.
/// ///
/// The [`PinInit::__pinned_init`] function /// The [`PinInit::__pinned_init`] function:
/// - returns `Ok(())` if it initialized every field of `slot`, /// - returns `Ok(())` if it initialized every field of `slot`,
/// - returns `Err(err)` if it encountered an error and then cleaned `slot`, this means: /// - returns `Err(err)` if it encountered an error and then cleaned `slot`, this means:
/// - `slot` can be deallocated without UB occurring, /// - `slot` can be deallocated without UB occurring,
...@@ -861,10 +861,10 @@ unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { ...@@ -861,10 +861,10 @@ unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> {
/// ///
/// # Safety /// # Safety
/// ///
/// When implementing this type you will need to take great care. Also there are probably very few /// When implementing this trait you will need to take great care. Also there are probably very few
/// cases where a manual implementation is necessary. Use [`init_from_closure`] where possible. /// cases where a manual implementation is necessary. Use [`init_from_closure`] where possible.
/// ///
/// The [`Init::__init`] function /// The [`Init::__init`] function:
/// - returns `Ok(())` if it initialized every field of `slot`, /// - returns `Ok(())` if it initialized every field of `slot`,
/// - returns `Err(err)` if it encountered an error and then cleaned `slot`, this means: /// - returns `Err(err)` if it encountered an error and then cleaned `slot`, this means:
/// - `slot` can be deallocated without UB occurring, /// - `slot` can be deallocated without UB occurring,
...@@ -1013,7 +1013,7 @@ pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> { ...@@ -1013,7 +1013,7 @@ pub fn uninit<T, E>() -> impl Init<MaybeUninit<T>, E> {
/// ///
/// ```rust /// ```rust
/// use kernel::{error::Error, init::init_array_from_fn}; /// use kernel::{error::Error, init::init_array_from_fn};
/// let array: Box<[usize; 1_000]>= Box::init::<Error>(init_array_from_fn(|i| i)).unwrap(); /// let array: Box<[usize; 1_000]> = Box::init::<Error>(init_array_from_fn(|i| i)).unwrap();
/// assert_eq!(array.len(), 1_000); /// assert_eq!(array.len(), 1_000);
/// ``` /// ```
pub fn init_array_from_fn<I, const N: usize, T, E>( pub fn init_array_from_fn<I, const N: usize, T, E>(
...@@ -1027,7 +1027,7 @@ pub fn init_array_from_fn<I, const N: usize, T, E>( ...@@ -1027,7 +1027,7 @@ pub fn init_array_from_fn<I, const N: usize, T, E>(
// Counts the number of initialized elements and when dropped drops that many elements from // Counts the number of initialized elements and when dropped drops that many elements from
// `slot`. // `slot`.
let mut init_count = ScopeGuard::new_with_data(0, |i| { let mut init_count = ScopeGuard::new_with_data(0, |i| {
// We now free every element that has been initialized before: // We now free every element that has been initialized before.
// SAFETY: The loop initialized exactly the values from 0..i and since we // SAFETY: The loop initialized exactly the values from 0..i and since we
// return `Err` below, the caller will consider the memory at `slot` as // return `Err` below, the caller will consider the memory at `slot` as
// uninitialized. // uninitialized.
...@@ -1056,7 +1056,7 @@ pub fn init_array_from_fn<I, const N: usize, T, E>( ...@@ -1056,7 +1056,7 @@ pub fn init_array_from_fn<I, const N: usize, T, E>(
/// ///
/// ```rust /// ```rust
/// use kernel::{sync::{Arc, Mutex}, init::pin_init_array_from_fn, new_mutex}; /// use kernel::{sync::{Arc, Mutex}, init::pin_init_array_from_fn, new_mutex};
/// let array: Arc<[Mutex<usize>; 1_000]>= /// let array: Arc<[Mutex<usize>; 1_000]> =
/// Arc::pin_init(pin_init_array_from_fn(|i| new_mutex!(i))).unwrap(); /// Arc::pin_init(pin_init_array_from_fn(|i| new_mutex!(i))).unwrap();
/// assert_eq!(array.len(), 1_000); /// assert_eq!(array.len(), 1_000);
/// ``` /// ```
...@@ -1071,7 +1071,7 @@ pub fn pin_init_array_from_fn<I, const N: usize, T, E>( ...@@ -1071,7 +1071,7 @@ pub fn pin_init_array_from_fn<I, const N: usize, T, E>(
// Counts the number of initialized elements and when dropped drops that many elements from // Counts the number of initialized elements and when dropped drops that many elements from
// `slot`. // `slot`.
let mut init_count = ScopeGuard::new_with_data(0, |i| { let mut init_count = ScopeGuard::new_with_data(0, |i| {
// We now free every element that has been initialized before: // We now free every element that has been initialized before.
// SAFETY: The loop initialized exactly the values from 0..i and since we // SAFETY: The loop initialized exactly the values from 0..i and since we
// return `Err` below, the caller will consider the memory at `slot` as // return `Err` below, the caller will consider the memory at `slot` as
// uninitialized. // uninitialized.
......
...@@ -28,13 +28,13 @@ pub const fn _IO(ty: u32, nr: u32) -> u32 { ...@@ -28,13 +28,13 @@ pub const fn _IO(ty: u32, nr: u32) -> u32 {
_IOC(uapi::_IOC_NONE, ty, nr, 0) _IOC(uapi::_IOC_NONE, ty, nr, 0)
} }
/// Build an ioctl number for an read-only ioctl. /// Build an ioctl number for a read-only ioctl.
#[inline(always)] #[inline(always)]
pub const fn _IOR<T>(ty: u32, nr: u32) -> u32 { pub const fn _IOR<T>(ty: u32, nr: u32) -> u32 {
_IOC(uapi::_IOC_READ, ty, nr, core::mem::size_of::<T>()) _IOC(uapi::_IOC_READ, ty, nr, core::mem::size_of::<T>())
} }
/// Build an ioctl number for an write-only ioctl. /// Build an ioctl number for a write-only ioctl.
#[inline(always)] #[inline(always)]
pub const fn _IOW<T>(ty: u32, nr: u32) -> u32 { pub const fn _IOW<T>(ty: u32, nr: u32) -> u32 {
_IOC(uapi::_IOC_WRITE, ty, nr, core::mem::size_of::<T>()) _IOC(uapi::_IOC_WRITE, ty, nr, core::mem::size_of::<T>())
......
...@@ -449,7 +449,7 @@ pub(crate) fn pos(&self) -> *mut u8 { ...@@ -449,7 +449,7 @@ pub(crate) fn pos(&self) -> *mut u8 {
self.pos as _ self.pos as _
} }
/// Return the number of bytes written to the formatter. /// Returns the number of bytes written to the formatter.
pub(crate) fn bytes_written(&self) -> usize { pub(crate) fn bytes_written(&self) -> usize {
self.pos - self.beg self.pos - self.beg
} }
......
...@@ -21,9 +21,9 @@ ...@@ -21,9 +21,9 @@
/// # Safety /// # Safety
/// ///
/// - Implementers must ensure that only one thread/CPU may access the protected data once the lock /// - Implementers must ensure that only one thread/CPU may access the protected data once the lock
/// is owned, that is, between calls to `lock` and `unlock`. /// is owned, that is, between calls to `lock` and `unlock`.
/// - Implementers must also ensure that `relock` uses the same locking method as the original /// - Implementers must also ensure that `relock` uses the same locking method as the original
/// lock operation. /// lock operation.
pub unsafe trait Backend { pub unsafe trait Backend {
/// The state required by the lock. /// The state required by the lock.
type State; type State;
......
...@@ -112,7 +112,7 @@ unsafe fn lock(ptr: *mut Self::State) -> Self::GuardState { ...@@ -112,7 +112,7 @@ unsafe fn lock(ptr: *mut Self::State) -> Self::GuardState {
unsafe fn unlock(ptr: *mut Self::State, _guard_state: &Self::GuardState) { unsafe fn unlock(ptr: *mut Self::State, _guard_state: &Self::GuardState) {
// SAFETY: The safety requirements of this function ensure that `ptr` is valid and that the // SAFETY: The safety requirements of this function ensure that `ptr` is valid and that the
// caller is the owner of the mutex. // caller is the owner of the spinlock.
unsafe { bindings::spin_unlock(ptr) } unsafe { bindings::spin_unlock(ptr) }
} }
} }
...@@ -253,7 +253,7 @@ fn run(mut this: Pin<Box<Self>>) { ...@@ -253,7 +253,7 @@ fn run(mut this: Pin<Box<Self>>) {
/// actual value of the id is not important as long as you use different ids for different fields /// actual value of the id is not important as long as you use different ids for different fields
/// of the same struct. (Fields of different structs need not use different ids.) /// of the same struct. (Fields of different structs need not use different ids.)
/// ///
/// Note that the id is used only to select the right method to call during compilation. It wont be /// Note that the id is used only to select the right method to call during compilation. It won't be
/// part of the final executable. /// part of the final executable.
/// ///
/// # Safety /// # Safety
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment