Skip to content

rust: sync: lock: allow fallible initializers in Lock::new

Ivan Tverdokhleb dri-devel lkml rust-for-linux 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest2 patches 2 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2rust: sync: lock: allow fallible initializers in Lock::newrust/kernel/sync/lock.rs+4 -42 replies
2/2rust: gpu: buddy: store the allocator inside the Mutexrust/kernel/gpu/buddy.rs+15 -230 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

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

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(-)
Signature · 1 line
2.56.1