Skip to content

Commit 6f8e0a0

Browse files
Valentin Obstojeda
authored andcommitted
rust: kernel: add doclinks
Add doclinks to existing documentation. Signed-off-by: Valentin Obst <kernel@valentinobst.de> Reviewed-by: Trevor Gross <tmgross@umich.edu> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20240131-doc-fixes-v3-v3-10-0c8af94ed7de@valentinobst.de Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 915168d commit 6f8e0a0

File tree

3 files changed

+40
-24
lines changed

3 files changed

+40
-24
lines changed

rust/kernel/sync/arc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,12 @@ impl<T: ?Sized> From<Pin<UniqueArc<T>>> for Arc<T> {
365365
/// A borrowed reference to an [`Arc`] instance.
366366
///
367367
/// For cases when one doesn't ever need to increment the refcount on the allocation, it is simpler
368-
/// to use just `&T`, which we can trivially get from an `Arc<T>` instance.
368+
/// to use just `&T`, which we can trivially get from an [`Arc<T>`] instance.
369369
///
370370
/// However, when one may need to increment the refcount, it is preferable to use an `ArcBorrow<T>`
371371
/// over `&Arc<T>` because the latter results in a double-indirection: a pointer (shared reference)
372-
/// to a pointer (`Arc<T>`) to the object (`T`). An [`ArcBorrow`] eliminates this double
373-
/// indirection while still allowing one to increment the refcount and getting an `Arc<T>` when/if
372+
/// to a pointer ([`Arc<T>`]) to the object (`T`). An [`ArcBorrow`] eliminates this double
373+
/// indirection while still allowing one to increment the refcount and getting an [`Arc<T>`] when/if
374374
/// needed.
375375
///
376376
/// # Invariants

rust/kernel/sync/lock.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,21 @@ pub mod spinlock;
2121
/// # Safety
2222
///
2323
/// - Implementers must ensure that only one thread/CPU may access the protected data once the lock
24-
/// is owned, that is, between calls to `lock` and `unlock`.
25-
/// - Implementers must also ensure that `relock` uses the same locking method as the original
24+
/// is owned, that is, between calls to [`lock`] and [`unlock`].
25+
/// - Implementers must also ensure that [`relock`] uses the same locking method as the original
2626
/// lock operation.
27+
///
28+
/// [`lock`]: Backend::lock
29+
/// [`unlock`]: Backend::unlock
30+
/// [`relock`]: Backend::relock
2731
pub unsafe trait Backend {
2832
/// The state required by the lock.
2933
type State;
3034

31-
/// The state required to be kept between `lock` and `unlock`.
35+
/// The state required to be kept between [`lock`] and [`unlock`].
36+
///
37+
/// [`lock`]: Backend::lock
38+
/// [`unlock`]: Backend::unlock
3239
type GuardState;
3340

3441
/// Initialises the lock.

rust/kernel/workqueue.rs

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
//!
1313
//! # The raw API
1414
//!
15-
//! The raw API consists of the `RawWorkItem` trait, where the work item needs to provide an
15+
//! The raw API consists of the [`RawWorkItem`] trait, where the work item needs to provide an
1616
//! arbitrary function that knows how to enqueue the work item. It should usually not be used
1717
//! directly, but if you want to, you can use it without using the pieces from the safe API.
1818
//!
1919
//! # The safe API
2020
//!
21-
//! The safe API is used via the `Work` struct and `WorkItem` traits. Furthermore, it also includes
22-
//! a trait called `WorkItemPointer`, which is usually not used directly by the user.
21+
//! The safe API is used via the [`Work`] struct and [`WorkItem`] traits. Furthermore, it also
22+
//! includes a trait called [`WorkItemPointer`], which is usually not used directly by the user.
2323
//!
24-
//! * The `Work` struct is the Rust wrapper for the C `work_struct` type.
25-
//! * The `WorkItem` trait is implemented for structs that can be enqueued to a workqueue.
26-
//! * The `WorkItemPointer` trait is implemented for the pointer type that points at a something
27-
//! that implements `WorkItem`.
24+
//! * The [`Work`] struct is the Rust wrapper for the C `work_struct` type.
25+
//! * The [`WorkItem`] trait is implemented for structs that can be enqueued to a workqueue.
26+
//! * The [`WorkItemPointer`] trait is implemented for the pointer type that points at a something
27+
//! that implements [`WorkItem`].
2828
//!
2929
//! ## Example
3030
//!
@@ -218,7 +218,9 @@ impl Queue {
218218
}
219219
}
220220

221-
/// A helper type used in `try_spawn`.
221+
/// A helper type used in [`try_spawn`].
222+
///
223+
/// [`try_spawn`]: Queue::try_spawn
222224
#[pin_data]
223225
struct ClosureWork<T> {
224226
#[pin]
@@ -258,9 +260,11 @@ impl<T: FnOnce()> WorkItem for ClosureWork<T> {
258260
///
259261
/// # Safety
260262
///
261-
/// Implementers must ensure that any pointers passed to a `queue_work_on` closure by `__enqueue`
263+
/// Implementers must ensure that any pointers passed to a `queue_work_on` closure by [`__enqueue`]
262264
/// remain valid for the duration specified in the guarantees section of the documentation for
263-
/// `__enqueue`.
265+
/// [`__enqueue`].
266+
///
267+
/// [`__enqueue`]: RawWorkItem::__enqueue
264268
pub unsafe trait RawWorkItem<const ID: u64> {
265269
/// The return type of [`Queue::enqueue`].
266270
type EnqueueOutput;
@@ -290,10 +294,11 @@ pub unsafe trait RawWorkItem<const ID: u64> {
290294

291295
/// Defines the method that should be called directly when a work item is executed.
292296
///
293-
/// This trait is implemented by `Pin<Box<T>>` and `Arc<T>`, and is mainly intended to be
297+
/// This trait is implemented by `Pin<Box<T>>` and [`Arc<T>`], and is mainly intended to be
294298
/// implemented for smart pointer types. For your own structs, you would implement [`WorkItem`]
295-
/// instead. The `run` method on this trait will usually just perform the appropriate
296-
/// `container_of` translation and then call into the `run` method from the [`WorkItem`] trait.
299+
/// instead. The [`run`] method on this trait will usually just perform the appropriate
300+
/// `container_of` translation and then call into the [`run`][WorkItem::run] method from the
301+
/// [`WorkItem`] trait.
297302
///
298303
/// This trait is used when the `work_struct` field is defined using the [`Work`] helper.
299304
///
@@ -309,8 +314,10 @@ pub unsafe trait WorkItemPointer<const ID: u64>: RawWorkItem<ID> {
309314
///
310315
/// # Safety
311316
///
312-
/// The provided `work_struct` pointer must originate from a previous call to `__enqueue` where
313-
/// the `queue_work_on` closure returned true, and the pointer must still be valid.
317+
/// The provided `work_struct` pointer must originate from a previous call to [`__enqueue`]
318+
/// where the `queue_work_on` closure returned true, and the pointer must still be valid.
319+
///
320+
/// [`__enqueue`]: RawWorkItem::__enqueue
314321
unsafe extern "C" fn run(ptr: *mut bindings::work_struct);
315322
}
316323

@@ -328,12 +335,14 @@ pub trait WorkItem<const ID: u64 = 0> {
328335

329336
/// Links for a work item.
330337
///
331-
/// This struct contains a function pointer to the `run` function from the [`WorkItemPointer`]
338+
/// This struct contains a function pointer to the [`run`] function from the [`WorkItemPointer`]
332339
/// trait, and defines the linked list pointers necessary to enqueue a work item in a workqueue.
333340
///
334341
/// Wraps the kernel's C `struct work_struct`.
335342
///
336343
/// This is a helper type used to associate a `work_struct` with the [`WorkItem`] that uses it.
344+
///
345+
/// [`run`]: WorkItemPointer::run
337346
#[repr(transparent)]
338347
pub struct Work<T: ?Sized, const ID: u64 = 0> {
339348
work: Opaque<bindings::work_struct>,
@@ -409,7 +418,7 @@ impl<T: ?Sized, const ID: u64> Work<T, ID> {
409418
/// }
410419
/// ```
411420
///
412-
/// Note that since the `Work` type is annotated with an id, you can have several `work_struct`
421+
/// Note that since the [`Work`] type is annotated with an id, you can have several `work_struct`
413422
/// fields by using a different id for each one.
414423
///
415424
/// # Safety
@@ -429,7 +438,7 @@ pub unsafe trait HasWork<T, const ID: u64 = 0> {
429438
/// Returns the offset of the [`Work<T, ID>`] field.
430439
///
431440
/// This method exists because the [`OFFSET`] constant cannot be accessed if the type is not
432-
/// `Sized`.
441+
/// [`Sized`].
433442
///
434443
/// [`Work<T, ID>`]: Work
435444
/// [`OFFSET`]: HasWork::OFFSET

0 commit comments

Comments
 (0)