Thread (21 messages) 21 messages, 3 authors, 2024-08-01

Re: [PATCH net-next v2 3/6] rust: net::phy implement AsRef<kernel::device::Device> trait

From: FUJITA Tomonori <fujita.tomonori@gmail.com>
Date: 2024-08-01 01:03:56
Also in: rust-for-linux

On Wed, 31 Jul 2024 10:38:11 +0200
Alice Ryhl [off-list ref] wrote:
quoted
+impl AsRef<kernel::device::Device> for Device {
+    fn as_ref(&self) -> &kernel::device::Device {
+        let phydev = self.0.get();
+        // SAFETY: The struct invariant ensures that we may access
+        // this field without additional synchronization.
+        unsafe { kernel::device::Device::as_ref(&mut (*phydev).mdio.dev) }
This is a case where I would recommend use of the `addr_of_mut!`
macro. The type of the mutable reference will be `&mut
bindings::device` without a `Opaque` wrapper around the referent, and
the lack of `Opaque` raises questions about uniqueness guarantees.
Using `addr_of_mut!` sidesteps those questions.

With `addr_of_mut!` and no intermediate mutable reference you may add:

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Understood. I will use addr_of_mut! in v3.

Thanks a lot!
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help