diff mbox series

[v2,1/5] rust: phy: implement `Send` for `Registration`

Message ID 20240328195457.225001-2-wedsonaf@gmail.com (mailing list archive)
State Not Applicable
Headers show
Series [v2,1/5] rust: phy: implement `Send` for `Registration` | expand

Commit Message

Wedson Almeida Filho March 28, 2024, 7:54 p.m. UTC
From: Wedson Almeida Filho <walmeida@microsoft.com>

In preparation for requiring `Send` for `Module` implementations in the
next patch.

Cc: FUJITA Tomonori <fujita.tomonori@gmail.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: netdev@vger.kernel.org
Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com>
---
 rust/kernel/net/phy.rs | 4 ++++
 1 file changed, 4 insertions(+)

Comments

FUJITA Tomonori March 29, 2024, 12:53 a.m. UTC | #1
Hi,

On Thu, 28 Mar 2024 16:54:53 -0300
Wedson Almeida Filho <wedsonaf@gmail.com> wrote:

> From: Wedson Almeida Filho <walmeida@microsoft.com>
> 
> In preparation for requiring `Send` for `Module` implementations in the
> next patch.
> 
> Cc: FUJITA Tomonori <fujita.tomonori@gmail.com>
> Cc: Trevor Gross <tmgross@umich.edu>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com>
> ---
>  rust/kernel/net/phy.rs | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
> index 96e09c6e8530..265d0e1c1371 100644
> --- a/rust/kernel/net/phy.rs
> +++ b/rust/kernel/net/phy.rs
> @@ -640,6 +640,10 @@ pub struct Registration {
>      drivers: Pin<&'static mut [DriverVTable]>,
>  }
>  
> +// SAFETY: The only action allowed in a `Registration` instance is dropping it, which is safe to do
> +// from any thread because `phy_drivers_unregister` can be called from any thread context.
> +unsafe impl Send for Registration {}
> +
>  impl Registration {
>      /// Registers a PHY driver.
>      pub fn register(

After the following discussion, I dropped Send for Registration:

https://lore.kernel.org/netdev/8f476b7c-4647-457b-ab45-d6a979da4e78@lunn.ch/T/

If you guys think that Send can be added here, it's fine by me.


Once this In-place module series are merged, I'll revisit the phy
module initialization to remove `static mut DRIVERS`.
Alice Ryhl April 4, 2024, 12:46 p.m. UTC | #2
On Thu, Mar 28, 2024 at 8:55 PM Wedson Almeida Filho <wedsonaf@gmail.com> wrote:
>
> From: Wedson Almeida Filho <walmeida@microsoft.com>
>
> In preparation for requiring `Send` for `Module` implementations in the
> next patch.
>
> Cc: FUJITA Tomonori <fujita.tomonori@gmail.com>
> Cc: Trevor Gross <tmgross@umich.edu>
> Cc: netdev@vger.kernel.org
> Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
diff mbox series

Patch

diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
index 96e09c6e8530..265d0e1c1371 100644
--- a/rust/kernel/net/phy.rs
+++ b/rust/kernel/net/phy.rs
@@ -640,6 +640,10 @@  pub struct Registration {
     drivers: Pin<&'static mut [DriverVTable]>,
 }
 
+// SAFETY: The only action allowed in a `Registration` instance is dropping it, which is safe to do
+// from any thread because `phy_drivers_unregister` can be called from any thread context.
+unsafe impl Send for Registration {}
+
 impl Registration {
     /// Registers a PHY driver.
     pub fn register(