Subject: linux-next: manual merge of the driver-core tree with the rust-alloc tree

From: Mark Brown <[email-masked]>
Date: Thu, 21 May 2026 13:07:54 +0100

Hi all,

Today's linux-next merge of the driver-core tree got a conflict in:

  rust/kernel/alloc/kbox.rs

between commit:

  9b25d4111e913 ("rust: alloc: cleanup imports and use "kernel vertical" style")

from the rust-alloc tree and commit:

  abb21500e7e5d ("rust: alloc: add Box::zeroed()")

from the driver-core tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

diff --combined rust/kernel/alloc/kbox.rs
index 31b2588ed5bf9,c824ed6e15233..0000000000000
--- a/rust/kernel/alloc/kbox.rs
+++ b/rust/kernel/alloc/kbox.rs
@@@ -3,47 -3,25 +3,47 @@@
  //! Implementation of [`Box`].
  
  #[allow(unused_imports)] // Used in doc comments.
 -use super::allocator::{KVmalloc, Kmalloc, Vmalloc, VmallocPageIter};
 -use super::{AllocError, Allocator, Flags, NumaNode};
 -use core::alloc::Layout;
 -use core::borrow::{Borrow, BorrowMut};
 -use core::marker::PhantomData;
 -use core::mem::ManuallyDrop;
 -use core::mem::MaybeUninit;
 -use core::ops::{Deref, DerefMut};
 -use core::pin::Pin;
 -use core::ptr::NonNull;
 -use core::result::Result;
 +use super::allocator::{
 +    KVmalloc,
 +    Kmalloc,
 +    Vmalloc,
 +    VmallocPageIter, //
 +};
  
 -use crate::ffi::c_void;
 -use crate::fmt;
 -use crate::init::InPlaceInit;
 -use crate::page::AsPageIter;
 -use crate::prelude::*;
 -use crate::types::ForeignOwnable;
 -use pin_init::{InPlaceWrite, Init, PinInit, ZeroableOption};
 +use super::{
 +    AllocError,
 +    Allocator,
 +    Flags,
 +    NumaNode, //
 +};
 +
 +use crate::{
 +    fmt,
 +    page::AsPageIter,
 +    prelude::*,
 +    types::ForeignOwnable, //
 +};
 +
 +use core::{
 +    alloc::Layout,
 +    borrow::{
 +        Borrow,
 +        BorrowMut, //
 +    },
 +    marker::PhantomData,
 +    mem::{
 +        ManuallyDrop,
 +        MaybeUninit, //
 +    },
 +    ops::{
 +        Deref,
 +        DerefMut, //
 +    },
 +    ptr::NonNull,
 +    result::Result, //
 +};
 +
 +use pin_init::ZeroableOption;
  
  /// The kernel's [`Box`] type -- a heap allocation for a single value of type `T`.
  ///
@@@ -279,6 -257,27 +279,27 @@@ wher
          Ok(Box(ptr.cast(), PhantomData))
      }
  
+     /// Creates a new zero-initialized `Box<T, A>`.
+     ///
+     /// New memory is allocated with `A` and the [`__GFP_ZERO`] flag. The allocation may fail, in
+     /// which case an error is returned. For ZSTs no memory is allocated.
+     ///
+     /// # Examples
+     ///
+     /// ```
+     /// let b = KBox::<[u8; 128]>::zeroed(GFP_KERNEL)?;
+     /// assert_eq!(*b, [0; 128]);
+     /// # Ok::<(), Error>(())
+     /// ```
+     pub fn zeroed(flags: Flags) -> Result<Self, AllocError>
+     where
+         T: Zeroable,
+     {
+         // SAFETY: `__GFP_ZERO` guarantees the memory is zeroed; `T: Zeroable` guarantees that
+         // all-zeroes is a valid bit pattern for `T`.
+         Ok(unsafe { Self::new_uninit(flags | __GFP_ZERO)?.assume_init() })
+     }
+ 
      /// Constructs a new `Pin<Box<T, A>>`. If `T` does not implement [`Unpin`], then `x` will be
      /// pinned in memory and can't be moved.
      #[inline]
@@@ -297,10 -296,7 +318,10 @@@
      /// # Examples
      ///
      /// ```
 -    /// use kernel::sync::{new_spinlock, SpinLock};
 +    /// use kernel::sync::{
 +    ///     new_spinlock,
 +    ///     SpinLock, //
 +    /// };
      ///
      /// struct Inner {
      ///     a: u32,
@@@ -593,6 -589,7 +614,6 @@@ wher
  ///
  /// ```
  /// # use core::borrow::Borrow;
 -/// # use kernel::alloc::KBox;
  /// struct Foo<B: Borrow<u32>>(B);
  ///
  /// // Owned instance.
@@@ -620,6 -617,7 +641,6 @@@ wher
  ///
  /// ```
  /// # use core::borrow::BorrowMut;
 -/// # use kernel::alloc::KBox;
  /// struct Foo<B: BorrowMut<u32>>(B);
  ///
  /// // Owned instance.
@@@ -684,13 -682,9 +705,13 @@@ wher
  /// # Examples
  ///
  /// ```
 -/// # use kernel::prelude::*;
 -/// use kernel::alloc::allocator::VmallocPageIter;
 -/// use kernel::page::{AsPageIter, PAGE_SIZE};
 +/// use kernel::{
 +///     alloc::allocator::VmallocPageIter,
 +///     page::{
 +///         AsPageIter,
 +///         PAGE_SIZE, //
 +///     }, //
 +/// };
  ///
  /// let mut vbox = VBox::new((), GFP_KERNEL)?;
  ///