mirror of
https://github.com/RGBCube/superfreq
synced 2025-07-27 17:07:44 +00:00
cpu: prevent possible overflow in frequency calculations
This commit is contained in:
parent
18141d22e1
commit
e8d7d1ab86
1 changed files with 8 additions and 2 deletions
10
src/cpu.rs
10
src/cpu.rs
|
@ -309,7 +309,10 @@ pub fn set_min_frequency(freq_mhz: u32, core_id: Option<u32>) -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
let freq_khz_str = (freq_mhz * 1000).to_string();
|
||||
// XXX: We use u64 for the intermediate calculation to prevent overflow
|
||||
let freq_khz = u64::from(freq_mhz) * 1000;
|
||||
let freq_khz_str = freq_khz.to_string();
|
||||
|
||||
let action = |id: u32| {
|
||||
let path = format!("/sys/devices/system/cpu/cpu{id}/cpufreq/scaling_min_freq");
|
||||
if Path::new(&path).exists() {
|
||||
|
@ -333,7 +336,10 @@ pub fn set_max_frequency(freq_mhz: u32, core_id: Option<u32>) -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
let freq_khz_str = (freq_mhz * 1000).to_string();
|
||||
// XXX: Use a u64 here as well.
|
||||
let freq_khz = u64::from(freq_mhz) * 1000;
|
||||
let freq_khz_str = freq_khz.to_string();
|
||||
|
||||
let action = |id: u32| {
|
||||
let path = format!("/sys/devices/system/cpu/cpu{id}/cpufreq/scaling_max_freq");
|
||||
if Path::new(&path).exists() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue