]> www.infradead.org Git - users/jedix/linux-maple.git/commit
panic_qr: use new #[export] macro
authorAlice Ryhl <aliceryhl@google.com>
Mon, 3 Mar 2025 08:45:16 +0000 (08:45 +0000)
committerMiguel Ojeda <ojeda@kernel.org>
Sun, 9 Mar 2025 19:52:46 +0000 (20:52 +0100)
commitfc2f191f850d9a2fb1b78c51d49076e60fb42c49
treece891a7d8af47e95aa5d9c3dbcf6ef9a484be5da
parent92d2873bedf33974b04530215692705185ec6572
panic_qr: use new #[export] macro

This validates at compile time that the signatures match what is in the
header file. It highlights one annoyance with the compile-time check,
which is that it can only be used with functions marked unsafe.

If the function is not unsafe, then this error is emitted:

error[E0308]: `if` and `else` have incompatible types
   --> <linux>/drivers/gpu/drm/drm_panic_qr.rs:987:19
    |
986 | #[export]
    | --------- expected because of this
987 | pub extern "C" fn drm_panic_qr_max_data_size(version: u8, url_len: usize) -> usize {
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected unsafe fn, found safe fn
    |
    = note: expected fn item `unsafe extern "C" fn(_, _) -> _ {kernel::bindings::drm_panic_qr_max_data_size}`
               found fn item `extern "C" fn(_, _) -> _ {drm_panic_qr_max_data_size}`

The signature declarations are moved to a header file so it can be
included in the Rust bindings helper, and the extern keyword is removed
as it is unnecessary.

Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Tamir Duberstein <tamird@gmail.com>
Acked-by: Simona Vetter <simona.vetter@ffwll.ch>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
Link: https://lore.kernel.org/r/20250303-export-macro-v3-5-41fbad85a27f@google.com
[ Fixed `rustfmt`. Moved on top the unsafe requirement comment to follow
  the usual style, and slightly reworded it for clarity. Formatted
  bindings helper comment. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
drivers/gpu/drm/drm_panic.c
drivers/gpu/drm/drm_panic_qr.rs
include/drm/drm_panic.h
rust/bindings/bindings_helper.h