Re: [PATCH v3] rust: cpufreq: mark Policy::data() as unsafe
From: Viresh Kumar
Date: Tue Dec 01 2026 - 02:40:28 EST
On 01-12-26, 13:45, Zhongqiu Han wrote:
> On 11/30/2026 2:15 PM, Bilal Hashim wrote:
> > Policy::data<T: ForeignOwnable>(&mut self) is currently a safe public
> > method that casts the untyped C pointer `policy->driver_data` via
> > `T::borrow(...)` for any caller-chosen type `T`.
> >
> > Because `Policy` is not parameterized by `Driver::PData` and performs no
> > runtime type verification, any safe Rust caller with `&mut Policy` can
> > invoke `policy.data::<WrongType>()` and reinterpret `driver_data` as an
> > arbitrary `ForeignOwnable` type, causing type confusion and undefined
> > behavior in safe Rust.
> >
> > Mark Policy::data() as `unsafe`, document the safety precondition that
> > `T` must match the exact `ForeignOwnable` type previously stored in the
> > policy's `driver_data`, and update the in-tree caller in
> > drivers/cpufreq/rcpufreq_dt.rs.
> >
> > Fixes: 6ebdd7c93177 ("rust: cpufreq: Extend abstractions for policy and driver ops")
> > Signed-off-by: Bilal Hashim <AeeSec@xxxxxxx>
>
> Reviewed-by: Zhongqiu Han <zhongqiu.han@xxxxxxxxxxxxxxxx>
Applied. Thanks.
--
viresh