[PATCH 0/2] rust: sync: lock: allow fallible initializers in Lock::new

From: Ivan Tverdokhleb

Date: Sat Nov 14 2026 - 15:07:40 EST


GpuBuddyInner keeps the C gpu_buddy structure next to a separate
Mutex<()> and has a TODO to move the structure inside the mutex once
Mutex::new() accepts a fallible initializer.

Patch 1 makes Lock::new() generic over the error type of the initializer
for the protected data, so a fallible initializer such as
Opaque::try_ffi_init() can be wrapped in a Mutex or SpinLock.

Patch 2 uses it to put the gpu_buddy allocator directly inside the Mutex
in GPU buddy, so that the allocator can only be reached through the lock
guard, and resolves the TODO.

Tested by building the rust/kernel crate (x86_64 defconfig with
CONFIG_RUST=y and CONFIG_GPU_BUDDY=y, built with LLVM=1). Not tested at
runtime.

Ivan Tverdokhleb (2):
rust: sync: lock: allow fallible initializers in Lock::new
rust: gpu: buddy: store the allocator inside the Mutex

rust/kernel/gpu/buddy.rs | 38 +++++++++++++++-----------------------
rust/kernel/sync/lock.rs | 8 ++++----
2 files changed, 19 insertions(+), 27 deletions(-)

--
2.56.1