netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v2] rust: net::phy scope ThisModule usage in the module_phy_driver macro
@ 2024-12-14 19:43 Rahul Rameshbabu
  2024-12-17 12:40 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Rahul Rameshbabu @ 2024-12-14 19:43 UTC (permalink / raw)
  To: netdev, rust-for-linux
  Cc: Eric Dumazet, Paolo Abeni, Jakub Kicinski, David S. Miller,
	Andrew Lunn, Rahul Rameshbabu, FUJITA Tomonori, Alice Ryhl

Similar to the use of $crate::Module, ThisModule should be referred to as
$crate::ThisModule in the macro evaluation. The reason the macro previously
did not cause any errors is because all the users of the macro would use
kernel::prelude::*, bringing ThisModule into scope.

Signed-off-by: Rahul Rameshbabu <sergeantsagara@protonmail.com>
Reviewed-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
---

Notes:
    Notes:
        v1->v2:
            Dropped the Fixes: tag and target net-next.
    
        How I came up with this change:
    
            I was working on my own rust bindings and rust driver when I compared my
            macro_rule to the one used for module_phy_driver. I noticed, if I made a
            driver that does not use kernel::prelude::*, that the ThisModule type
            identifier used in the macro would cause an error without being scoped in
            the macro_rule. I believe the correct implementation for the macro is one
            where the types used are correctly expanded with needed scopes.

 rust/kernel/net/phy.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
index b89c681d97c0..00c3100f5ebd 100644
--- a/rust/kernel/net/phy.rs
+++ b/rust/kernel/net/phy.rs
@@ -837,7 +837,7 @@ const fn as_int(&self) -> u32 {
 ///         [::kernel::net::phy::create_phy_driver::<PhySample>()];
 ///
 ///     impl ::kernel::Module for Module {
-///         fn init(module: &'static ThisModule) -> Result<Self> {
+///         fn init(module: &'static ::kernel::ThisModule) -> Result<Self> {
 ///             let drivers = unsafe { &mut DRIVERS };
 ///             let mut reg = ::kernel::net::phy::Registration::register(
 ///                 module,
@@ -903,7 +903,7 @@ struct Module {
                 [$($crate::net::phy::create_phy_driver::<$driver>()),+];
 
             impl $crate::Module for Module {
-                fn init(module: &'static ThisModule) -> Result<Self> {
+                fn init(module: &'static $crate::ThisModule) -> Result<Self> {
                     // SAFETY: The anonymous constant guarantees that nobody else can access
                     // the `DRIVERS` static. The array is used only in the C side.
                     let drivers = unsafe { &mut DRIVERS };

base-commit: 9bc5c9515b4817e994579b21c32c033cbb3b0e6c
-- 
2.44.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next v2] rust: net::phy scope ThisModule usage in the module_phy_driver macro
  2024-12-14 19:43 [PATCH net-next v2] rust: net::phy scope ThisModule usage in the module_phy_driver macro Rahul Rameshbabu
@ 2024-12-17 12:40 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-12-17 12:40 UTC (permalink / raw)
  To: Rahul Rameshbabu
  Cc: netdev, rust-for-linux, edumazet, pabeni, kuba, davem, andrew,
	fujita.tomonori, aliceryhl

Hello:

This patch was applied to netdev/net-next.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Sat, 14 Dec 2024 19:43:06 +0000 you wrote:
> Similar to the use of $crate::Module, ThisModule should be referred to as
> $crate::ThisModule in the macro evaluation. The reason the macro previously
> did not cause any errors is because all the users of the macro would use
> kernel::prelude::*, bringing ThisModule into scope.
> 
> Signed-off-by: Rahul Rameshbabu <sergeantsagara@protonmail.com>
> Reviewed-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
> Reviewed-by: Alice Ryhl <aliceryhl@google.com>
> 
> [...]

Here is the summary with links:
  - [net-next,v2] rust: net::phy scope ThisModule usage in the module_phy_driver macro
    https://git.kernel.org/netdev/net-next/c/d22f955cc2cb

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-17 12:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-14 19:43 [PATCH net-next v2] rust: net::phy scope ThisModule usage in the module_phy_driver macro Rahul Rameshbabu
2024-12-17 12:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).