Fix int8_t overflow in AAF frequency selection for ICM-42688P/42686P#11682
Merged
sensei-hacker merged 1 commit intoJul 2, 2026
Merged
Conversation
selectedFreq in getGyroAafConfig() was declared int8_t (max 127), but aafLUT42688[] contains freq values up to 1962. Values above 127 silently truncated on assignment, corrupting the closest-frequency comparison and causing the wrong AAF register configuration to be selected. This affected every board using this gyro at the default 256Hz LPF setting (selected 303Hz instead of the correct 258Hz cutoff). Changed to uint16_t to match aafConfig_t.freq's own type.
Contributor
PR Summary by QodoFix AAF frequency selection overflow for ICM-42688P/42686P
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Contributor
|
Test firmware build ready — commit Download firmware for PR #11682 240 targets built. Find your board's
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getGyroAafConfig()insrc/main/drivers/accgyro/accgyro_icm42605.ctracks the running "best candidate" Anti-Alias Filter (AAF) frequency in a local variableselectedFreqdeclared asint8_t(max value 127). TheaafLUT42688[]table (used for ICM-42688P/42686P) containsfreqvalues up to 1962, all stored asuint16_tinaafConfig_t. Any LUT value above 127 silently truncates on assignment toselectedFreq, corrupting the closest-frequency comparison and causing the wrong AAF register configuration to be selected.This affects every board using the ICM-42688P/42686P gyro at INAV's default hardware LPF setting (
GYRO_LPF_256HZ, set unconditionally ingyro.c): the function selects 303Hz instead of the correct 258Hz AAF cutoff.Changes
selectedFreqfromint8_ttouint16_tingetGyroAafConfig(), matching the type ofaafConfig_t.freq(the field it tracks) anddesiredFreq(the value it's compared against).Testing
GYRO_LPF_256HZ(default) on the 42688P table, the buggy code selects 303Hz instead of the correct 258Hz; also reproduced forGYRO_LPF_188HZon both the 42688P and 42605 tables.AETH743Basictarget (uses ICM-42688P, confirmed via WHOAMI-detectedICM42605_VARIANT_42688Pat runtime, exercisingaafLUT42688[]directly) — build succeeds with zero warnings on the changed file.ABS()macro (src/main/common/maths.h) has no signed/unsigned hazard now thatdesiredFreq,selectedFreq, andaafConfigs[i].freqare alluint16_t— both operands promote to signedintbefore subtraction on all INAV-supported 32-bit targets.Code Review
Reviewed with inav-code-review agent — approved, no issues found.
Related
This is a long-standing pre-existing bug present on master, maintenance-9.x, maintenance-10.x, and release/9.1. Flagged by Qodo bot review on PR #11681 (a release/9.1 → maintenance-10.x branch-sync merge) and independently verified against the actual file content. Targeting
release/9.1per current branch-basing guidance; this will flow up to maintenance-10.x via the normal release/9.1 → maintenance-10.x merge process.