Skip to content

Commit 15ecd83

Browse files
pekkarrbrauner
authored andcommitted
rust: file: mark LocalFile as repr(transparent)
Unsafe code in `LocalFile`'s methods assumes that the type has the same layout as the inner `bindings::file`. This is not guaranteed by the default struct representation in Rust, but requires specifying the `transparent` representation. The `File` struct (which also wraps `bindings::file`) is already marked as `repr(transparent)`, so this change makes their layouts equivalent. Fixes: 8518498 ("rust: file: add Rust abstraction for `struct file`") Closes: 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 34ecde3 commit 15ecd83

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

rust/kernel/fs/file.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ unsafe impl AlwaysRefCounted for File {
219219
/// must be on the same thread as this file.
220220
///
221221
/// [`assume_no_fdget_pos`]: LocalFile::assume_no_fdget_pos
222+
#[repr(transparent)]
222223
pub struct LocalFile {
223224
inner: Opaque<bindings::file>,
224225
}

0 commit comments

Comments
 (0)