From nobody Fri Jul 24 22:54:26 2026 Received: from CWXP265CU010.outbound.protection.outlook.com (mail-ukwestazon11022085.outbound.protection.outlook.com [52.101.101.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B43A33689A; Wed, 22 Jul 2026 18:50:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.101.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784746237; cv=fail; b=uWFpBp7h/0Af13ivRh6saQ2XwI6+mUmMGzzHvUNJzCEws7rQkVwpokxUKP7AtH45R3JJb8dXCln0aNP/ortOvbVY/LeLW96jBJ1MCEoxXEjThoGWtOoEtRd0jMl45oWkSh5lwErA2SdeZlkNJH8PD9Jl2o/HKkAWTQvJvRmseaY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784746237; c=relaxed/simple; bh=uSQ4Gt+Rk1cJBp4XxSmuCqHFwN8IM2BigFvI15aqCq0=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=k4rdgKvYt56bKx11L9R9lU6ajGzVigMbILDx+s4g1CfZD7AbtJJV23irlaY2f5hEux8XtauHoE+cE652plSYQIksVnrOp7HIRJXx5/+FHnYYPHRV3Arodx3V5XZEN543uLLmNSNNNpZHHbGMgI/dJoI89IMdtjyl4JqwSJdzDeE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net; spf=pass smtp.mailfrom=garyguo.net; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b=KbTnMQrm; arc=fail smtp.client-ip=52.101.101.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=garyguo.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b="KbTnMQrm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xpzFq1mUNjWnr/0YqprAYNzvihrSucq/bTUOgbRZdD4ljThfcu1+yyunjLPg+aY8QgpkVl0KF7iTnn/atEn+UHi6k7RHMQALuBU9inHAJi2GDaMTQ4kzTEO+hJGpxnBRb2HpOP8V/qgGUBKAAasiNuLapI91asZoDjTHFPcTPEKEonnnmdy87MAr+E6VputWEV9jS1wM6wHnm8ZCQ9nI5iMR5tlziMkL10DXrf9ZqDrB+4MP8kGfuozacmoOSn+W3CrZ4eihEWqLF1tQn3xkDdhT1CNjXDO7a8gntlAsbGoIM/Jcdj/Ab68jxQl+8+nt/prRsrkXUTYqvdWQId4MwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=isZ8uvc9xP3xHuO51gn0EUSVJN2LfrxxfqKuSx8H0iU=; b=VcDIE9mglx1cddnQQvM5uHLAU1vPbviwuM7p6vZsPRtrjogHVc0Ov0eIAJeTcGSTuFfPUFjwvLbIDqlAF57rQLs4i4BepjEX80Q2aBD91AGXhoOeDb5jWZ+xgCnwT0VI6Ykx+89V+jCK6CMeG+OidomBcg+s3ZvMb5J3IfHOxZsUTV8lCBdxWSvZkUNs/5K4UTh4gKpHkZ8xWAPDc7KcCtC+KvCfiiZ5Lgv7FxQdBIq1GsigAifFFvLcr0pdcO/bI4PGEcNWm/L3NsOZuwtzpzc58IvrUM7VWx8b3pGO8r5BuQDhYYOfrfP8YxQiuHxI8HcWdK2ryT+sIUQSR0KihA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=isZ8uvc9xP3xHuO51gn0EUSVJN2LfrxxfqKuSx8H0iU=; b=KbTnMQrmNedl3zIIZWiLF02mlL3jRDVE392TeeFFIyK5JFlNRKepebVSL43Zc2BoHxUFaMR4xc0iPRHu5VGknNCG0VDxfjFuGFANmH0qG66/DJp+YqImugFkZCsvFLPTqL2EaRrbqayatJtYaGSAADbsM4UTxaFkFSbKdsZC7Fo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) by CWXP265MB2471.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:9d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.10; Wed, 22 Jul 2026 18:50:29 +0000 Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986]) by LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986%4]) with mapi id 15.21.0223.017; Wed, 22 Jul 2026 18:50:29 +0000 From: Gary Guo Date: Wed, 22 Jul 2026 19:50:15 +0100 Subject: [PATCH 1/4] rust: pin-init: merge `__pinned_init` and `__init` Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260722-merge-init-v1-1-d4594de76538@garyguo.net> References: <20260722-merge-init-v1-0-d4594de76538@garyguo.net> In-Reply-To: <20260722-merge-init-v1-0-d4594de76538@garyguo.net> To: Benno Lossin , Miguel Ojeda , Boqun Feng , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Gary Guo X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784746228; l=20170; i=gary@garyguo.net; s=20221204; h=from:subject:message-id; bh=uSQ4Gt+Rk1cJBp4XxSmuCqHFwN8IM2BigFvI15aqCq0=; b=E8kQ/bqgqtu0nfwhvVvdEI1vfTo4uAdI1T0vZyu6HjQ/dXsS0/42JOWfmEbsmOgSrmcgGy/xh Q+LcIVwrNvwApqMOR7Gt2HE+FyjmRK/kTmXZIafftYHnKPb9D8F7Ehe X-Developer-Key: i=gary@garyguo.net; a=ed25519; pk=vB3uIX95SM4eVrIqo1DWNWKDKD2xzB+yLLLr0yOPYMo= X-ClientProxiedBy: LO4P123CA0243.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a7::14) To LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LOVP265MB8871:EE_|CWXP265MB2471:EE_ X-MS-Office365-Filtering-Correlation-Id: cd239628-1fca-4202-f86e-08dee82219f0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|23010399003|10070799003|376014|7416014|1800799024|56012099006|10067099003|921020|6133799003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: ses/dqQbwRyFhWMzreSSHdW6Gp39Zhr/vr+qmGGGUAdw+sn25i5H6oK8TO1HNXAVKjdiPkP2OFFTd7qzxuAkPl/DRoUn9iP9HWeEPp0PCTU3pDnyfUMMLrc4bybFErB1DO03PfvsZXD81Sx0VC8ZCs+mfRh3llPmkihXO1ZlYZpoiWDEm1SKYapzt+lSj8fMP0xRrHCdz8JVAkaPLOK/lZbsVxvUNzBpG0NxDo8LESAIa/aNSgtQdKA/ZA/zA+Qi2lzKAlsAqwFYg9ab9hm62M6q+CMyvYAHhu+L0JvZCipL47x7fuIGTbieDord+RUmsRzcEdSICpMI4av2G09DmPBssFBTR+yCz/ociYc1rFsjhuo/Jsiu9kJhH3lq9mx+/vtl/OCHuQOz0e2XQyDqOsQbd7XLNByoKKbT+mS/jJMIPgqE/0NDiz26AA3RwIcn4u0nwtr+w37qPTSzwoKKdrQ2rjxkK0IbNgiDZcN89lA8gCKiz18tiJA+hKjgDN7Ta4wOlHLkUb68LrOJveIuw1UfYp8FUQhEN2aXAx40i4gGz+lXVhtjQDJELDKgLxAxa9+tQx/6k2RDpdoyB6aDQnmEyJSBIAGgHEoQRG1HIK1w6167CNpB8XbCOOi9kpjmSdohyYE6yXLY8QCtB+K5IrUtvkl0j7vJw0ru4rHcH8IUnv2C3cgKSnJdOFNsUOcuUrEq1LO02yNaEG7I/6Zppw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(366016)(23010399003)(10070799003)(376014)(7416014)(1800799024)(56012099006)(10067099003)(921020)(6133799003)(22082099003)(18002099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RUtvYk1VYWVQNkZFYzVGbjRYZEQyYWhOdmJ1MWthbEVKQm5BVDFRWnFYSTlZ?= =?utf-8?B?NkZHcEdzTEQ5bzhZRkpScDF3L3pLOVE4bWt0YXlwL2d0UjlTZ0V5b3ZkY3d2?= =?utf-8?B?a0lQQ0pkMUhtdmRzSVZSQTg4cENJY2k2M0tzNTZPTGZsSERWc1p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3hXbU80MnNuN0sxSXNFdmdFUFJmcW54?= =?utf-8?B?ZXJuaVB4L0RuYjhrYU13VGQyem5oQTJucWl2cUc3TGZaTjhudlRsRVpsMEZB?= =?utf-8?B?YnVXVmhZMVNZQ1A2U3JSclFoMGNEbElGUkJiN0tGTkJYZTNqbHZmdGdtamdi?= =?utf-8?B?WDZ1VVEvWWkvMWRCeFpyVnIvYmtBVG5xMzZrUlpsVStYd3F2dnlFdmlPdHBi?= =?utf-8?B?TmtDd0tycSt3aWlyWGZ4cEp5T2dseHBwdjQ3azE5emlBTU5QeHFhVG5WZTB3?= =?utf-8?B?akFIOTNKa1c0ZlpsV1o1Tkk3SEQxV09SYmhiNUp4R2xLTWFXbjk5QkM4eEc0?= =?utf-8?B?UW85OWs1SDhZVGpUaVdYMmFEeDdORCtGU1NUY0MwS1VsbkN4Q2tXZz09?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: cd239628-1fca-4202-f86e-08dee82219f0 X-MS-Exchange-CrossTenant-AuthSource: LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2026 18:50:29.5577 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: JdTNVdXTZzGucjpQuwqETatbxMOWtZN/0jzoWcQzQguPQjfZunWZrvWn06xtnr+IaqDhKQ2pT5duBILItSWSXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWXP265MB2471 These functions have the same requirements and are also required to execute the same code. Prevent duplication by merging them to the single function and document the additional relaxation of `Init::__init` on both the merged function and the safety requirement of `Init`. The existing `__pinned_init` function is deprecated and kept for compatibility for existing users. For `cfg(kernel)`, it is soft-deprecated for now and will be removed when all users are migrated. Signed-off-by: Gary Guo --- rust/pin-init/examples/mutex.rs | 2 +- rust/pin-init/examples/static_init.rs | 9 +-- rust/pin-init/src/__internal.rs | 8 +- rust/pin-init/src/alloc.rs | 6 +- rust/pin-init/src/lib.rs | 146 +++++++++++++-----------------= ---- 5 files changed, 68 insertions(+), 103 deletions(-) diff --git a/rust/pin-init/examples/mutex.rs b/rust/pin-init/examples/mutex= .rs index 882f3e23f5dd..8a3236c0c502 100644 --- a/rust/pin-init/examples/mutex.rs +++ b/rust/pin-init/examples/mutex.rs @@ -81,7 +81,7 @@ pub fn new(val: impl PinInit) -> impl PinInit { locked: Cell::new(false), data <- unsafe { pin_init_from_closure(|slot: *mut UnsafeCell| { - val.__pinned_init(slot.cast::()) + val.__init(slot.cast::()) }) }, }) diff --git a/rust/pin-init/examples/static_init.rs b/rust/pin-init/examples= /static_init.rs index 58cd4241b78c..8e71556ffe85 100644 --- a/rust/pin-init/examples/static_init.rs +++ b/rust/pin-init/examples/static_init.rs @@ -59,7 +59,7 @@ fn deref(&self) -> &Self::Target { println!("doing init"); let ptr =3D self.cell.get().cast::(); match self.init.take() { - Some(f) =3D> unsafe { f.__pinned_init(ptr).unwrap() }, + Some(f) =3D> unsafe { f.__init(ptr).unwrap() }, None =3D> unsafe { core::hint::unreachable_unchecked() }, } self.present.set(true); @@ -71,13 +71,10 @@ fn deref(&self) -> &Self::Target { pub struct CountInit; =20 unsafe impl PinInit> for CountInit { - unsafe fn __pinned_init( - self, - slot: *mut CMutex, - ) -> Result<(), core::convert::Infallible> { + unsafe fn __init(self, slot: *mut CMutex) -> Result<(), core::c= onvert::Infallible> { let init =3D CMutex::new(0); std::thread::sleep(std::time::Duration::from_millis(1000)); - unsafe { init.__pinned_init(slot) } + unsafe { init.__init(slot) } } } =20 diff --git a/rust/pin-init/src/__internal.rs b/rust/pin-init/src/__internal= .rs index 56dc655e323e..ae9a0e68cd75 100644 --- a/rust/pin-init/src/__internal.rs +++ b/rust/pin-init/src/__internal.rs @@ -181,7 +181,7 @@ pub fn init(self: Pin<&mut Self>, init: impl PinInit= ) -> Result(self, init: impl PinInit) -> Resul= t, E // - when `Err` is returned, we also propagate the error without t= ouching `ptr`; // also `self` is consumed so it cannot be touched further. // - the drop guard will not hand out `&mut` (only `Pin<&mut T>`). - unsafe { init.__pinned_init(self.ptr)? }; + unsafe { init.__init(self.ptr)? }; =20 // SAFETY: // - `self.ptr` is valid, properly aligned and pinned per type inv= ariant. @@ -396,9 +396,9 @@ fn default() -> Self { } } =20 -// SAFETY: `__pinned_init` always fails, which is always okay. +// SAFETY: `__init` always fails, which is always okay. unsafe impl PinInit for AlwaysFail { - unsafe fn __pinned_init(self, _slot: *mut T) -> Result<(), ()> { + unsafe fn __init(self, _slot: *mut T) -> Result<(), ()> { Err(()) } } diff --git a/rust/pin-init/src/alloc.rs b/rust/pin-init/src/alloc.rs index 5017f57442d8..641f4c7ce890 100644 --- a/rust/pin-init/src/alloc.rs +++ b/rust/pin-init/src/alloc.rs @@ -38,7 +38,7 @@ fn try_pin_init(init: impl PinInit) -> Result, E> fn pin_init(init: impl PinInit) -> Result, AllocError> { // SAFETY: We delegate to `init` and only change the error type. let init =3D unsafe { - pin_init_from_closure(|slot| match init.__pinned_init(slot) { + pin_init_from_closure(|slot| match init.__init(slot) { Ok(()) =3D> Ok(()), Err(i) =3D> match i {}, }) @@ -109,7 +109,7 @@ fn try_pin_init(init: impl PinInit) -> Result<= Pin, E> let slot =3D slot.as_mut_ptr(); // SAFETY: When init errors/panics, slot will get deallocated but = not dropped, // slot is valid and will not be moved, because we pin it later. - unsafe { init.__pinned_init(slot)? }; + unsafe { init.__init(slot)? }; // SAFETY: All fields have been initialized and this is the only `= Arc` to that data. Ok(unsafe { Pin::new_unchecked(this.assume_init()) }) } @@ -149,7 +149,7 @@ fn write_pin_init(mut self, init: impl PinInit= ) -> Result`]: alloc::alloc::boxed::Box")] #[must_use =3D "An initializer must be used in order to create its value."] pub unsafe trait PinInit: Sized { + /// Alias of [`PinInit::__init`]. + /// + /// New code should use `__init` instead. + /// + /// # Safety + /// + /// Same as `__init`. + #[inline(always)] + #[cfg_attr(not(kernel), deprecated =3D "use `__init` instead")] + unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { + // SAFETY: Per safety requirement. + unsafe { self.__init(slot) } + } + /// Initializes `slot`. /// /// # Safety @@ -917,7 +931,8 @@ pub unsafe trait PinInit: = Sized { /// - the caller does not touch `slot` when `Err` is returned, they ar= e only permitted to /// deallocate. /// - `slot` will not move until it is dropped, i.e. it will be pinned. - unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E>; + /// If `Self: Init`, this requirement is cancelled and it may = be moved. + unsafe fn __init(self, slot: *mut T) -> Result<(), E>; =20 /// First initializes the value using `self` then calls the function `= f` with the initialized /// value. @@ -948,7 +963,7 @@ fn pin_chain(self, f: F) -> ChainPinInit /// An initializer returned by [`PinInit::pin_chain`]. pub struct ChainPinInit(I, F, __internal::PhantomInvar= iant<(E, T)>); =20 -// SAFETY: The `__pinned_init` function is implemented such that it +// SAFETY: The `__init` function is implemented such that it // - returns `Ok(())` on successful initialization, // - returns `Err(err)` on error and in this case `slot` will be dropped. // - considers `slot` pinned. @@ -957,8 +972,8 @@ unsafe impl PinInit for Chain= PinInit I: PinInit, F: FnOnce(Pin<&mut T>) -> Result<(), E>, { - unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { - // SAFETY: All requirements fulfilled since this function is `__pi= nned_init`. + unsafe fn __init(self, slot: *mut T) -> Result<(), E> { + // SAFETY: All requirements fulfilled since this function is `__in= it`. let slot =3D unsafe { __internal::Slot::<__internal::Pinned, _>::n= ew(slot) }; let mut guard =3D slot.init(self.0)?; (self.1)(guard.let_binding())?; @@ -980,19 +995,8 @@ unsafe fn __pinned_init(self, slot: *mut T) -> Result<= (), E> { /// When implementing this trait you will need to take great care. Also th= ere are probably very few /// cases where a manual implementation is necessary. Use [`init_from_clos= ure`] where possible. /// -/// The [`Init::__init`] function: -/// - returns `Ok(())` if it initialized every field of `slot`, -/// - returns `Err(err)` if it encountered an error and then cleaned `slot= `, this means: -/// - `slot` can be deallocated without UB occurring, -/// - `slot` does not need to be dropped, -/// - `slot` is not partially initialized. -/// - while constructing the `T` at `slot` it upholds the pinning invarian= ts of `T`. -/// -/// The `__pinned_init` function from the supertrait [`PinInit`] needs to = execute the exact same -/// code as `__init`. -/// -/// Contrary to its supertype [`PinInit`] the caller is allowed to -/// move the pointee after initialization. +/// The [`PinInit::__init`] function must work without the pinning require= ment; the caller is +/// allowed to move the pointee after initialization. /// #[cfg_attr( kernel, @@ -1006,15 +1010,6 @@ unsafe fn __pinned_init(self, slot: *mut T) -> Resul= t<(), E> { #[cfg_attr(not(kernel), doc =3D "[`Box`]: alloc::alloc::boxed::Box")] #[must_use =3D "An initializer must be used in order to create its value."] pub unsafe trait Init: PinInit { - /// Initializes `slot`. - /// - /// # Safety - /// - /// - `slot` is a valid pointer to uninitialized memory. - /// - the caller does not touch `slot` when `Err` is returned, they ar= e only permitted to - /// deallocate. - unsafe fn __init(self, slot: *mut T) -> Result<(), E>; - /// First initializes the value using `self` then calls the function `= f` with the initialized /// value. /// @@ -1053,10 +1048,18 @@ fn chain(self, f: F) -> ChainInit /// An initializer returned by [`Init::chain`]. pub struct ChainInit(I, F, __internal::PhantomInvarian= t<(E, T)>); =20 +// SAFETY: The `__init` function does not rely on the pinning requirement. +unsafe impl Init for ChainInit +where + I: Init, + F: FnOnce(&mut T) -> Result<(), E>, +{ +} + // SAFETY: The `__init` function is implemented such that it // - returns `Ok(())` on successful initialization, // - returns `Err(err)` on error and in this case `slot` will be dropped. -unsafe impl Init for ChainInit +unsafe impl PinInit for ChainInit where I: Init, F: FnOnce(&mut T) -> Result<(), E>, @@ -1071,44 +1074,28 @@ unsafe fn __init(self, slot: *mut T) -> Result<(), = E> { } } =20 -// SAFETY: `__pinned_init` behaves exactly the same as `__init`. -unsafe impl PinInit for ChainInit -where - I: Init, - F: FnOnce(&mut T) -> Result<(), E>, -{ - unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { - // SAFETY: `__init` has less strict requirements compared to `__pi= nned_init`. - unsafe { self.__init(slot) } - } -} - /// Implement `PinInit` and `Init` for closures. /// /// It is unsafe to create this type, since the closure needs to fulfill t= he same safety -/// requirement as the `__pinned_init`/`__init` functions. +/// requirement as the `__init` functions. struct InitClosure(F, __internal::PhantomInvariant); =20 -// SAFETY: While constructing the `InitClosure`, the user promised that it= upholds the -// `__init` invariants. -unsafe impl Init for InitClosure -where - F: FnOnce(*mut T) -> Result<(), E>, +// SAFETY: When constructing via `init_from_closure`, the `__init` functio= n does not rely on the +// pinning requirement. When constructing via `pin_init_from_closure`, the= opaque type prevents this +// implementation from being visible. +unsafe impl Init for InitClosure where + F: FnOnce(*mut T) -> Result<(), E> { - #[inline] - unsafe fn __init(self, slot: *mut T) -> Result<(), E> { - (self.0)(slot) - } } =20 // SAFETY: While constructing the `InitClosure`, the user promised that it= upholds the -// `__pinned_init` invariants. +// `__init` invariants. unsafe impl PinInit for InitClosure where F: FnOnce(*mut T) -> Result<(), E>, { #[inline] - unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { + unsafe fn __init(self, slot: *mut T) -> Result<(), E> { (self.0)(slot) } } @@ -1160,7 +1147,7 @@ unsafe fn __pinned_init(self, slot: *mut T) -> Result= <(), E> { pub const unsafe fn cast_pin_init(init: impl PinInit) -> im= pl PinInit { // SAFETY: initialization delegated to a valid initializer. Cast is va= lid by function safety // requirements. - unsafe { pin_init_from_closure(|ptr: *mut U| init.__pinned_init(ptr.ca= st::())) } + unsafe { pin_init_from_closure(|ptr: *mut U| init.__init(ptr.cast::= ())) } } =20 /// Changes the to be initialized type. @@ -1195,7 +1182,7 @@ pub fn uninit() -> impl Init, E>= { F: FnMut(usize) -> I, I: PinInit, { - unsafe fn __pinned_init(mut self, slot: *mut [T; N]) -> Result<(), E> { + unsafe fn __init(mut self, slot: *mut [T; N]) -> Result<(), E> { /// # Invariants /// /// - `ptr[..num_init]` contains initialized elements of type `T` @@ -1237,7 +1224,7 @@ fn drop(&mut self) { // - If `Err` is touched, the subslot is not touched further, = the guard will drop // previously initialized elements only. // - `slot` is pinned so is the subslot. - unsafe { init.__pinned_init(&raw mut (*slot)[i]) }?; + unsafe { init.__init(&raw mut (*slot)[i]) }?; } =20 // Dismiss the drop guard now that all elements are initialized. @@ -1246,18 +1233,13 @@ fn drop(&mut self) { } } =20 -// SAFETY: Follows the `PinInit` impl. `__init` executes the same code as = `__pinned_init`. +// SAFETY: `I: Init` cancels out the pinning requirement on subslots, whic= h is the only place in the +// `__init` function that relies on `slot` being pinned. unsafe impl Init<[T; N], E> for ArrayInit where F: FnMut(usize) -> I, I: Init, { - #[inline(always)] - unsafe fn __init(self, slot: *mut [T; N]) -> Result<(), E> { - // SAFETY: `I: Init` cancels out the pinning requirement on subslo= ts. The other safety - // requirements follow that of `__init`. - unsafe { self.__pinned_init(slot) } - } } =20 /// Initializes an array by initializing each element via the provided ini= tializer. @@ -1336,13 +1318,13 @@ pub fn pin_init_scope(make_init: F) -> = impl PinInit { // SAFETY: // - If `make_init` returns `Err`, `Err` is returned and `slot` is com= pletely uninitialized, - // - If `make_init` returns `Ok`, safety requirement are fulfilled by = `init.__pinned_init`. - // - The safety requirements of `init.__pinned_init` are fulfilled, si= nce it's being called - // from an initializer. + // - If `make_init` returns `Ok`, safety requirement are fulfilled by = `init.__init`. + // - The safety requirements of `init.__init` are fulfilled, since it'= s being called from an + // initializer. unsafe { pin_init_from_closure(move |slot: *mut T| -> Result<(), E> { let init =3D make_init()?; - init.__pinned_init(slot) + init.__init(slot) }) } } @@ -1390,41 +1372,27 @@ pub fn init_scope(make_init: F) -> impl= Init } } =20 -// SAFETY: the `__init` function always returns `Ok(())` and initializes e= very field of `slot`. -unsafe impl Init for T { - unsafe fn __init(self, slot: *mut T) -> Result<(), Infallible> { - // SAFETY: `slot` is valid for writes by the safety requirements o= f this function. - unsafe { slot.write(self) }; - Ok(()) - } -} +// SAFETY: The `__init` function does not rely on slot being pinned after = it returns. +unsafe impl Init for T {} =20 -// SAFETY: the `__pinned_init` function always returns `Ok(())` and initia= lizes every field of +// SAFETY: the `__init` function always returns `Ok(())` and initializes e= very field of // `slot`. Additionally, all pinning invariants of `T` are upheld. unsafe impl PinInit for T { - unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible> { + unsafe fn __init(self, slot: *mut T) -> Result<(), Infallible> { // SAFETY: `slot` is valid for writes by the safety requirements o= f this function. unsafe { slot.write(self) }; Ok(()) } } =20 -// SAFETY: when the `__init` function returns with -// - `Ok(())`, `slot` was initialized and all pinned invariants of `T` are= upheld. -// - `Err(err)`, slot was not written to. -unsafe impl Init for Result { - unsafe fn __init(self, slot: *mut T) -> Result<(), E> { - // SAFETY: `slot` is valid for writes by the safety requirements o= f this function. - unsafe { slot.write(self?) }; - Ok(()) - } -} +// SAFETY: The `__init` function does not rely on slot being pinned after = it returns. +unsafe impl Init for Result {} =20 -// SAFETY: when the `__pinned_init` function returns with +// SAFETY: when the `__init` function returns with // - `Ok(())`, `slot` was initialized and all pinned invariants of `T` are= upheld. // - `Err(err)`, slot was not written to. unsafe impl PinInit for Result { - unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { + unsafe fn __init(self, slot: *mut T) -> Result<(), E> { // SAFETY: `slot` is valid for writes by the safety requirements o= f this function. unsafe { slot.write(self?) }; Ok(()) @@ -1467,7 +1435,7 @@ fn write_pin_init(self, init: impl PinInit) = -> Result Date: Wed, 22 Jul 2026 19:50:16 +0100 Subject: [PATCH 2/4] rust: devres: use `cast_pin_init` instead of manual reimplementation Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260722-merge-init-v1-2-d4594de76538@garyguo.net> References: <20260722-merge-init-v1-0-d4594de76538@garyguo.net> In-Reply-To: <20260722-merge-init-v1-0-d4594de76538@garyguo.net> To: Benno Lossin , Miguel Ojeda , Boqun Feng , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Gary Guo X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784746228; l=1000; i=gary@garyguo.net; s=20221204; h=from:subject:message-id; bh=ccBzhz7pNkSAhvUsWVM8L4/e8oB9w2GAPULx90uVvE0=; b=rdE/WnkUJkhnD1N1yQb6gWdFu1smCDboJVP19lrxfGpamOfzU7UJawMlXyV4NteGuaH1daylq aclPjFz9/FkBBta19o+mgIZrN1M0O36g179R3ZsYxcR8CMX15OY174K X-Developer-Key: i=gary@garyguo.net; a=ed25519; pk=vB3uIX95SM4eVrIqo1DWNWKDKD2xzB+yLLLr0yOPYMo= X-ClientProxiedBy: LO4P123CA0243.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a7::14) To LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LOVP265MB8871:EE_|CWXP265MB2471:EE_ X-MS-Office365-Filtering-Correlation-Id: 5bb8f16b-37fc-4061-d5e5-08dee8221a1b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|23010399003|10070799003|376014|7416014|1800799024|56012099006|10067099003|921020|6133799003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: Hiicb3GVTKU4eHqxzUmnrS7Lh2KTfT+H7IOIhMu2GuODpluikt1vdfxHJvVBl06PnIOTMAFN1LPRUYpCye5AuTOWIpdaVzoaNI20ik3fD4vkL/q+fv2cs+hroQKkNhaqESH4frvLE0EwvWnq0rq+vjhpcSRQdMe0e9ERyvcWDrN47S9Syt7sL1JiPGoMMDSE/hujXBVVa6/HOcj9Ed9t/LaGj5rKw+fXZZerKQ4CUG7XLj4XmScPz7DYYoJaQSxQo0CL+E/rS2iTxeZ1xcN5rH0UMuWI3iNKaMDxf5CzZvVHYiwqnh/h0yuPmCRLRkkCQyBJxY6aU0dgROyamw2Tjnzk/ZCSS2KbsqjJk0eHDFA8gr9R7zUUm1+m5QWtmMEYHjrCfR6B6WxzbmGf/h3WkeNxX5N7/HqDCU4sNxa6GTXqw+FfNp7Y0zzHK9M0wLeLUCP7cZ+YCylEiNeb3kE17LqvzJZ7D/r/u0iD6xtVnSeo95rYe4xZiwKo5WlBLua7tstYDntklSJL75lrLCzeTWAG5eVU6xSjFPkIhxTQnzzlyBzo3zjCvJmW0VM5Q/A9A5PkMjX+5dq3G122tSgVz5oa/WqmaXFc84dkdDRNDbqR9jQ/45G7x9S7/rbPeCu2TlcHgU9eikAVSX/ZKLD+t9H+PcE5vXcVe93JlM8EGOk576Lo3p9fJSAUIFPET+4o/2eg/m01RguoEX74ZzisVg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(366016)(23010399003)(10070799003)(376014)(7416014)(1800799024)(56012099006)(10067099003)(921020)(6133799003)(22082099003)(18002099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?NUZybDdtVnUxd3dNbndCREpvTnR0cnFSanNZN3lzdGhWZE9zMm95K1FkeTdB?= =?utf-8?B?ZzFmM3lrQUhDUTFGSDRXcVFkUnpXWDNDTG1iMjBpeVhoNzFpeG9Cbjk2UDYz?= =?utf-8?B?dDNRVDNpTm5IY3lnYXMxekY4Nmo1VGNGZWFHNGYvL3ZJSEQxTklSc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xHTDlXS1FzdUNVUmRHVnZsNUcxdFRtQnVzWDV4QUtH?= =?utf-8?B?TDRlOXNzaURCeUFTc0tINVRWMkVyeVpzZ21zZEZ5aFpmV3g3YjNTeEdzbFBj?= =?utf-8?B?QkMwNG9za09vLzlnc2VuYWtnQ1R3aVJyMFF0SHFsWGkrN1h6Y2dVSVhML08r?= =?utf-8?B?YXNlRVppZE4vL1lUY2pEWkRjd3VHM3ZwdXNLd0hXQTI5cVRKUWtzQW5JN29Z?= =?utf-8?B?eldtM3Y1MmFQLzNLdlZ4ZDhGSk4zS0czZGJYMlVVYTU3TkVtRXM1MmtnQ29T?= =?utf-8?B?VitTU1NNVzJkYkoxQkJvVFFUL3VVTU9aMjlMVk5VaWhWVEtkY2lCMmVEcjlC?= =?utf-8?B?VUpVaHl0SE5kVkFhZVNyQ2tkbWRkUWhmcEVuc2hXNmI1dm5JeWE4QT09?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 5bb8f16b-37fc-4061-d5e5-08dee8221a1b X-MS-Exchange-CrossTenant-AuthSource: LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2026 18:50:29.8485 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XEaTkH9svbsxPfAjJZJhNKnGif1TsJqso1cc01Ohm910Dinif93YhP/YQOEE2QnBfNqYu2aGq6R4qcVoB2k9KQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWXP265MB2471 Remove the manual type-casting which is already available as `cast_pin_init`. Signed-off-by: Gary Guo --- rust/kernel/devres.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/rust/kernel/devres.rs b/rust/kernel/devres.rs index ebb5c19e851e..aecc8906de2c 100644 --- a/rust/kernel/devres.rs +++ b/rust/kernel/devres.rs @@ -435,11 +435,7 @@ pub unsafe fn new<'a, E>( // SAFETY: The caller guarantees the data is valid for the device'= s full bound scope. // Lifetimes do not affect layout, so F::Of<'a> and F::Of<'static>= have identical // representation; casting the slot pointer is sound. - let data =3D unsafe { - pin_init::pin_init_from_closure::, E>(move |slo= t| { - data.__pinned_init(slot.cast()) - }) - }; + let data =3D unsafe { pin_init::cast_pin_init(data) }; =20 Ok(Self(Devres::new(dev, data)?)) } --=20 2.54.0 From nobody Fri Jul 24 22:54:26 2026 Received: from CWXP265CU010.outbound.protection.outlook.com (mail-ukwestazon11022085.outbound.protection.outlook.com [52.101.101.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 53E533033DE; Wed, 22 Jul 2026 18:50:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.101.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784746241; cv=fail; b=qsIPZW2a6fS6xVB55ox2UCREBwxx+UbDKDTg4XjVz/00Dnb33q539A4Sv7PRvVq6fv53x4hNaqn8VSAy8UZTp3j9u4nvclCMlZ30x2JF0/nZ2MvGL+B3BSgcRjCvJzhgNCctbT65na1QPyDBY/IIYBMu/sVbUHftcoQybkDJEFQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784746241; c=relaxed/simple; bh=m0nRZfj91bHtcDU6acJX7qj11AsAFclUVDgAmfckORs=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=NBGpnIrfUqXk2Lz8xGpPu81WD2O012C5RABXExj8mCSeAVoE3QOBaI/QthQsK0JwH4AsvkRno5XrjAc0Ae6zby4+XjWN4lIGLUEsgjExxK0qPe9LDpNnzn28+IiZEw77/SbznHZxrhjYEy7tq0FtYYP46YqCiVCz/rW7JQ3nbbg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net; spf=pass smtp.mailfrom=garyguo.net; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b=apil8Sax; arc=fail smtp.client-ip=52.101.101.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=garyguo.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b="apil8Sax" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QQg9j9oPJKBxpN1bTq5hWLHCUQI9afiDyrmEgLpGbTr5lc36sUDigdnZ5KF3vLxqb/2W8NsLBRd2cMFsobn1oxznN2lgERjb8qdUQTTFK+I1Mfn1ARMYBkxUCHRrOco3rSOvltQw4s/fT+Ay4VtFRVBmMWzNfNtwoZGSJjWH9X6sykpeMjYzbbqToswLNL7fogFB2Xmpy5XBKnaEEjaEg1um2Qjmc9VxRJ5alG8ZvlrVD4+f1e+7gEXOLn5Iui4PDELX0WJ6U7958UNoqx1Ov+EuOzJFQA9hev5h+u5L0jBnnhpGiiwkWNItIJFwNOxjOaNne1N2Q+yFSPW30b2l1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=77PsvBmgNSycN4xZY61vH5Zi8vrqlOL1X/t5Rm+Yx44=; b=kbJaGpQ70Hg9O3kUmH659VI/xpy7so17iHArS3/XnnnGcuD/Wa8S7uL+a+wG7e4R9N4PoDMnkebkfnhmuhDwBYvwVfe3GkfvB6d+M77XIu5roGZ9SliYE99ZNcNGEgxunO5Ga4GaTUMnw2aoZPvVbw9Mfcm3U2FRyCJudnk4JO4I3enWXO1Z277AFdgPYW8SIeUHIjVDlknjtThmfzQs5Qqb1I8AiR2rM4loh9r3mX4SYwltQJLHy2n+6fhU/UhTydL6+PF3ZwdpUPukn6eWwW5qellmSbdkh0vXmOnOIcdDciwsA9IAj45i9MOpsPOe8ltdx6wwWFeiZXOsxwa+aw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=77PsvBmgNSycN4xZY61vH5Zi8vrqlOL1X/t5Rm+Yx44=; b=apil8SaxVZC8pXDm+oNH9Q7Bc9QnOAx97xGXiM5ShhRIg8eLg/tuW20t/Ec358Df6182S2U8HKGEI2fFYZrgYOSbwou60BhNJgohdvTTMzqBK0FTG9uShhXj8anFCStr9u88gQQYK4cs1rZXpKlypVTdgCyTvcs3xv1kBC5cvJo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) by CWXP265MB2471.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:9d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.10; Wed, 22 Jul 2026 18:50:36 +0000 Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986]) by LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986%4]) with mapi id 15.21.0223.017; Wed, 22 Jul 2026 18:50:36 +0000 From: Gary Guo Date: Wed, 22 Jul 2026 19:50:17 +0100 Subject: [PATCH 3/4] rust: treewide: replace `__pinned_init` with `__init` Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260722-merge-init-v1-3-d4594de76538@garyguo.net> References: <20260722-merge-init-v1-0-d4594de76538@garyguo.net> In-Reply-To: <20260722-merge-init-v1-0-d4594de76538@garyguo.net> To: Benno Lossin , Miguel Ojeda , Boqun Feng , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Gary Guo X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784746228; l=8736; i=gary@garyguo.net; s=20221204; h=from:subject:message-id; bh=m0nRZfj91bHtcDU6acJX7qj11AsAFclUVDgAmfckORs=; b=/fib0IRjPUt6wh6ZINlQBhxlI1Z5IIyFzXifU+7VEzVBKMw8OVxB+gsdmbeGuaL31XR5txV9F BTlCtU78ySWDKC+lNuxm0gKuZqdzTvIfPFO6Bftw9+FbqjXgpVEkTE5 X-Developer-Key: i=gary@garyguo.net; a=ed25519; pk=vB3uIX95SM4eVrIqo1DWNWKDKD2xzB+yLLLr0yOPYMo= X-ClientProxiedBy: LO4P123CA0243.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a7::14) To LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LOVP265MB8871:EE_|CWXP265MB2471:EE_ X-MS-Office365-Filtering-Correlation-Id: d2be9e32-11a7-4313-ddc9-08dee8221a46 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|23010399003|10070799003|376014|7416014|1800799024|56012099006|10067099003|921020|6133799003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: 7DldtFS1rOi7B1CrxOzdM9Qax9Bnt0HHfzYGMhVJX7/nkrrFhObSmTSv4ZzxafoHUY6G/E2w7+E4W00HCR8l8AUdlfZm3uxuaJ9jdHXA18jEKHTK9F0zWG0Z/Ogg5sVaFQ4BUomoD6VroAS5ji6H/kS27DdEY1J9kicF9g8pdSfELt8mfDS2DvIpm2U5WOMi9reIbpx0UnWwTAUeUMpOQ/lMxQ8tzr9ZuhO35ZP3UbKIM9fd0WIuibNvLtvOoFKw5/EgI4Qg/L3ndeUKozCSKr0HWssGpsAhy3MrYDhIRuVisWQuC/Oi9GcAgQfAPLnb4FRayKZprtThWIblSctaRVZwjCCQzSz+rrzodnIQxDEZbvD+2KYQhspCtzNcms0xz6ZpV+HXdKQ8JQ/QQhPDPfNFA63UKCnFh1KzB3dBMG80YUw77ndND6M5zdbU9T0NYnRVbM7rWafjMmEDhTg7QsVjnNGkcyOWZ9kpVXBrBwrlSex6xMZVsog5JacSCTmcbbY9v4/bVkRILFY4/CrTmOI1rkVTWEiUEylDyhIMZ/zvUCyHgZR5VPDq7J4QcxVKv14np/gW+RoS0SeXi9B0h5jQNYwmlJTbIZwhIthrI3YXAJtJe7ZDwfpLXT1bBe7KOsy+J2CIFUypjob6be78ywA60VRCjq8tODAZepQqnhat+u6O08bst8AAwnTUZKo2BX4y6O78l8GwZoTy646cOw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(366016)(23010399003)(10070799003)(376014)(7416014)(1800799024)(56012099006)(10067099003)(921020)(6133799003)(22082099003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nhlWUQ5U1RhaUtMbjVqdENlcUhqL1ZyeGd3?= =?utf-8?B?QnprNVFFNis1cks3a3V2cGI1ZmpvRTRFcmNaT1ZqdllpZ3EycXhjaFd5MjFW?= =?utf-8?B?cEdoemF4UThTWWpzeGVFUURHbkpsazdkZ0xsWjdDMXJNMkxGYXBnZEJiZ0xa?= =?utf-8?B?QkQ1RU5Wdm9HWGlseVVzN0xHdVdTendiN29ycDlrM3hEK2EwSjVTd0VTK0d5?= =?utf-8?B?ZUt3YXRIa0Z1SjFrM2d5SDZzOXRMWHUxSnV0NzZWYTJJZ2NQOFdlY25pZm1u?= =?utf-8?B?WkpNMk1xRkFFVENCK3RSSFM0Nng5ZHhwalFsb1UybWg2T1lBM05VT0I4WTZn?= =?utf-8?B?N0hxYUQwUXN1QTEwUjJCQlRXT0dqcHlVRmRUVy96dmNtKzRqZzc0aDNUWkVi?= =?utf-8?B?M0kxZHRjYUhKQVo4TzZrWW1oTHY4enNHaVU4c0RaWUFjYUZaNHZSUGxkWWVH?= =?utf-8?B?djc0WDNjbWtxYTdxb1pQdkZHb01obnVkaVhRdFcyaUdwUysxN3RrR29vV0ZF?= =?utf-8?B?UXFzRmJ4eXFCWkJPSnc5S29xeTZ1K2htdHVkRnhQQ0tudVZvVjdyYjY0elFQ?= =?utf-8?B?aUpaTUFjM3RIclBCOFlYMndsTmNiNW93cGdReEZuTm9wZktGL3hBQT09?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: d2be9e32-11a7-4313-ddc9-08dee8221a46 X-MS-Exchange-CrossTenant-AuthSource: LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2026 18:50:30.1218 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: gNbUbBCPv56S9gPVz0jS1049UEhjAF1tBOkgU/mJKdJB1pHY1K+jdO+kNGyOciAL4dasRbGP3Kud1EyNL6ylAA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWXP265MB2471 The `__pinned_init` is being merged with `__init` and is soft-deprecated and is to be removed. Replace the users with `__init`. Signed-off-by: Gary Guo Acked-by: Danilo Krummrich --- rust/kernel/alloc/kbox.rs | 6 +++--- rust/kernel/drm/device.rs | 2 +- rust/kernel/drm/gpuvm/va.rs | 2 +- rust/kernel/drm/gpuvm/vm_bo.rs | 2 +- rust/kernel/init.rs | 10 ++++------ rust/kernel/pwm.rs | 2 +- rust/kernel/sync/arc.rs | 4 ++-- rust/kernel/types.rs | 2 +- rust/macros/module.rs | 2 +- 9 files changed, 15 insertions(+), 17 deletions(-) diff --git a/rust/kernel/alloc/kbox.rs b/rust/kernel/alloc/kbox.rs index 35d1e015848d..78e929ed3382 100644 --- a/rust/kernel/alloc/kbox.rs +++ b/rust/kernel/alloc/kbox.rs @@ -372,13 +372,13 @@ pub fn pin_slice( // - `ptr` is a valid pointer to uninitialized memory. // - `ptr` is not used if an error is returned. // - `ptr` won't be moved until it is dropped, i.e. it is pinn= ed. - unsafe { init(i).__pinned_init(ptr)? }; + unsafe { init(i).__init(ptr)? }; =20 // SAFETY: // - `i + 1 <=3D len`, hence we don't exceed the capacity, due= to the call to // `with_capacity()` above. // - The new value at index buffer.len() + 1 is the only eleme= nt being added here, and - // it has been initialized above by `init(i).__pinned_init(p= tr)`. + // it has been initialized above by `init(i).__init(ptr)`. unsafe { buffer.inc_len(1) }; } =20 @@ -473,7 +473,7 @@ fn write_pin_init(mut self, init: impl PinInit= ) -> Result Result, = AllocError> { pub(super) fn prepare(mut self, va_data: impl PinInit) -> *= mut bindings::drm_gpuva { let va_ptr =3D MaybeUninit::as_mut_ptr(&mut self.0); // SAFETY: The `data` field is pinned. - let Ok(()) =3D unsafe { va_data.__pinned_init(&raw mut (*va_ptr).d= ata) }; + let Ok(()) =3D unsafe { va_data.__init(&raw mut (*va_ptr).data) }; KBox::into_raw(self.0).cast() } } diff --git a/rust/kernel/drm/gpuvm/vm_bo.rs b/rust/kernel/drm/gpuvm/vm_bo.rs index a30f838c11b8..c7305e4c03da 100644 --- a/rust/kernel/drm/gpuvm/vm_bo.rs +++ b/rust/kernel/drm/gpuvm/vm_bo.rs @@ -190,7 +190,7 @@ pub(super) fn new( }; let ptr =3D NonNull::new(raw_ptr).ok_or(AllocError)?; // SAFETY: `ptr->data` is a valid pinned location. - let Ok(()) =3D unsafe { value.__pinned_init(&raw mut (*raw_ptr).da= ta) }; + let Ok(()) =3D unsafe { value.__init(&raw mut (*raw_ptr).data) }; // INVARIANTS: We just created the vm_bo so it's absent from lists= , and the data is valid // as we just initialized it. Ok(GpuVmBoAlloc(ptr)) diff --git a/rust/kernel/init.rs b/rust/kernel/init.rs index 05a12e869a57..2afdccb67373 100644 --- a/rust/kernel/init.rs +++ b/rust/kernel/init.rs @@ -157,9 +157,8 @@ fn pin_init(init: impl PinInit, flags: Flags) = -> error::Result, { // SAFETY: We delegate to `init` and only change the error type. - let init =3D unsafe { - pin_init_from_closure(|slot| init.__pinned_init(slot).map_err(= |e| Error::from(e))) - }; + let init =3D + unsafe { pin_init_from_closure(|slot| init.__init(slot).map_er= r(|e| Error::from(e))) }; Self::try_pin_init(init, flags) } =20 @@ -175,9 +174,8 @@ fn init(init: impl Init, flags: Flags) -> erro= r::Result Error: From, { // SAFETY: We delegate to `init` and only change the error type. - let init =3D unsafe { - init_from_closure(|slot| init.__pinned_init(slot).map_err(|e| = Error::from(e))) - }; + let init =3D + unsafe { init_from_closure(|slot| init.__init(slot).map_err(|e= | Error::from(e))) }; Self::try_init(init, flags) } } diff --git a/rust/kernel/pwm.rs b/rust/kernel/pwm.rs index 6c9d667009ef..ed051c1780a1 100644 --- a/rust/kernel/pwm.rs +++ b/rust/kernel/pwm.rs @@ -600,7 +600,7 @@ pub fn new<'a>( let drvdata_ptr =3D unsafe { bindings::pwmchip_get_drvdata(c_chip_= ptr) }; =20 // SAFETY: We construct the `T` object in-place in the allocated p= rivate memory. - unsafe { data.__pinned_init(drvdata_ptr.cast()) }.inspect_err(|_| { + unsafe { data.__init(drvdata_ptr.cast()) }.inspect_err(|_| { // SAFETY: It is safe to call `pwmchip_put()` with a valid poi= nter obtained // from `pwmchip_alloc()`. We will not use pointer after this. unsafe { bindings::pwmchip_put(c_chip_ptr) } diff --git a/rust/kernel/sync/arc.rs b/rust/kernel/sync/arc.rs index 5ac4961b7cd2..c5200cc0bc51 100644 --- a/rust/kernel/sync/arc.rs +++ b/rust/kernel/sync/arc.rs @@ -727,7 +727,7 @@ fn write_pin_init(mut self, init: impl PinInit= ) -> Result( ) -> core::result::Result>, E> { // SAFETY: The supplied pointer is valid for initialization and we= will later pin the value // to ensure it does not move. - match unsafe { init.__pinned_init(self.as_mut_ptr()) } { + match unsafe { init.__init(self.as_mut_ptr()) } { // SAFETY: Initialization completed successfully. Ok(()) =3D> Ok(unsafe { self.assume_init() }.into()), Err(err) =3D> Err(err), diff --git a/rust/kernel/types.rs b/rust/kernel/types.rs index 699aabe01ee5..b769c80189df 100644 --- a/rust/kernel/types.rs +++ b/rust/kernel/types.rs @@ -426,7 +426,7 @@ fn pin_init(slot: impl PinInit) -> impl PinIni= t { // - `ptr` is a valid pointer to uninitialized memory, // - `slot` is not accessed on error, // - `slot` is pinned in memory. - unsafe { PinInit::::__pinned_init(slot, ptr) } + unsafe { PinInit::::__init(slot, ptr) } }) } } diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 025323fb030d..a922103b7e35 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -622,7 +622,7 @@ unsafe fn __init() -> ::kernel::ffi::c_int { // SAFETY: No data race, since `__MOD` can only be acc= essed by this module // and there only `__init` and `__exit` access it. The= se functions are only // called once and `__exit` cannot be called before or= during `__init`. - match unsafe { initer.__pinned_init(__MOD.as_mut_ptr()= ) } { + match unsafe { initer.__init(__MOD.as_mut_ptr()) } { Ok(m) =3D> 0, Err(e) =3D> e.to_errno(), } --=20 2.54.0 From nobody Fri Jul 24 22:54:26 2026 Received: from CWXP265CU010.outbound.protection.outlook.com (mail-ukwestazon11022085.outbound.protection.outlook.com [52.101.101.85]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6155D370D7B; Wed, 22 Jul 2026 18:50:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.101.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784746242; cv=fail; b=Pkap4koZgYwOIXS8LEppCAL1UUOUO/FKkCue0KrQtabyAT1f7k+7TUEqVMyJWwgKIU15M+tVmtooy6ZB3xXmhvhIyGvb77RRumATuICcGX1pdaW4JcVniKFBDeg4lalngK5LmkEDsTtQBB65ZezRsiUO1QjYLPjlst2iOQYTylk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784746242; c=relaxed/simple; bh=dNgYY/3Zqd0QAG8CgtBNJF1HAw83++tlV5uqE1m3ZKs=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=u/ZHmJ6TLUNfw+7KE/ezazBp5At4LsWkKgJTkiWuipNLsVCwpKXlhaQ+ZTDrtouYveCqAosnszwi5NvUtRfttERguf5vRCik3xd0/opoK8Org+b4LZaUpWIeQu0dIXixxP2wgZ7ehVSnQv0XtKt8B/3gOjaru+QKzLmKKdud968= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net; spf=pass smtp.mailfrom=garyguo.net; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b=KxOvVRG4; arc=fail smtp.client-ip=52.101.101.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=garyguo.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=garyguo.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=garyguo.net header.i=@garyguo.net header.b="KxOvVRG4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bq3pMYeDJ4TmAO6MZfRnOsolFumeZrJHeZm+WXoGVf9VGY6tbs8iebY2NNJ+uVLMi0zmL6AsGRWLqvZv6NSYj1jEKLno9v3QiVoCIAoVVcaraY+S0wsrkZI4N5sS7e3v7K1zAVxKSbQyzF0ln8tq9KlDZnVAHmFYXDYZY3EVFO/zVxZx/IQbvzlWaGNfyIV7OoY3Nwo1I+77kSOqJ7k3yE6HhKxXLbwPYbeLmQhCAb1WmSee3wsl3E42tzXRt9lyE4hmfuLEhtt4auOIAUYfKZQGaXK76EDm4Dq0epSK/vG9+vK/13h0KPddy8PwzeZsD4nKsDhrNB48tqYP3hwmsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eNa+AQImJQ07xH0dhu7ToPFVE6M4I5LRD/6nerpaFG8=; b=p3lXiflD+o8Z0eKnLDBkuXlgt5HJhvprYzU439ookRHOazQFHmFk6U09IM1jAnl6jI6A/p2Vn5LYkUZ8ga5qyFnobKnMztlcX6XIyIMomVTzhUlFjzS6PHNvpWQZihKH82j5PaLEcdMCvog7XTpjXphgyLik4eY4o6zScXSFxx6MgPPhHJP8ARw7F8+g0/ESrtNjbAzT57eVzjQ5Ocm51vFOTSqKCH9schcxQDETSYHv1YCz485B5tQnVrKYeb20yrl1bq3Wo5Sg/CE+9pS63ZoMRcs+ejo5esn3xKEGzwPJE6SQiAnDnMLTGO356MkaEQbkQYvECpvtaZ6wSkiC4Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=garyguo.net; dmarc=pass action=none header.from=garyguo.net; dkim=pass header.d=garyguo.net; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=garyguo.net; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eNa+AQImJQ07xH0dhu7ToPFVE6M4I5LRD/6nerpaFG8=; b=KxOvVRG4KYtiAhmFr7y6T68qjtIbt//YW9DcHCXrAQHx0Zxiv2l4djvyAM+EpdPM2Iqnki4sKBrGQdOBeYi3Z3G2KzQPJYfTwOKTySwrAOrO7XaE21/wEW+mr5lv1Ba/N64cK364E89aCiAJ8pVma28ZPv+tE5w0niuj2+EnUEs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=garyguo.net; Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) by CWXP265MB2471.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:9d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.245.10; Wed, 22 Jul 2026 18:50:36 +0000 Received: from LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986]) by LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM ([fe80::1c3:ceba:21b4:9986%4]) with mapi id 15.21.0223.017; Wed, 22 Jul 2026 18:50:36 +0000 From: Gary Guo Date: Wed, 22 Jul 2026 19:50:18 +0100 Subject: [PATCH 4/4] rust: pin-init: remove `__pinned_init` method for `cfg(kernel)` Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260722-merge-init-v1-4-d4594de76538@garyguo.net> References: <20260722-merge-init-v1-0-d4594de76538@garyguo.net> In-Reply-To: <20260722-merge-init-v1-0-d4594de76538@garyguo.net> To: Benno Lossin , Miguel Ojeda , Boqun Feng , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Gary Guo X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1784746228; l=917; i=gary@garyguo.net; s=20221204; h=from:subject:message-id; bh=dNgYY/3Zqd0QAG8CgtBNJF1HAw83++tlV5uqE1m3ZKs=; b=bCybW99wP7GIIoTKtVs4KrKi9ud2ZDiiRtr69A3cooDupkFUVgzAn5PJ197jw3/K/WQXQTi1Q sf435Z+e72BBxv+X0JFhw59W03bMCBuHBFXix1jSBSQqAZFpiaL+88B X-Developer-Key: i=gary@garyguo.net; a=ed25519; pk=vB3uIX95SM4eVrIqo1DWNWKDKD2xzB+yLLLr0yOPYMo= X-ClientProxiedBy: LO4P123CA0243.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a7::14) To LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:488::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: LOVP265MB8871:EE_|CWXP265MB2471:EE_ X-MS-Office365-Filtering-Correlation-Id: 80a81a8e-dee3-4943-0610-08dee8221a74 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|23010399003|10070799003|376014|7416014|1800799024|56012099006|10067099003|921020|6133799003|22082099003|18002099003; X-Microsoft-Antispam-Message-Info: 69c6JCJa3IDdQaLfoxGkyuM03TuLJChTWLB85qdwa+t7Obm0WibEWZm54RwU39l7y9RVLMmWiwv1it77iYbzjgX/f8tcfwckMemk3AnHfOm7kt4BodCw3DW7KNHgMIPFTUEGFsViSydY/tK6/nkHCz8SQXn6YlAxTe1tGmXSUqWMkW7IY1lZeHN17vmN+Csx8qC52WuEFNeFWih7sEvPYj6deGPscXdkAIsrRlqGFr1bSOnJxZk246ZxhjYP6vvpbxcffAfhDlRa7NlQJ4h9+ycc2CMUS74F9NVi46FjU5OLU46oh6/kbKPK/YpJzKVszHpHqqggoPcrAH2yiEAJGL/Ke6vYhQUdiwjiMwK78gB9VlqWKNWBXXqiVpiyumLfde9rYueiylDQX9qPPNy5l3qmUO+7odajFXrlxYEYL8My3kLCqirGHZYnJv6JVDCc1ZwIS0LeeOzXe9IbS8VuEMMlx6yA6Oy9HTyMFSdygbGCmqO7Y52jnOOyzlv7nQd+uaaS2UZzK2zQyA2bH/Ubu8HMfOJPzxnIn/lM06GvzO+3vzt3UAT4ZUrhm5Z4yVwhbDkh3z4Z+FNRpN2ljajbrxx8SNc7RccrvxixVTfTk6QHZy8Sy9xoz0SQ1eyDnq3yWLJCSQVv+yqvqOSsCWAU0rXYdqZvJ20T8GRqGDHRhHoClLgUtObRFBYsA2T8LvqTPBsJjG8VzquFDlFNi1HkrA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230040)(366016)(23010399003)(10070799003)(376014)(7416014)(1800799024)(56012099006)(10067099003)(921020)(6133799003)(22082099003)(18002099003);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?ZzZXQStHaHh6TU9PQXRWWVZMUVhJbGozaGxKZktSU2dWSDcvK3A0YUxXMmVk?= =?utf-8?B?L2ZsbGx1bDRPRk9OMHlyRVY4YXVXNU8vcHBzT1pJTVFqUXM2U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3VkTnBsNkcvbVRmMXdTSkoyaDh0RmJuU2d2Wldl?= =?utf-8?B?RFJxTHNYeHNWT0lmTXQzSHdDUlVaMEFpN1k1TnJDdVdWOWVibVZzd3lFeEtU?= =?utf-8?B?R2xVaXZneTRaVlR5L3c2NFRidHlNZ2V1V0RYMFdNakhJWDBHM3h4WktQNGdF?= =?utf-8?B?N1dyRkdxV0xCVmx1ZkRoVlErVnZIcG0xM0lCMTNYVmdkNlRPOVNqNWhqRUcr?= =?utf-8?B?WlpJSWVtYlVlVmF3dkJyUlFwTFduVUYvWUF0a0FzaGtxVVM1UDV0NDFvRXdr?= =?utf-8?B?YW9XN25Wamd0ZUtiYzZINW40WVRlVEYxdHlPd0p3VXRRNlZXaks3dFhkZUtH?= =?utf-8?B?RkxzV1Z2WGphR3dEd1lOUjB0dEhGMlNHTEpQcFFYVFNENVZMS0htemhPbjQ1?= =?utf-8?B?RHkwUE1uR1pGbUc0VzVESC9vb09Ub01lT2tuWGNHb0o3STFzR2p5QT09?= X-OriginatorOrg: garyguo.net X-MS-Exchange-CrossTenant-Network-Message-Id: 80a81a8e-dee3-4943-0610-08dee8221a74 X-MS-Exchange-CrossTenant-AuthSource: LOVP265MB8871.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Jul 2026 18:50:30.4050 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: bbc898ad-b10f-4e10-8552-d9377b823d45 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RHSHQfxlL/6lpuKFq4ZJYXPemv22t68imurY/pCXvaIqyya3IlVzrhw3ePD/m3831BKSqwDkQpjOBVh8+8wSrw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWXP265MB2471 Remove `__pinned_init` for kernel configuration, with all users gone. Still perserve it temporarily as deprecated so other users have time to move off it. Signed-off-by: Gary Guo --- rust/pin-init/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rust/pin-init/src/lib.rs b/rust/pin-init/src/lib.rs index 354fbefcf80e..c8c1d0184da4 100644 --- a/rust/pin-init/src/lib.rs +++ b/rust/pin-init/src/lib.rs @@ -917,7 +917,8 @@ pub unsafe trait PinInit: = Sized { /// /// Same as `__init`. #[inline(always)] - #[cfg_attr(not(kernel), deprecated =3D "use `__init` instead")] + #[cfg(not(kernel))] + #[deprecated =3D "use `__init` instead"] unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), E> { // SAFETY: Per safety requirement. unsafe { self.__init(slot) } --=20 2.54.0