Skip to content

Commit cc135b2

Browse files
pekkarrintel-lab-lkp
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]>
1 parent a3b2347 commit cc135b2

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)