Re: [PATCH v4] rust: cpufreq: reject NULL from cpufreq_cpu_get()
From: Viresh Kumar
Date: Sun Oct 04 2026 - 23:56:42 EST
On 01-10-26, 13:19, 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.
>
> If the lookup fails, Policy::from_raw_mut() therefore constructs a mutable
> reference from NULL. Dropping the resulting PolicyCpu then passes the
> invalid pointer to cpufreq_cpu_put(), causing an oops in kobject_put().
>
> Reject NULL with NonNull before constructing the Policy reference. Return
> ENODEV instead.
>
> A KUnit negative-control run reproduced the oops with the original
> conversion. The same test passed with this change. The reproducer is
> available on request.
>
> Fixes: 6ebdd7c93177 ("rust: cpufreq: Extend abstractions for policy and driver ops")
> Cc: stable@xxxxxxxxxxxxxxx
> Assisted-by: LLM
> Signed-off-by: Mehmet Koseoglu <mehmet.mkoseoglu@xxxxxxxxx>
> Reviewed-by: Onur Özkan <work@xxxxxxxxxxxxx>
> Reviewed-by: spidermana <xuyiwen14@xxxxxxxxx>
Applied. Thanks.
--
viresh