lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLggzkjHE+NY_gLzcmwSeQ5MFYXMYU-nqX7=R7RF4WLosug@mail.gmail.com>
Date: Fri, 20 Sep 2024 18:00:56 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: FUJITA Tomonori <fujita.tomonori@...il.com>
Cc: netdev@...r.kernel.org, rust-for-linux@...r.kernel.org, andrew@...n.ch, 
	tmgross@...ch.edu, lkp@...el.com
Subject: Re: [PATCH net] net: phy: qt2025: Fix warning: unused import DeviceId

On Fri, Sep 20, 2024 at 3:53 PM FUJITA Tomonori
<fujita.tomonori@...il.com> wrote:
>
> Hi,
>
> On Thu, 19 Sep 2024 08:17:42 +0200
> Alice Ryhl <aliceryhl@...gle.com> wrote:
>
> > On Thu, Sep 19, 2024 at 6:39 AM FUJITA Tomonori
> > <fujita.tomonori@...il.com> wrote:
> >>
> >> Fix the following warning when the driver is compiled as built-in:
> >>
> >> >> warning: unused import: `DeviceId`
> >>    --> drivers/net/phy/qt2025.rs:18:5
> >>    |
> >>    18 |     DeviceId, Driver,
> >>    |     ^^^^^^^^
> >>    |
> >>    = note: `#[warn(unused_imports)]` on by default
> >>
> >> device_table in module_phy_driver macro is defined only when the
> >> driver is built as module. Use an absolute module path in the macro
> >> instead of importing `DeviceId`.
> >>
> >> Reported-by: kernel test robot <lkp@...el.com>
> >> Closes: https://lore.kernel.org/oe-kbuild-all/202409190717.i135rfVo-lkp@intel.com/
> >> Signed-off-by: FUJITA Tomonori <fujita.tomonori@...il.com>
> >
> > It may be nice to change the macro to always use the expression so
> > that this warning doesn't happen again.
>
> Like the C code does, a valuable is defined only when the driver is
> built as module because the valuable is used to create the information
> for module loading. So the macro adds `#[cfg(MODULE)]` like the
> following:
>
> #[cfg(MODULE)]
> #[no_mangle]
> static __mod_mdio__phydev_device_table: [::kernel::bindings::mdio_device_id; 2] = [
>     ::kernel::bindings::mdio_device_id {
>         phy_id: 0x00000001,
>         phy_id_mask: 0xffffffff,
>     },
>     ::kernel::bindings::mdio_device_id {
>         phy_id: 0,
>         phy_id_mask: 0,
>     },
> ];
>
> We can remove `#[cfg(MODULE)]` however an unused valuable to added to
> the kernel image when the driver is compiled as built-in. Seems that
> with `#[no_mangle]`, the compiler doesn't give a warning about unused
> valuable though.
>
> Is there a nice way to handle such case?

Put it in a const. That way it doesn't end up in the image if unused.

const _TABLE_INIT: [::kernel::bindings::mdio_device_id; 2] = [
    ::kernel::bindings::mdio_device_id {
        phy_id: 0x00000001,
        phy_id_mask: 0xffffffff,
    },
    ::kernel::bindings::mdio_device_id {
        phy_id: 0,
        phy_id_mask: 0,
    },
];

#[cfg(MODULE)]
#[no_mangle]
static __mod_mdio__phydev_device_table:
[::kernel::bindings::mdio_device_id; 2] = _TABLE_INIT;

Alice

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ