Re: [PATCH v2 3/4] rust: pci: impl TryFrom<&Device> for &pci::Device

From: Danilo Krummrich
Date: Fri Mar 21 2025 - 13:45:09 EST


On Sat, Mar 22, 2025 at 12:56:58AM +0800, kernel test robot wrote:
> >> error[E0133]: use of extern static is unsafe and requires unsafe block
> --> rust/kernel/pci.rs:473:43
> |
> 473 | if dev.bus_type_raw() != addr_of!(bindings::pci_bus_type) {
> | ^^^^^^^^^^^^^^^^^^^^^^ use of extern static
> |
> = note: extern statics are not controlled by the Rust type system: invalid data, aliasing violations or data races will cause undefined behavior

This requires an unsafe block for compilers < 1.82. For compilers >= 1.82 it
turns into a warning *if* using an unsafe block.

*Not* requiring unsafe for this seems like the correct thing -- was this a
bugfix in the compiler?

I guess to make it work for all compiler versions supported by the kernel we
have to use unsafe and suppress the warning?