Re: [RFC PATCH V3 8/8] cpufreq: Add Rust based cpufreq-dt driver

From: Viresh Kumar
Date: Wed Jul 10 2024 - 04:59:13 EST


On 05-07-24, 13:32, Danilo Krummrich wrote:
> On 7/3/24 09:14, Viresh Kumar wrote:
> > + fn probe(_dev: &mut platform::Device, _id_info: Option<&Self::IdInfo>) -> Result<Self::Data> {
> > + let drv = Arc::new(
> > + cpufreq::Registration::<CPUFreqDTDriver>::register(
> > + c_str!("cpufreq-dt"),
> > + (),
> > + cpufreq::flags::NEED_INITIAL_FREQ_CHECK | cpufreq::flags::IS_COOLING_DEV,
> > + true,
> > + )?,
> > + GFP_KERNEL,
> > + )?;
>
> Putting the `cpufreq::Registration` into `Arc<DeviceData>` is unsafe from a
> lifetime point of view. Nothing prevents this `Arc` to out-live the
> `platform::Driver`.

Hmm, the platform driver layer (in Rust) should guarantee that the
data will be freed from the driver removal path. Isn't it ?

> Instead, you should wrap `cpufreq::Registration` into `Devres`. See
> `drm::drv::Registration` for an example [1].
>
> [1] https://gitlab.freedesktop.org/drm/nova/-/blob/nova-next/rust/kernel/drm/drv.rs?ref_type=heads#L173

I can convert to that too, will do it anyway.

--
viresh