Re: [PATCH v4] rust: sync: Accept errors for Lock payload data

From: Gary Guo

Date: Mon Nov 02 2026 - 02:01:03 EST


On Fri Oct 23, 2026 at 12:07 AM CST, Philipp Stanner wrote:
> The `Lock` baseclass currently does not allow for fallible user-data.
> This can cause conflicts when used with other primitives, for example
> when a lock shall be pin-initialized with payload data that is fallible.
>
> Add support for the lock base class so that it works with
> try_pin_init!(). Adjust spinlock and mutex accordingly.
>
> Signed-off-by: Philipp Stanner <phasta@xxxxxxxxxx>

Reviewed-by: Gary Guo <gary@xxxxxxxxxxx>

> ---
> Changes in v4:
> - Do imports at appropriate places. (Gary)
> - Remove unnecessary changes from pin_init to try_pin_init. (Gary)
> - re-run rustfmt.
>
> Changes in v3:
> - Vertical formatting for imports
>
> Changes in v2:
> - Don't import prelude in doctests. (Gary)
> - Keep using pin_init! over try_pin_init! in Lock::new(). (Gary)
> ---
> rust/kernel/sync/lock.rs | 28 +++++++++++++++++++++-------
> rust/kernel/sync/lock/spinlock.rs | 5 +----
> 2 files changed, 22 insertions(+), 11 deletions(-)