Skip to content

Commit 946026b

Browse files
pekkarrbrauner
authored andcommitted
rust: file: improve safety comments
Some of the safety comments in `LocalFile`'s methods incorrectly refer to the `File` type instead of `LocalFile`, so fix them to use the correct type. Also add missing Markdown code spans around lifetimes in the safety comments, i.e. change 'a to `'a`. Link: Rust-for-Linux#1165 Signed-off-by: Pekka Ristola <[email protected]> Link: https://lore.kernel.org/[email protected] Reviewed-by: Benno Lossin <[email protected]> Reviewed-by: Alice Ryhl <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent 15ecd83 commit 946026b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

rust/kernel/fs/file.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub struct LocalFile {
225225
}
226226

227227
// SAFETY: The type invariants guarantee that `LocalFile` is always ref-counted. This implementation
228-
// makes `ARef<File>` own a normal refcount.
228+
// makes `ARef<LocalFile>` own a normal refcount.
229229
unsafe impl AlwaysRefCounted for LocalFile {
230230
#[inline]
231231
fn inc_ref(&self) {
@@ -236,7 +236,8 @@ unsafe impl AlwaysRefCounted for LocalFile {
236236
#[inline]
237237
unsafe fn dec_ref(obj: ptr::NonNull<LocalFile>) {
238238
// SAFETY: To call this method, the caller passes us ownership of a normal refcount, so we
239-
// may drop it. The cast is okay since `File` has the same representation as `struct file`.
239+
// may drop it. The cast is okay since `LocalFile` has the same representation as
240+
// `struct file`.
240241
unsafe { bindings::fput(obj.cast().as_ptr()) }
241242
}
242243
}
@@ -274,7 +275,7 @@ impl LocalFile {
274275
#[inline]
275276
pub unsafe fn from_raw_file<'a>(ptr: *const bindings::file) -> &'a LocalFile {
276277
// SAFETY: The caller guarantees that the pointer is not dangling and stays valid for the
277-
// duration of 'a. The cast is okay because `File` is `repr(transparent)`.
278+
// duration of `'a`. The cast is okay because `LocalFile` is `repr(transparent)`.
278279
//
279280
// INVARIANT: The caller guarantees that there are no problematic `fdget_pos` calls.
280281
unsafe { &*ptr.cast() }
@@ -348,7 +349,7 @@ impl File {
348349
#[inline]
349350
pub unsafe fn from_raw_file<'a>(ptr: *const bindings::file) -> &'a File {
350351
// SAFETY: The caller guarantees that the pointer is not dangling and stays valid for the
351-
// duration of 'a. The cast is okay because `File` is `repr(transparent)`.
352+
// duration of `'a`. The cast is okay because `File` is `repr(transparent)`.
352353
//
353354
// INVARIANT: The caller guarantees that there are no problematic `fdget_pos` calls.
354355
unsafe { &*ptr.cast() }

0 commit comments

Comments
 (0)