diff options
| author | Priya Bala Govindasamy <pgovind2@uci.edu> | 2026-07-20 18:00:58 +0000 |
|---|---|---|
| committer | Viresh Kumar <viresh.kumar@linaro.org> | 2026-08-06 11:54:41 +0530 |
| commit | 19c76bdd3fc02475c73c8576f6f4a55ff07886f1 (patch) | |
| tree | fc4e146c95cafc123a4044d48b5b4c2c543107c4 /rust | |
| parent | b5e4771f20a37fdf19eac0824bf062dffb4e291f (diff) | |
| download | linux-19c76bdd3fc02475c73c8576f6f4a55ff07886f1.tar.gz linux-19c76bdd3fc02475c73c8576f6f4a55ff07886f1.zip | |
rust: cpufreq: Fix temporary write in Registration::bios_limit_callback
In `Registration::bios_limit_callback`, the expression
`&mut (unsafe { *limit })` creates a reference to a temporary copy
of the value pointed to by `limit` on the stack.
Therefore, writes made by `T::bios_limit` go to this temporary
instead of the memory location pointed to by `limit`.
Additionally, `limit` may be uninitialized, such as when
`Registration::bios_limit_callback` is invoked by `show_bios_limit`
in drivers/cpufreq/cpufreq.c. Therefore creating a reference to
`limit` is unsound.
Fix this by changing the signature of `T::bios_limit` to return the limit
value.
`Registration::bios_limit_callback` can then update `limit` directly.
Fixes: c6af9a1191d042839e56abff69e8b0302d117988 ("rust: cpufreq: Extend abstractions for driver registration")
Reported-by: Dylan Zueck<dzueck@uci.edu>
Reported-by: Yuan Tan<ytan089@ucr.edu>
Assisted-by: ChatGPT:gpt-5.4
Signed-off-by: Priya Bala Govindasamy<pgovind2@uci.edu>
[ Viresh: Fix rustfmtcheck warning ]
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Diffstat (limited to 'rust')
| -rw-r--r-- | rust/kernel/cpufreq.rs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/rust/kernel/cpufreq.rs b/rust/kernel/cpufreq.rs index f360eb9578f3..1158ef3a85f2 100644 --- a/rust/kernel/cpufreq.rs +++ b/rust/kernel/cpufreq.rs @@ -822,7 +822,9 @@ pub trait Driver { } /// Driver's `bios_limit` callback. - fn bios_limit(_policy: &mut Policy, _limit: &mut u32) -> Result { + /// + /// Returns HW/BIOS max frequency limitations for the CPU. + fn bios_limit(_policy: &mut Policy) -> Result<u32> { build_error!(VTABLE_DEFAULT_ERROR) } @@ -1357,9 +1359,12 @@ impl<T: Driver> Registration<T> { from_result(|| { let mut policy = PolicyCpu::from_cpu(cpu_id)?; - + let val = T::bios_limit(&mut policy)?; // SAFETY: `limit` is guaranteed by the C code to be valid. - T::bios_limit(&mut policy, &mut (unsafe { *limit })).map(|()| 0) + unsafe { + *limit = val; + } + Ok(0) }) } |
