rust: device_id: replace possible incorrect word in safety document
Subsystems (4)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/3 rust: device_id: replace possible incorrect word in safety document
The safety documentation incorrectly refers to RawDeviceId when transmuting to RawType. This fixes the documentation to correctly indicate that implementers must ensure layout compatibility with RawType, not RawDeviceId.
--- rust/kernel/device_id.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
rust/kernel/device_id.rs +1 -1
@@ -15,7 +15,7 @@/// # Safety /// /// Implementers must ensure that `Self` is layout-compatible with [`RawDeviceId::RawType`]; -/// i.e. it's safe to transmute to `RawDeviceId`. +/// i.e. it's safe to transmute to `RawType`. /// /// This requirement is needed so `IdArray::new` can convert `Self` to `RawType` when building /// the ID table.
Signature · 1 line
2.34.1
PATCH 2/3 rust: dma: remove incorrect safety documentation
In reply to a message not in the archiveRemoves a safety requirement that incorrectly states callers must ensure the device does not access memory while the returned slice is live, as this method doesn't return a slice.
--- rust/kernel/dma.rs | 2 -- 1 file changed, 2 deletions(-)
rust/kernel/dma.rs +0 -2
@@ -532,8 +532,6 @@ pub unsafe fn as_slice_mut(&mut self, offset: usize, count: usize) -> Result<&mu/// /// # Safety /// -/// * Callers must ensure that the device does not read/write to/from memory while the returned -/// slice is live. /// * Callers must ensure that this call does not race with a read or write to the same region /// that overlaps with this write. ///
Signature · 1 line
2.34.1
PATCH 3/3 rust: cpumask: rename methods of Cpumask for clarity and consistency
In reply to a message not in the archiveRename as_ref and as_mut_ref to from_raw and from_raw_mut to align with the established naming convention for constructing types from raw pointers in the kernel's Rust codebase.
--- rust/kernel/cpumask.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
rust/kernel/cpumask.rs +5 -5
@@ -39,7 +39,7 @@/// fn set_clear_cpu(ptr: *mut bindings::cpumask, set_cpu: CpuId, clear_cpu: CpuId) { /// // SAFETY: The `ptr` is valid for writing and remains valid for the lifetime of the /// // returned reference. -/// let mask = unsafe { Cpumask::as_mut_ref(ptr) }; +/// let mask = unsafe { Cpumask::from_raw_mut(ptr) }; /// /// mask.set(set_cpu); /// mask.clear(clear_cpu);
@@ -49,13 +49,13 @@pub struct Cpumask (Opaque <bindings::cpumask >);impl Cpumask { -/// Creates a mutable reference to an existing `struct cpumask` pointer. +/// Creates a mutable reference from an existing `struct cpumask` pointer. /// /// # Safety /// /// The caller must ensure that `ptr` is valid for writing and remains valid for the lifetime /// of the returned reference. -pub unsafe fn as_mut_ref <'a>(ptr: *mut bindings::cpumask ) -> &'amut Self { +pub unsafe fn from_raw_mut <'a>(ptr: *mut bindings::cpumask ) -> &'amut Self {// SAFETY: Guaranteed by the safety requirements of the function. // // INVARIANT: The caller ensures that `ptr` is valid for writing and remains valid for the
@@ -63,13 +63,13 @@ pub unsafe fn as_mut_ref<'a>(ptr: *mut bindings::cpumask) -> &'a mut Self {unsafe { &mut *ptr.cast () } } -/// Creates a reference to an existing `struct cpumask` pointer. +/// Creates a reference from an existing `struct cpumask` pointer. /// /// # Safety /// /// The caller must ensure that `ptr` is valid for reading and remains valid for the lifetime /// of the returned reference. -pub unsafe fn as_ref <'a>(ptr: *const bindings::cpumask ) -> &'aSelf { +pub unsafe fn from_raw <'a>(ptr: *const bindings::cpumask ) -> &'aSelf {// SAFETY: Guaranteed by the safety requirements of the function. // // INVARIANT: The caller ensures that `ptr` is valid for reading and remains valid for the
Signature · 1 line
2.34.1
Re: [PATCH 3/3] rust: cpumask: rename methods of Cpumask for clarity and consistency
Quoted 5 lines · yilin
Rename
as_refandas_mut_reftofrom_rawandfrom_raw_mutto align with the established naming convention for constructing types from raw pointers in the kernel's Rust codebase.Signed-off-by yilin <[email protected]>
You need to use a real identity such as your real name here. Please see:
https://docs.kernel.org/process/submitting-patches.html#reviewer-s-statement-of-oversight
You should probably also split this series up, as the patches are for unrelated subsystem.s
The change itself looks good:
Quoted 51 lines
rust/kernel/cpumask.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)rust/kernel/cpumask.rs +5
-5@@ -39,7 +39,7 @@/// fn set_clear_cpu(ptr: *mut bindings::cpumask, set_cpu: CpuId, clear_cpu: CpuId) { /// // SAFETY: The `ptr` is valid for writing and remains valid for the lifetime of the /// // returned reference. -/// let mask = unsafe { Cpumask::as_mut_ref(ptr) }; +/// let mask = unsafe { Cpumask::from_raw_mut(ptr) }; /// /// mask.set(set_cpu); /// mask.clear(clear_cpu); @@ -49,13 +49,13 @@pub struct Cpumask (Opaque <bindings::cpumask >);impl Cpumask { -/// Creates a mutable reference to an existing `struct cpumask` pointer. +/// Creates a mutable reference from an existing `struct cpumask` pointer. /// /// # Safety /// /// The caller must ensure that `ptr` is valid for writing and remains valid for the lifetime /// of the returned reference. -pub unsafe fn as_mut_ref <'a>(ptr: *mut bindings::cpumask ) -> &'amut Self { +pub unsafe fn from_raw_mut <'a>(ptr: *mut bindings::cpumask ) -> &'amut Self {// SAFETY: Guaranteed by the safety requirements of the function. // // INVARIANT: The caller ensures that `ptr` is valid for writing and remains valid for the @@ -63,13 +63,13 @@ pub unsafe fn as_mut_ref<'a>(ptr: *mut bindings::cpumask) -> &'a mut Self {unsafe { &mut *ptr.cast () } } -/// Creates a reference to an existing `struct cpumask` pointer. +/// Creates a reference from an existing `struct cpumask` pointer. /// /// # Safety /// /// The caller must ensure that `ptr` is valid for reading and remains valid for the lifetime /// of the returned reference. -pub unsafe fn as_ref <'a>(ptr: *const bindings::cpumask ) -> &'aSelf { +pub unsafe fn from_raw <'a>(ptr: *const bindings::cpumask ) -> &'aSelf {// SAFETY: Guaranteed by the safety requirements of the function. // // INVARIANT: The caller ensures that `ptr` is valid for reading and remains valid for the Signature · 1 line
2.34.1