Skip to content

Commit ed56f3e

Browse files
committed
fix(safety): resolve potential mutex deadlock in get_e_core_l2_cache_size
The original code acquired cached_s_core_count mutex twice in the same if-expression. Rust drops temporaries at statement end, not at &&, so when the first condition evaluated to true the second .lock() would deadlock. Consolidate into a single lock acquisition with matches!.
1 parent e7ba644 commit ed56f3e

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/device/cpu_macos.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,11 +710,12 @@ impl MacOsCpuReader {
710710
}
711711

712712
fn get_e_core_l2_cache_size(&self) -> Result<u32, Box<dyn std::error::Error>> {
713-
// M5 Pro/Max has no E-cores
714-
if *self.cached_s_core_count.lock().unwrap() != Some(0)
715-
&& self.cached_s_core_count.lock().unwrap().is_some()
713+
// M5 Pro/Max has no E-cores — skip if Super cores are present
716714
{
717-
return Err("No E-cores on M5 Pro/Max".into());
715+
let s_count = self.cached_s_core_count.lock().unwrap();
716+
if matches!(*s_count, Some(n) if n > 0) {
717+
return Err("No E-cores on M5 Pro/Max".into());
718+
}
718719
}
719720

720721
// Check if we have cached value

0 commit comments

Comments
 (0)