mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 12:44:03 +02:00
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: c6af9a1191 ("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>
This commit is contained in:
parent
b5e4771f20
commit
19c76bdd3f
|
|
@ -822,7 +822,9 @@ fn update_limits(_policy: &mut Policy) {
|
|||
}
|
||||
|
||||
/// 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)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user