]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
rust: map `long` to `isize` and `char` to `u8`
authorGary Guo <gary@garyguo.net>
Sun, 9 Mar 2025 20:42:17 +0000 (21:42 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 12:02:13 +0000 (13:02 +0100)
commitf3accd04370837c2dd1ab00c12b1572b66638d67
tree8ef4e8d2d6ed70d9f676bcf34edf0ed7e3e8c598
parent31cdae8094e1395c113fb6d77c1b1d2d71d086be
rust: map `long` to `isize` and `char` to `u8`

commit 1bae8729e50a900f41e9a1c17ae81113e4cf62b8 upstream.

The following FFI types are replaced compared to `core::ffi`:

1. `char` type is now always mapped to `u8`, since kernel uses
   `-funsigned-char` on the C code. `core::ffi` maps it to platform
   default ABI, which can be either signed or unsigned.

2. `long` is now always mapped to `isize`. It's very common in the
   kernel to use `long` to represent a pointer-sized integer, and in
   fact `intptr_t` is a typedef of `long` in the kernel. Enforce this
   mapping rather than mapping to `i32/i64` depending on platform can
   save us a lot of unnecessary casts.

Signed-off-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240913213041.395655-5-gary@garyguo.net
[ Moved `uaccess` changes from the next commit, since they were
  irrefutable patterns that Rust >= 1.82.0 warns about. Reworded
  slightly and reformatted a few documentation comments. Rebased on
  top of `rust-next`. Added the removal of two casts to avoid Clippy
  warnings. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
rust/ffi.rs
rust/kernel/error.rs
rust/kernel/firmware.rs
rust/kernel/uaccess.rs