Skip to content

Commit bc26723

Browse files
judyhsiao2020Chromeos LUCI
authored and
Chromeos LUCI
committed
sound_card_init: max98397: Prevent integer overflow in RDC calibration
The `avg_rdc` accumulator in `do_rdc_calibration` was changed to `i64` to prevent potential integer overflows when summing RDC values. BUG=b:407129459 TEST=CQ Change-Id: Ia49132b26e0eef13d8fb82887f1b5a1540350068 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/adhd/+/6420893 Reviewed-by: Yu-Hsuan Hsu <[email protected]> Tested-by: [email protected] <[email protected]> Reviewed-by: Baili Deng <[email protected]> Commit-Queue: Baili Deng <[email protected]> Feels: Baili Deng <[email protected]> Tested-by: Judy Hsiao <[email protected]> Feels: Judy Hsiao <[email protected]> Auto-Submit: Judy Hsiao <[email protected]>
1 parent ba60597 commit bc26723

File tree

1 file changed

+4
-4
lines changed
  • sound_card_init/amp/src/max98373d

1 file changed

+4
-4
lines changed

sound_card_init/amp/src/max98373d/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,21 +372,21 @@ impl Max98373 {
372372
self.set_spt_mode(SPTMode::OFF)?;
373373
self.set_calibration_mode(CalibMode::ON)?;
374374
// Playback of zeros is started, and the main thread can start the calibration.
375-
let mut avg_rdc = vec![0; self.setting.num_channels()];
375+
let mut avg_rdc: Vec<i64> = vec![0; self.setting.num_channels()];
376376
for _ in 0..Self::CALIB_REPEAT_TIMES {
377377
let rdc = self.get_adaptive_rdc()?;
378378
for i in 0..self.setting.num_channels() {
379-
avg_rdc[i] += rdc[i];
379+
avg_rdc[i] += rdc[i] as i64;
380380
}
381381
thread::sleep(Self::RDC_CALIB_INTERVAL);
382382
}
383383
self.set_spt_mode(SPTMode::ON)?;
384384
self.set_calibration_mode(CalibMode::OFF)?;
385385
zero_player.stop()?;
386386

387-
avg_rdc = avg_rdc
387+
let avg_rdc: Vec<i32> = avg_rdc
388388
.iter()
389-
.map(|val| val / Self::CALIB_REPEAT_TIMES as i32)
389+
.map(|val| (val / Self::CALIB_REPEAT_TIMES as i64) as i32) // Cast back to i32 after division
390390
.collect();
391391
Ok(avg_rdc)
392392
}

0 commit comments

Comments
 (0)