[PATCH 1/3] rust: error: implement ZeroableOption for Error

From: Alice Ryhl

Date: Wed Oct 07 2026 - 10:46:20 EST


Rust Binder wants to store an Option<Error> in TransactionInfo, which
derives Zeroable. Implement ZeroableOption for Error so that
Option<Error> implements Zeroable.

Signed-off-by: Alice Ryhl <aliceryhl@xxxxxxxxxx>
---
rust/kernel/error.rs | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/rust/kernel/error.rs b/rust/kernel/error.rs
index e52793f77196..81f32dc8715b 100644
--- a/rust/kernel/error.rs
+++ b/rust/kernel/error.rs
@@ -199,8 +199,12 @@ macro_rules! declare_err {
///
/// The value is a valid `errno` (i.e. `>= -MAX_ERRNO && < 0`).
#[derive(Clone, Copy, PartialEq, Eq)]
+#[repr(transparent)]
pub struct Error(NonZeroI32);

+// SAFETY: All zeros is equivalent to `None` according to the option layout optimization guarantee.
+unsafe impl pin_init::ZeroableOption for Error {}
+
impl Error {
/// Creates an [`Error`] from a kernel error code.
///

--
2.56.0.rc1.315.gc6ed9934b7-goog