Re: [PATCH V10 13/15] rust: cpufreq: Extend abstractions for driver registration
From: Danilo Krummrich
Date: Wed Apr 16 2025 - 06:59:42 EST
On Wed, Apr 16, 2025 at 03:47:26PM +0530, Viresh Kumar wrote:
> On 16-04-25, 11:04, Danilo Krummrich wrote:
> > You need to justify why drv is a valid pointer to be passed to
> > cpufreq_register_driver(), i.e. something like
> >
> > // SAFETY:
> > // - `drv` comes from Self::VTABLE and hence is a valid pointer to a `struct cpufreq_driver`,
> > // - `cpufreq_register_driver()` never attempts to modify the data `drv` points to
>
> The cpufreq core can try to change the data pointed by `drv`. For now
> it updates the `cpufreq_driver->boost_enabled` flag.
VTABLE is const and hence ends up in the read-only section of the binary.
I assumed that struct cpufreq_driver (like most driver structures) is const.
Actually, I think it should be.
Anyways, that doesn't help for now. Unfortunately, I think you actually need to
dynamically allocate it. There's no need to revert everything though. You can
just allocate a new KBox from VTABLE, i.e.
let vtable = KBox::new(Self::VTABLE, GFP_KERNEL)?;
This makes it easy for you to remove the dynamic allocation once (or if) cpufreq
is ever reworked to allow a static const struct cpufreq_driver.