Skip to content

Commit bbe98f4

Browse files
dakrgregkh
authored andcommitted
firmware: rust: improve safety comments
Improve the wording of safety comments to be more explicit about what exactly is guaranteed to be valid. Suggested-by: Benno Lossin <[email protected]> Signed-off-by: Danilo Krummrich <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 269e974 commit bbe98f4

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

rust/kernel/firmware.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ type FwFunc =
2222
///
2323
/// The pointer is valid, and has ownership over the instance of `struct firmware`.
2424
///
25-
/// Once requested, the `Firmware` backing buffer is not modified until it is freed when `Firmware`
26-
/// is dropped.
25+
/// The `Firmware`'s backing buffer is not modified.
2726
///
2827
/// # Examples
2928
///
@@ -72,22 +71,22 @@ impl Firmware {
7271

7372
/// Returns the size of the requested firmware in bytes.
7473
pub fn size(&self) -> usize {
75-
// SAFETY: Safe by the type invariant.
74+
// SAFETY: `self.as_raw()` is valid by the type invariant.
7675
unsafe { (*self.as_raw()).size }
7776
}
7877

7978
/// Returns the requested firmware as `&[u8]`.
8079
pub fn data(&self) -> &[u8] {
81-
// SAFETY: Safe by the type invariant. Additionally, `bindings::firmware` guarantees, if
82-
// successfully requested, that `bindings::firmware::data` has a size of
83-
// `bindings::firmware::size` bytes.
80+
// SAFETY: `self.as_raw()` is valid by the type invariant. Additionally,
81+
// `bindings::firmware` guarantees, if successfully requested, that
82+
// `bindings::firmware::data` has a size of `bindings::firmware::size` bytes.
8483
unsafe { core::slice::from_raw_parts((*self.as_raw()).data, self.size()) }
8584
}
8685
}
8786

8887
impl Drop for Firmware {
8988
fn drop(&mut self) {
90-
// SAFETY: Safe by the type invariant.
89+
// SAFETY: `self.as_raw()` is valid by the type invariant.
9190
unsafe { bindings::release_firmware(self.as_raw()) };
9291
}
9392
}

0 commit comments

Comments
 (0)