linux/rust/kernel
Christian Schrefl 53bd978016 rust: firmware: Use `ffi::c_char` type in `FwFunc`
The `FwFunc` struct contains an function with a char pointer argument,
for which a `*const u8` pointer was used. This is not really the
"proper" type for this, so use a `*const kernel::ffi::c_char` pointer
instead.

This has no real functionality changes, since now `kernel::ffi::c_char`
(which bindgen uses for `char`) is now a type alias to `u8` anyways,
but before commit 1bae8729e5 ("rust: map `long` to `isize` and `char`
to `u8`") the concrete type of `kernel::ffi::c_char` depended on the
architecture (However all supported architectures at the time mapped to
`i8`).

This caused problems on the v6.13 tag when building for 32 bit arm (with
my patches), since back then `*const i8` was used in the function
argument and the function that bindgen generated used
`*const core::ffi::c_char` which Rust mapped to `*const u8` on 32 bit
arm. The stable v6.13.y branch does not have this issue since commit
1bae8729e5 ("rust: map `long` to `isize` and `char` to `u8`") was
backported.

This caused the following build error:
```
error[E0308]: mismatched types
  --> rust/kernel/firmware.rs:20:4
   |
20 |         Self(bindings::request_firmware)
   |         ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
   |         |
   |         arguments to this function are incorrect
   |
   = note: expected fn pointer `unsafe extern "C" fn(_, *const i8, _) -> _`
                 found fn item `unsafe extern "C" fn(_, *const u8, _) -> _ {request_firmware}`
note: tuple struct defined here
  --> rust/kernel/firmware.rs:14:8
   |
14 | struct FwFunc(
   |        ^^^^^^

error[E0308]: mismatched types
  --> rust/kernel/firmware.rs:24:14
   |
24 |         Self(bindings::firmware_request_nowarn)
   |         ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
   |         |
   |         arguments to this function are incorrect
   |
   = note: expected fn pointer `unsafe extern "C" fn(_, *const i8, _) -> _`
                 found fn item `unsafe extern "C" fn(_, *const u8, _) -> _ {firmware_request_nowarn}`
note: tuple struct defined here
  --> rust/kernel/firmware.rs:14:8
   |
14 | struct FwFunc(
   |        ^^^^^^

error[E0308]: mismatched types
  --> rust/kernel/firmware.rs:64:45
   |
64 |         let ret = unsafe { func.0(pfw as _, name.as_char_ptr(), dev.as_raw()) };
   |                            ------           ^^^^^^^^^^^^^^^^^^ expected `*const i8`, found `*const u8`
   |                            |
   |                            arguments to this function are incorrect
   |
   = note: expected raw pointer `*const i8`
              found raw pointer `*const u8`

error: aborting due to 3 previous errors
```

Fixes: de6582833d ("rust: add firmware abstractions")
Cc: stable@vger.kernel.org
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Christian Schrefl <chrisi.schrefl@gmail.com>
Acked-by: Miguel Ojeda <ojeda@kernel.org>
Link: https://lore.kernel.org/r/20250413-rust_arm_fix_fw_abstaction-v3-1-8dd7c0bbcd47@gmail.com
[ Add firmware prefix to commit subject. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
2025-04-14 14:13:23 +02:00
..
alloc Rust changes for v6.15 2025-03-30 17:03:26 -07:00
block rust: block: refactor to use `&raw mut` 2025-03-23 20:39:37 +01:00
fs Rust changes for v6.15 2025-03-30 17:03:26 -07:00
list
net
sync Rust changes for v6.15 2025-03-30 17:03:26 -07:00
time Rust hrtimer API for v6.15 2025-03-25 23:41:14 +01:00
.gitignore
alloc.rs
block.rs
build_assert.rs
cred.rs
device.rs
device_id.rs
devres.rs
dma.rs rust: dma: add `Send` implementation for `CoherentAllocation` 2025-03-24 20:14:10 +01:00
driver.rs
error.rs Rust changes for v6.15 2025-03-30 17:03:26 -07:00
faux.rs
firmware.rs rust: firmware: Use `ffi::c_char` type in `FwFunc` 2025-04-14 14:13:23 +02:00
fs.rs
generated_arch_static_branch_asm.rs.S
init.rs Rust changes for v6.15 2025-03-30 17:03:26 -07:00
io.rs
ioctl.rs
jump_label.rs
kunit.rs
lib.rs Rust changes for v6.15 2025-03-30 17:03:26 -07:00
list.rs
miscdevice.rs
net.rs
of.rs
page.rs
pci.rs Driver core updates for 6.15-rc1 2025-04-01 11:02:03 -07:00
pid_namespace.rs
platform.rs Driver core updates for 6.15-rc1 2025-04-01 11:02:03 -07:00
prelude.rs
print.rs
rbtree.rs rust: rbtree: fix comments referring to Box instead of KBox 2025-03-23 19:43:02 +01:00
revocable.rs
security.rs
seq_file.rs Rust changes for v6.15 2025-03-30 17:03:26 -07:00
sizes.rs
static_assert.rs
std_vendor.rs
str.rs rust: str: implement `strip_prefix` for `BStr` 2025-03-20 21:44:47 +01:00
sync.rs Rust changes for v6.15 2025-03-30 17:03:26 -07:00
task.rs Rust changes for v6.15 2025-03-30 17:03:26 -07:00
time.rs rust: hrtimer: add clocksource selection through `ClockId` 2025-03-22 12:08:54 +01:00
tracepoint.rs
transmute.rs
types.rs
uaccess.rs rust: uaccess: name the correct function 2025-03-23 19:45:03 +01:00
workqueue.rs Locking changes for v6.15: 2025-03-24 20:55:03 -07:00