diff mbox series

[net-next,v1] rust: net::phy always define device_table in module_phy_driver macro

Message ID 20240930134038.1309-1-fujita.tomonori@gmail.com (mailing list archive)
State Accepted
Commit 3ed8d344e061f382069c27705543c1882aca468a
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v1] rust: net::phy always define device_table in 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: 9 this patch: 9
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 7 maintainers not CCed: bjorn3_gh@protonmail.com a.hindborg@kernel.org gary@garyguo.net benno.lossin@proton.me ojeda@kernel.org boqun.feng@gmail.com alex.gaynor@gmail.com
netdev/build_clang success Errors and warnings before: 9 this patch: 9
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 fail Errors and warnings before: 13 this patch: 12
netdev/checkpatch warning WARNING: line length of 100 exceeds 80 columns WARNING: line length of 82 exceeds 80 columns WARNING: line length of 86 exceeds 80 columns
netdev/build_clang_rust fail Errors and warnings before: 13 this patch: 12
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

FUJITA Tomonori Sept. 30, 2024, 1:40 p.m. UTC
device_table in module_phy_driver macro is defined only when the
driver is built as a module. So a PHY driver imports phy::DeviceId
module in the following way then hits `unused import` warning when
it's compiled as built-in:

 use kernel::net::phy::DeviceId;

 kernel::module_phy_driver! {
     drivers: [PhyQT2025],
     device_table: [
        DeviceId::new_with_driver::<PhyQT2025>(),
     ],

Put device_table in a const. It's not included in the kernel image if
unused (when the driver is compiled as built-in), and the compiler
doesn't complain.

Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
 rust/kernel/net/phy.rs | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)


base-commit: c824deb1a89755f70156b5cdaf569fca80698719

Comments

Alice Ryhl Sept. 30, 2024, 1:49 p.m. UTC | #1
On Mon, Sep 30, 2024 at 3:41 PM FUJITA Tomonori
<fujita.tomonori@gmail.com> wrote:
>
> device_table in module_phy_driver macro is defined only when the
> driver is built as a module. So a PHY driver imports phy::DeviceId
> module in the following way then hits `unused import` warning when
> it's compiled as built-in:
>
>  use kernel::net::phy::DeviceId;
>
>  kernel::module_phy_driver! {
>      drivers: [PhyQT2025],
>      device_table: [
>         DeviceId::new_with_driver::<PhyQT2025>(),
>      ],
>
> Put device_table in a const. It's not included in the kernel image if
> unused (when the driver is compiled as built-in), and the compiler
> doesn't complain.
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
patchwork-bot+netdevbpf@kernel.org Oct. 4, 2024, midnight UTC | #2
Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 30 Sep 2024 13:40:37 +0000 you wrote:
> device_table in module_phy_driver macro is defined only when the
> driver is built as a module. So a PHY driver imports phy::DeviceId
> module in the following way then hits `unused import` warning when
> it's compiled as built-in:
> 
>  use kernel::net::phy::DeviceId;
> 
> [...]

Here is the summary with links:
  - [net-next,v1] rust: net::phy always define device_table in module_phy_driver macro
    https://git.kernel.org/netdev/net-next/c/3ed8d344e061

You are awesome, thank you!
diff mbox series

Patch

diff --git a/rust/kernel/net/phy.rs b/rust/kernel/net/phy.rs
index 910ce867480a..801907fba199 100644
--- a/rust/kernel/net/phy.rs
+++ b/rust/kernel/net/phy.rs
@@ -848,9 +848,7 @@  const fn as_int(&self) -> u32 {
 ///     }
 /// };
 ///
-/// #[cfg(MODULE)]
-/// #[no_mangle]
-/// static __mod_mdio__phydev_device_table: [::kernel::bindings::mdio_device_id; 2] = [
+/// const _DEVICE_TABLE: [::kernel::bindings::mdio_device_id; 2] = [
 ///     ::kernel::bindings::mdio_device_id {
 ///         phy_id: 0x00000001,
 ///         phy_id_mask: 0xffffffff,
@@ -860,6 +858,9 @@  const fn as_int(&self) -> u32 {
 ///         phy_id_mask: 0,
 ///     },
 /// ];
+/// #[cfg(MODULE)]
+/// #[no_mangle]
+/// static __mod_mdio__phydev_device_table: [::kernel::bindings::mdio_device_id; 2] = _DEVICE_TABLE;
 /// ```
 #[macro_export]
 macro_rules! module_phy_driver {
@@ -871,9 +872,7 @@  macro_rules! module_phy_driver {
 
     (@device_table [$($dev:expr),+]) => {
         // SAFETY: C will not read off the end of this constant since the last element is zero.
-        #[cfg(MODULE)]
-        #[no_mangle]
-        static __mod_mdio__phydev_device_table: [$crate::bindings::mdio_device_id;
+        const _DEVICE_TABLE: [$crate::bindings::mdio_device_id;
             $crate::module_phy_driver!(@count_devices $($dev),+) + 1] = [
             $($dev.mdio_device_id()),+,
             $crate::bindings::mdio_device_id {
@@ -881,6 +880,11 @@  macro_rules! module_phy_driver {
                 phy_id_mask: 0
             }
         ];
+
+        #[cfg(MODULE)]
+        #[no_mangle]
+        static __mod_mdio__phydev_device_table: [$crate::bindings::mdio_device_id;
+            $crate::module_phy_driver!(@count_devices $($dev),+) + 1] = _DEVICE_TABLE;
     };
 
     (drivers: [$($driver:ident),+ $(,)?], device_table: [$($dev:expr),+ $(,)?], $($f:tt)*) => {