diff options
| author | Pekka Ristola <pekkarr@protonmail.com> | 2025-05-27 20:48:55 +0000 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2025-06-19 15:40:25 +0200 |
| commit | aefd954dd83e0f635266e82d2d0f8e257600f230 (patch) | |
| tree | afc684b1a724250c7700ff909408e54e2fc01c5b /rust | |
| parent | 61009dd2252ab4391d44a240e891f1e04c00b9ca (diff) | |
| download | linux-aefd954dd83e0f635266e82d2d0f8e257600f230.tar.gz linux-aefd954dd83e0f635266e82d2d0f8e257600f230.tar.bz2 linux-aefd954dd83e0f635266e82d2d0f8e257600f230.zip | |
rust: file: mark `LocalFile` as `repr(transparent)`
[ Upstream commit 15ecd83dc06277385ad71dc7ea26911d9a79acaf ]
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: 851849824bb5 ("rust: file: add Rust abstraction for `struct file`")
Closes: https://github.com/Rust-for-Linux/linux/issues/1165
Signed-off-by: Pekka Ristola <pekkarr@protonmail.com>
Link: https://lore.kernel.org/20250527204636.12573-1-pekkarr@protonmail.com
Reviewed-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/kernel/fs/file.rs | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/rust/kernel/fs/file.rs b/rust/kernel/fs/file.rs index 13a0e44cd1aa..138693bdeb3f 100644 --- a/rust/kernel/fs/file.rs +++ b/rust/kernel/fs/file.rs @@ -219,6 +219,7 @@ unsafe impl AlwaysRefCounted for File { /// must be on the same thread as this file. /// /// [`assume_no_fdget_pos`]: LocalFile::assume_no_fdget_pos +#[repr(transparent)] pub struct LocalFile { inner: Opaque<bindings::file>, } |
