Re: [PATCH V4 8/8] cpufreq: Add Rust based cpufreq-dt driver
From: Danilo Krummrich
Date: Thu Jul 11 2024 - 09:21:49 EST
On Thu, Jul 11, 2024 at 06:38:02PM +0530, Viresh Kumar wrote:
> On 11-07-24, 12:43, Danilo Krummrich wrote:
> > Please just call this function `cpufreq::Registration::new`.
> >
> > The existance of a `cpufreq::Registration` means that it's registered. Once it
> > is dropped, it's unregistered. It's the whole point of a `Registration` type
> > to bind the period of a driver being registered to the lifetime of a
> > `Registration` instance.
> >
> > Having `Registration::register` implies a bit, that we could ever have an
> > unregistered `Registration`, which can never happen.
> >
> > Besides that, it'd be nice to follow the same naming scheme everywhere.
>
> Sure, ::new() looks fine.
>
> > > + c_str!("cpufreq-dt"),
> > > + (),
> > > + cpufreq::flags::NEED_INITIAL_FREQ_CHECK | cpufreq::flags::IS_COOLING_DEV,
> > > + true,
> > > + )?;
> > > +
> > > + Devres::new_foreign_owned(dev.as_ref(), drv, GFP_KERNEL)?;
> >
> > This should be called by `cpufreq::Registration` directly, otherwise it's every
> > driver's responsibility to take care of the registration lifetime.
>
> Some details were shared in another thread [1] earlier and I understand that
> they are not very clear otherwise.
>
> The problem is that it is not guaranteed that a struct device will be available
> to the cpufreq core all the time, to which a platform driver (or other bus) can
> be bound. And so this has to be taken care of by the individual drivers only.
I guess you are referring to the case where you want to register a CPUfreq
driver directly from `Module::init`. I see two possible options for that, with
one of them being the preference.
(1) You simply provide an additional `Registration::new_foreign_owed` function.
(2) You require drivers to always implement a "dummy" struct platform_device,
there is platform_device_register_simple() for that purpose.
I think (2) is the preferred option.
>
> --
> viresh
>
> [1] https://lore.kernel.org/all/20240620100556.xsehtd7ii25rtn7k@vireshk-i7/
>