From: Boqun Feng <boqun.feng@xxxxxxxxx> commit be2ca1e03965ffb214b6cbda0ffd84daeeb5f214 upstream. To support a potential usage: static foo: Opaque<Foo> = ..; // Or defined in an extern block. ... fn bar() { let ptr = foo.get(); } `Opaque::get` need to be `const`, otherwise compiler will complain because calls on statics are limited to const functions. Also `Opaque::get` should be naturally `const` since it's a composition of two `const` functions: `UnsafeCell::get` and `ptr::cast`. Signed-off-by: Boqun Feng <boqun.feng@xxxxxxxxx> Reviewed-by: Alice Ryhl <aliceryhl@xxxxxxxxxx> Reviewed-by: Wedson Almeida Filho <walmeida@xxxxxxxxxxxxx> Reviewed-by: Benno Lossin <benno.lossin@xxxxxxxxx> Link: https://lore.kernel.org/r/20240401214543.1242286-1-boqun.feng@xxxxxxxxx Signed-off-by: Miguel Ojeda <ojeda@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- rust/kernel/types.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/rust/kernel/types.rs +++ b/rust/kernel/types.rs @@ -248,7 +248,7 @@ impl<T> Opaque<T> { } /// Returns a raw pointer to the opaque data. - pub fn get(&self) -> *mut T { + pub const fn get(&self) -> *mut T { UnsafeCell::get(&self.value).cast::<T>() } Patches currently in stable-queue which might be from boqun.feng@xxxxxxxxx are queue-6.6/rust-types-make-opaque-get-const.patch queue-6.6/rust-macros-provide-correct-provenance-when-constructing-this_module.patch