Skip to content

Commit 0bf626d

Browse files
Gnurouojeda
authored andcommitted
rust: inline some init methods
These methods should be inlined for optimization reasons. Failure to do so can also produce symbol names larger than what `modpost` or `objtool` can handle. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Gary Guo <gary@garyguo.net> Link: https://patch.msgid.link/20260605-nova-exports-v4-1-e948c287407c@nvidia.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 01504bc commit 0bf626d

3 files changed

Lines changed: 8 additions & 0 deletions

File tree

‎rust/kernel/alloc/kbox.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ where
437437
{
438438
type Initialized = Box<T, A>;
439439

440+
#[inline]
440441
fn write_init<E>(mut self, init: impl Init<T, E>) -> Result<Self::Initialized, E> {
441442
let slot = self.as_mut_ptr();
442443
// SAFETY: When init errors/panics, slot will get deallocated but not dropped,
@@ -446,6 +447,7 @@ where
446447
Ok(unsafe { Box::assume_init(self) })
447448
}
448449

450+
#[inline]
449451
fn write_pin_init<E>(mut self, init: impl PinInit<T, E>) -> Result<Pin<Self::Initialized>, E> {
450452
let slot = self.as_mut_ptr();
451453
// SAFETY: When init errors/panics, slot will get deallocated but not dropped,

‎rust/kernel/init.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ pub trait InPlaceInit<T>: Sized {
151151
/// type.
152152
///
153153
/// If `T: !Unpin` it will not be able to move afterwards.
154+
#[inline]
154155
fn pin_init<E>(init: impl PinInit<T, E>, flags: Flags) -> error::Result<Self::PinnedSelf>
155156
where
156157
Error: From<E>,
@@ -168,6 +169,7 @@ pub trait InPlaceInit<T>: Sized {
168169
E: From<AllocError>;
169170

170171
/// Use the given initializer to in-place initialize a `T`.
172+
#[inline]
171173
fn init<E>(init: impl Init<T, E>, flags: Flags) -> error::Result<Self>
172174
where
173175
Error: From<E>,

‎rust/kernel/sync/arc.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ impl<T> InPlaceInit<T> for UniqueArc<T> {
712712
impl<T> InPlaceWrite<T> for UniqueArc<MaybeUninit<T>> {
713713
type Initialized = UniqueArc<T>;
714714

715+
#[inline]
715716
fn write_init<E>(mut self, init: impl Init<T, E>) -> Result<Self::Initialized, E> {
716717
let slot = self.as_mut_ptr();
717718
// SAFETY: When init errors/panics, slot will get deallocated but not dropped,
@@ -721,6 +722,7 @@ impl<T> InPlaceWrite<T> for UniqueArc<MaybeUninit<T>> {
721722
Ok(unsafe { self.assume_init() })
722723
}
723724

725+
#[inline]
724726
fn write_pin_init<E>(mut self, init: impl PinInit<T, E>) -> Result<Pin<Self::Initialized>, E> {
725727
let slot = self.as_mut_ptr();
726728
// SAFETY: When init errors/panics, slot will get deallocated but not dropped,
@@ -782,6 +784,7 @@ impl<T> UniqueArc<MaybeUninit<T>> {
782784
}
783785

784786
/// Initialize `self` using the given initializer.
787+
#[inline]
785788
pub fn init_with<E>(mut self, init: impl Init<T, E>) -> core::result::Result<UniqueArc<T>, E> {
786789
// SAFETY: The supplied pointer is valid for initialization.
787790
match unsafe { init.__init(self.as_mut_ptr()) } {
@@ -792,6 +795,7 @@ impl<T> UniqueArc<MaybeUninit<T>> {
792795
}
793796

794797
/// Pin-initialize `self` using the given pin-initializer.
798+
#[inline]
795799
pub fn pin_init_with<E>(
796800
mut self,
797801
init: impl PinInit<T, E>,

0 commit comments

Comments
 (0)