Merge tag 'rust-fixes-7.4-2' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux

Pull Rust fixes from Miguel Ojeda:
 "Toolchain and infrastructure:

   - Fix build error with bindgen 0.73 in certain configs such as
     allmodconfig by deriving 'Zeroable' for opaque array wrappers.

  'kernel' crate:

   - 'cpufreq' module: clean 'undocumented_unsafe_blocks' Clippy warning
     for Rust <= 1.86"

* tag 'rust-fixes-7.4-2' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux:
  rust: bindings: derive Zeroable for bindgen's opaque array wrappers
  rust: cpufreq: fix `undocumented_unsafe_blocks` in `PolicyCpu::from_cpu()`
This commit is contained in:
Linus Torvalds
2026-11-08 08:49:58 -08:00
2 changed files with 10 additions and 3 deletions
+8 -1
View File
@@ -514,13 +514,20 @@ endif
bindgen_c_flags_final = $(bindgen_c_flags_lto) -fno-builtin -D__BINDGEN__
# `--rust-target` points to our minimum supported Rust version.
#
# `bindgen` 0.73 emits the blob of some opaque types as a
# `__BindgenOpaqueArray[<align>]` newtype, which the custom derives do not
# reach. Derive `Zeroable` for those wrappers, so that a struct embedding such
# an opaque type (e.g. `spinlock_t` with lockdep) is still `Zeroable`. The
# pattern also matches the unformatted output used when `rustfmt` is missing.
quiet_cmd_bindgen = BINDGEN $@
cmd_bindgen = \
$(BINDGEN) $< $(bindgen_target_flags) --rust-target 1.85 \
--use-core --with-derive-default --ctypes-prefix ffi --no-layout-tests \
--no-debug '.*' --enable-function-attribute-detection \
-o $@ -- $(bindgen_c_flags_final) -DMODULE \
$(bindgen_target_cflags) $(bindgen_target_extra)
$(bindgen_target_cflags) $(bindgen_target_extra); \
sed -Ei 's/pub struct __BindgenOpaqueArray[0-9]* *< *T *> *\( *pub T *\) *;/$(pound)[derive(pin_init::Zeroable)] &/g' $@
$(obj)/bindings/bindings_generated.rs: private bindgen_target_flags = \
$(shell grep -Ev '^#|^$$' $(src)/bindgen_parameters)
+2 -2
View File
@@ -696,8 +696,8 @@ struct PolicyCpu<'a>(&'a mut Policy);
impl<'a> PolicyCpu<'a> {
fn from_cpu(cpu: CpuId) -> Result<Self> {
// SAFETY: It is safe to call `cpufreq_cpu_get` for any valid CPU.
let ptr =
NonNull::new(unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) }).ok_or(ENODEV)?;
let ptr = unsafe { bindings::cpufreq_cpu_get(u32::from(cpu)) };
let ptr = NonNull::new(ptr).ok_or(ENODEV)?;
Ok(Self(
// SAFETY: `ptr` is non-NULL and `cpufreq_cpu_get()` took a reference on it, so it is