]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
rust: redefine `bindings::compat_ptr_ioctl` in Rust
authorAlice Ryhl <aliceryhl@google.com>
Mon, 5 Jan 2026 14:25:03 +0000 (14:25 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 16 Jan 2026 13:54:11 +0000 (14:54 +0100)
commit68aabb29a5469e4b7358e70e64a7fac433e27f06
tree72303b34479bac95233632668c1e737f30abd7b2
parentb0e930a6360ff5f81045146f0a8fcac4f7897eda
rust: redefine `bindings::compat_ptr_ioctl` in Rust

There is currently an inconsistency between C and Rust, which is that
when Rust requires cfg(CONFIG_COMPAT) on compat_ioctl when using the
compat_ptr_ioctl symbol because '#define compat_ptr_ioctl NULL' does not
get translated to anything by bindgen.

But it's not *just* a matter of translating the '#define' into Rust when
CONFIG_COMPAT=n. This is because when CONFIG_COMPAT=y, the type of
compat_ptr_ioctl is a non-nullable function pointer, and to seamlessly
use it regardless of the config, we need a nullable function pointer.

I think it's important to do something about this; I've seen the mistake
of accidentally forgetting '#[cfg(CONFIG_COMPAT)]' when compat_ptr_ioctl
is used multiple times now.

This explicitly declares 'bindings::compat_ptr_ioctl' as an Option that
is always defined but might be None. This matches C, but isn't ideal:
it modifies the bindings crate. But I'm not sure if there's a better way
to do it. If we just redefine in kernel/, then people may still use the
one in bindings::, since that is where you would normally find it. I am
open to suggestions.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Gary Guo <gary@garyguo.net>
Link: https://patch.msgid.link/20260105-redefine-compat_ptr_ioctl-v1-1-25edb3d91acc@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/android/binder/rust_binder_main.rs
rust/bindings/lib.rs
rust/kernel/miscdevice.rs