diff mbox series

[net-next,v2] rust: net::phy scope ThisModule usage in the module_phy_driver macro

Message ID 20241214194242.19505-1-sergeantsagara@protonmail.com (mailing list archive)
State Accepted
Commit d22f955cc2cb9684dd45396f974101f288869485
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v2] rust: net::phy scope ThisModule usage in the module_phy_driver macro | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 8 maintainers not CCed: a.hindborg@kernel.org boqun.feng@gmail.com bjorn3_gh@protonmail.com gary@garyguo.net benno.lossin@proton.me tmgross@umich.edu alex.gaynor@gmail.com ojeda@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 16 lines checked
netdev/build_clang_rust fail Link
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-12-15--09-00 (tests: 795)

Commit Message

Rahul Rameshbabu Dec. 14, 2024, 7:43 p.m. UTC
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(-)


base-commit: 9bc5c9515b4817e994579b21c32c033cbb3b0e6c

Comments

patchwork-bot+netdevbpf@kernel.org Dec. 17, 2024, 12:40 p.m. UTC | #1
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!
diff mbox series

Patch

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 };