diff options
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/Makefile | 2 | ||||
| -rw-r--r-- | rust/kernel/alloc/box_ext.rs | 6 | ||||
| -rw-r--r-- | rust/kernel/block/mq/gen_disk.rs | 6 | ||||
| -rw-r--r-- | rust/kernel/init/macros.rs | 4 | ||||
| -rw-r--r-- | rust/kernel/net/phy.rs | 2 | ||||
| -rw-r--r-- | rust/macros/module.rs | 6 | 
6 files changed, 15 insertions, 11 deletions
diff --git a/rust/Makefile b/rust/Makefile index 8de3ebba9551..f168d2c98a15 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -305,7 +305,7 @@ $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers.c FORCE  quiet_cmd_exports = EXPORTS $@        cmd_exports = \  	$(NM) -p --defined-only $< \ -		| awk '/ (T|R|D) / {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@ +		| awk '/ (T|R|D|B) / {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@  $(obj)/exports_core_generated.h: $(obj)/core.o FORCE  	$(call if_changed,exports) diff --git a/rust/kernel/alloc/box_ext.rs b/rust/kernel/alloc/box_ext.rs index 829cb1c1cf9e..9f1c1c489189 100644 --- a/rust/kernel/alloc/box_ext.rs +++ b/rust/kernel/alloc/box_ext.rs @@ -21,8 +21,10 @@ pub trait BoxExt<T>: Sized {  impl<T> BoxExt<T> for Box<T> {      fn new(x: T, flags: Flags) -> Result<Self, AllocError> { -        let b = <Self as BoxExt<_>>::new_uninit(flags)?; -        Ok(Box::write(b, x)) +        let mut b = <Self as BoxExt<_>>::new_uninit(flags)?; +        b.write(x); +        // SAFETY: We just wrote to it. +        Ok(unsafe { b.assume_init() })      }      #[cfg(any(test, testlib))] diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_disk.rs index f548a6199847..708125dce96a 100644 --- a/rust/kernel/block/mq/gen_disk.rs +++ b/rust/kernel/block/mq/gen_disk.rs @@ -6,8 +6,8 @@  //! C header: [`include/linux/blk_mq.h`](srctree/include/linux/blk_mq.h)  use crate::block::mq::{raw_writer::RawWriter, Operations, TagSet}; -use crate::error;  use crate::{bindings, error::from_err_ptr, error::Result, sync::Arc}; +use crate::{error, static_lock_class};  use core::fmt::{self, Write};  /// A builder for [`GenDisk`]. @@ -93,8 +93,6 @@ impl GenDiskBuilder {          name: fmt::Arguments<'_>,          tagset: Arc<TagSet<T>>,      ) -> Result<GenDisk<T>> { -        let lock_class_key = crate::sync::LockClassKey::new(); -          // SAFETY: `bindings::queue_limits` contain only fields that are valid when zeroed.          let mut lim: bindings::queue_limits = unsafe { core::mem::zeroed() }; @@ -110,7 +108,7 @@ impl GenDiskBuilder {                  tagset.raw_tag_set(),                  &mut lim,                  core::ptr::null_mut(), -                lock_class_key.as_ptr(), +                static_lock_class!().as_ptr(),              )          })?; diff --git a/rust/kernel/init/macros.rs b/rust/kernel/init/macros.rs index 02ecedc4ae7a..9a0c4650ef67 100644 --- a/rust/kernel/init/macros.rs +++ b/rust/kernel/init/macros.rs @@ -145,7 +145,7 @@  //!         }  //!     }  //!     // Implement the internal `PinData` trait that marks the pin-data struct as a pin-data -//!     // struct. This is important to ensure that no user can implement a rouge `__pin_data` +//!     // struct. This is important to ensure that no user can implement a rogue `__pin_data`  //!     // function without using `unsafe`.  //!     unsafe impl<T> ::kernel::init::__internal::PinData for __ThePinData<T> {  //!         type Datee = Bar<T>; @@ -156,7 +156,7 @@  //!     // case no such fields exist, hence this is almost empty. The two phantomdata fields exist  //!     // for two reasons:  //!     // - `__phantom`: every generic must be used, since we cannot really know which generics -//!     //   are used, we declere all and then use everything here once. +//!     //   are used, we declare all and then use everything here once.  //!     // - `__phantom_pin`: uses the `'__pin` lifetime and ensures that this struct is invariant  //!     //   over it. The lifetime is needed to work around the limitation that trait bounds must  //!     //   not be trivial, e.g. the user has a `#[pin] PhantomPinned` field -- this is diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs index fd40b703d224..91dac63ffa17 100644 --- a/rust/kernel/net/phy.rs +++ b/rust/kernel/net/phy.rs @@ -491,7 +491,7 @@ impl<T: Driver> Adapter<T> {  pub struct DriverVTable(Opaque<bindings::phy_driver>);  // SAFETY: `DriverVTable` doesn't expose any &self method to access internal data, so it's safe to -// share `&DriverVTable` across execution context boundries. +// share `&DriverVTable` across execution context boundaries.  unsafe impl Sync for DriverVTable {}  /// Creates a [`DriverVTable`] instance from [`Driver`]. diff --git a/rust/macros/module.rs b/rust/macros/module.rs index 411dc103d82e..7a5b899e47b7 100644 --- a/rust/macros/module.rs +++ b/rust/macros/module.rs @@ -217,7 +217,11 @@ pub(crate) fn module(ts: TokenStream) -> TokenStream {              // freed until the module is unloaded.              #[cfg(MODULE)]              static THIS_MODULE: kernel::ThisModule = unsafe {{ -                kernel::ThisModule::from_ptr(&kernel::bindings::__this_module as *const _ as *mut _) +                extern \"C\" {{ +                    static __this_module: kernel::types::Opaque<kernel::bindings::module>; +                }} + +                kernel::ThisModule::from_ptr(__this_module.get())              }};              #[cfg(not(MODULE))]              static THIS_MODULE: kernel::ThisModule = unsafe {{  | 
