Re: [PATCH v3] rust: cpufreq: reject NULL from cpufreq_cpu_get()
From: spidermana
Date: Mon Sep 28 2026 - 12:27:59 EST
On Sat, 29 Aug 2026 19:10:13 +0300, Mehmet Koseoglu wrote:
> cpufreq_cpu_get() returns either a referenced policy or NULL.
> PolicyCpu::from_cpu() passed its return value to from_err_ptr(), which
> rejects ERR_PTR values but accepts NULL.
[...]
> Ok(Self(
> // SAFETY: The `ptr` is guaranteed to be valid and remains valid for the lifetime of
> // the returned reference.
> - unsafe { Policy::from_raw_mut(ptr) },
> + unsafe { Policy::from_raw_mut(ptr.as_ptr()) },
Just a quick nit here, maybe rephrase this SAFETY comment, e.g.:
// SAFETY: `ptr` is non-NULL and `cpufreq_cpu_get()` took a reference on it, so it is
// valid for writing and remains valid for the lifetime of the returned reference.
Either way, looks good to me.
FWIW, I hit this too and have a reproducer [1].
[1] https://github.com/Rust-for-Linux/linux/issues/1258
Reviewed-by: Elowen Xu <malanalyzing@xxxxxxxxx>