Skip to content

Reject servo mixer inputs from RC channels 19-34 on boards without them - #12284

Open
sensei-hacker wants to merge 1 commit into
iNavFlight:release/9.1from
sensei-hacker:servo-mixer-reject-high-channels
Open

sensei-hacker wants to merge 1 commit into
iNavFlight:release/9.1from
sensei-hacker:servo-mixer-reject-high-channels

Conversation

@sensei-hacker

Copy link
Copy Markdown
Member

Problem

servoMixer() keeps its inputs in an array on the stack that is never zeroed, int16_t input[INPUT_SOURCE_COUNT]. It fills the RC channel 19–34 inputs only when USE_34CHANNELS is defined, and that is off on 512 KB boards such as the F411.

Even so, smix and both MSP setters accepted those inputs on every board. On a board without USE_34CHANNELS, a servo rule with input 44–59 (RC channel 19–34) drives its servo from whatever value is left in that stack memory.

There is a second problem in the MSP setters, MSP_SET_SERVO_MIX_RULE and MSP2_INAV_SET_SERVO_MIXER. They didn't check the input number at all, so an out-of-range input was read past the end of input[].

Changes

  • Check: servoMixerInputSupported() rejects RC channel 19–34 inputs on boards without USE_34CHANNELS, and any input outside the defined range.
  • Rejected: smix, MSP_SET_SERVO_MIX_RULE and MSP2_INAV_SET_SERVO_MIXER refuse such an input. The MSP setters reply with an error and change nothing.
  • Already saved: a rule saved before this change is skipped when the mixer loads, so its servo never reads that memory.
    • It also blocks arming as an invalid setting (SETTINGFAIL).
    • CLI status explains why: "Servo mixer rule uses an input this board does not support".
    • Rules in every mixer profile are checked, not just the active one.

Testing

The test script is servo_mixer_input_check.py. It sends rules with input 43 (RC channel 18), 45 (RC channel 20) and 316 (which is 60 when cut to 8 bits) over the CLI and both MSP commands. It also checks the arming flag and the status text for a rule that is already saved.

SITL build Result
Unmodified (no USE_34CHANNELS) Input 45 accepted over the CLI and both MSP commands: the bug
This change (no USE_34CHANNELS) Inputs 45 and 316 rejected everywhere, input 43 accepted
This change, EEPROM saved by an unmodified build with a rule using input 45 The rule and other settings load. Arming is blocked and status gives the reason
This change with USE_34CHANNELS (SITL built with its real flash size, #12281) Input 45 accepted
  • MATEKF411 and MATEKF722 build.
  • The unit tests pass.

Not covered here

  • Configurator: it logs a rejected MSP write only to the console, so saving a mixer that uses channel 19–34 on a small board would drop that rule without telling the user. That needs a separate configurator change.
  • OSD/DJI: when the servo rule is the only invalid setting, the OSD and DJI arming messages show no reason, because they only name invalid CLI settings.

servoMixer() fills the RC channel 19-34 inputs only when USE_34CHANNELS
is defined, but smix and both MSP setters accepted them on every board.
On a 512 KB board a rule using one of them drove its servo from
uninitialized stack memory. The MSP setters also accepted any input
number at all, reading past the end of the input array.

smix and both MSP setters now refuse an input the board cannot fill. A
rule already saved with one is skipped, and blocks arming as an invalid
setting; CLI status says which problem it is.
@qodo-code-review

Copy link
Copy Markdown
Contributor

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 6, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Reject servo mixer inputs from RC channels 19-34 on boards without them

🐞 Bug fix 🕐 20-40 Minutes

Grey Divider

AI Description

• Rejects servo mixer inputs for RC channels 19-34 when USE_34CHANNELS is not defined.
• smix and both MSP setters now refuse unsupported or out-of-range inputs, leaving rules unchanged.
• Saved rules with unsupported inputs are skipped at load, block arming, and are reported by CLI
 status.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The changed configuration admission, persisted-rule validation, rule loading, and servo output calculation all govern one bounded servo-mixing behavior.
  • The propagation path ends at the servo mixer, rather than establishing independent capabilities for MSP, CLI, storage, or runtime layers.
Sources

src/main/flight/servos.c[261-264]

        // Arming is blocked while such a rule exists; see servoMixerRulesValid()
        if (!servoMixerInputSupported(customServoMixers(i)->inputSource)) {
            continue;
        }

src/main/fc/fc_msp.c[2371-2377]

            const uint8_t targetChannel = sbufReadU8(src);
            const uint8_t inputSource = sbufReadU8(src);
            if (!servoMixerInputSupported(inputSource)) {
                return MSP_RESULT_ERROR;
            }
            customServoMixersMutable(tmp_u8)->targetChannel = targetChannel;
            customServoMixersMutable(tmp_u8)->inputSource = inputSource;

src/main/fc/config.c[267-271]

    if (settingsValidate(NULL) && servoMixerRulesValid()) {
        DISABLE_ARMING_FLAG(ARMING_DISABLED_INVALID_SETTING);
    } else {
        ENABLE_ARMING_FLAG(ARMING_DISABLED_INVALID_SETTING);
    }

src/main/flight/servos.c[472-475]

        const uint8_t target = currentServoMixer[i].targetChannel;
        const uint8_t from = currentServoMixer[i].inputSource;

        int16_t inputRaw = input[from];
Behavioral complexity 🟡 Medium 🧩 Coordinated invariants, Interacting branches

  • Before, input-range validation was applied at individual CLI/MSP entry points and runtime rules could be loaded without the new target-support invariant.
  • After, one predicate governs CLI/MSP admission, persisted multi-profile validation, arming state, and runtime rule loading.
  • The new correctness condition is that every active servo rule must reference an input populated by the current target, while invalid persisted state must be rejected consistently without being executed.
  • The branches themselves are straightforward, but their consistency spans configuration updates, reloads, arming validation, and runtime mixing.
Sources

src/main/flight/servos.c[261-264]

        // Arming is blocked while such a rule exists; see servoMixerRulesValid()
        if (!servoMixerInputSupported(customServoMixers(i)->inputSource)) {
            continue;
        }

src/main/fc/fc_msp.c[2371-2377]

            const uint8_t targetChannel = sbufReadU8(src);
            const uint8_t inputSource = sbufReadU8(src);
            if (!servoMixerInputSupported(inputSource)) {
                return MSP_RESULT_ERROR;
            }
            customServoMixersMutable(tmp_u8)->targetChannel = targetChannel;
            customServoMixersMutable(tmp_u8)->inputSource = inputSource;

src/main/fc/config.c[267-271]

    if (settingsValidate(NULL) && servoMixerRulesValid()) {
        DISABLE_ARMING_FLAG(ARMING_DISABLED_INVALID_SETTING);
    } else {
        ENABLE_ARMING_FLAG(ARMING_DISABLED_INVALID_SETTING);
    }
Potential damage 🟡 Medium 🩹 Temporary loss

  • If this changed behavior regresses, servo-mixer configuration or a configured servo output can become unavailable or fail to follow its rule.
  • The inspected code shows no broader consumer path beyond servo mixing.
  • Persisted invalid rules can also keep arming blocked until corrected; no automatic repair worker or compensation path is present.
  • Configuration can be corrected or the code reverted, but persisted invalid rules require an explicit configuration update before normal arming and servo behavior is restored.
Sources

src/main/flight/servos.c[261-264]

        // Arming is blocked while such a rule exists; see servoMixerRulesValid()
        if (!servoMixerInputSupported(customServoMixers(i)->inputSource)) {
            continue;
        }

src/main/fc/fc_msp.c[2371-2377]

            const uint8_t targetChannel = sbufReadU8(src);
            const uint8_t inputSource = sbufReadU8(src);
            if (!servoMixerInputSupported(inputSource)) {
                return MSP_RESULT_ERROR;
            }
            customServoMixersMutable(tmp_u8)->targetChannel = targetChannel;
            customServoMixersMutable(tmp_u8)->inputSource = inputSource;

src/main/fc/config.c[267-271]

    if (settingsValidate(NULL) && servoMixerRulesValid()) {
        DISABLE_ARMING_FLAG(ARMING_DISABLED_INVALID_SETTING);
    } else {
        ENABLE_ARMING_FLAG(ARMING_DISABLED_INVALID_SETTING);
    }

src/main/flight/servos.c[472-475]

        const uint8_t target = currentServoMixer[i].targetChannel;
        const uint8_t from = currentServoMixer[i].inputSource;

        int16_t inputRaw = input[from];
Assessed commit c599aee
Diagram

graph TD
  A["smix / MSP setters"] --> B{"servoMixerInputSupported()"}
  B -->|no| C["Reject with error"]
  B -->|yes| D["Store rule"] --> E["loadCustomServoMixer()"]
  E --> F{"Input supported?"}
  F -->|no| G["Skip rule, block arming"]
  F -->|yes| H["Active servo rules"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Zero-initialize servoMixer input array
  • ➕ Removes the uninitialized stack read with a one-line change
  • ➕ Existing saved rules keep loading and running
  • ➖ Servo silently follows a constant 0 instead of the configured channel
  • ➖ Hides a misconfiguration the user cannot see
  • ➖ Does not fix the MSP setters reading past input[] for out-of-range numbers
2. Always populate all 34 RC channel inputs
  • ➕ Makes every defined input valid on every board
  • ➕ No validation logic needed
  • ➖ Adds stack or static memory on 512 KB boards such as F411
  • ➖ Requires changes to the fill path for the flash-constrained target

Recommendation: The PR's approach (reject at write time, skip and flag at load time) is sound and explicit. The main alternative, zero-initializing input[] so missing channels read 0, would remove the stack read but silently drive servos from a value the user never configured. Rejecting makes the misconfiguration visible. The main cost is that saved rules on small boards stop working and arming is blocked until the user fixes them, which is the intended outcome. Also, the configurator still drops rejected rules silently, as the PR notes.

Files changed (5) +49 / -6

Enhancement (2) +6 / -1
servos.hDeclare servo mixer input validation functions +2/-0

Declare servo mixer input validation functions

• Exports servoMixerInputSupported() and servoMixerRulesValid() so the CLI, MSP and config code can call them.

src/main/flight/servos.h

cli.cValidate smix input and report bad rules in status +4/-1

Validate smix input and report bad rules in status

• The smix command uses servoMixerInputSupported() instead of a plain range check. cliStatus() prints 'Servo mixer rule uses an input this board does not support' when servoMixerRulesValid() fails.

src/main/fc/cli.c

Bug fix (3) +43 / -5
servos.cAdd input-support check and load-time rule filtering +28/-0

Add input-support check and load-time rule filtering

• Adds servoMixerInputSupported() to reject RC CH19-34 inputs when USE_34CHANNELS is off, and servoMixerRulesValid() to scan all mixer profiles. loadCustomServoMixer() now skips unsupported saved rules so their servos never read the uninitialized input.

src/main/flight/servos.c

fc_msp.cReject unsupported input in both MSP servo mixer setters +14/-4

Reject unsupported input in both MSP servo mixer setters

• MSP_SET_SERVO_MIX_RULE and MSP2_INAV_SET_SERVO_MIXER read targetChannel and inputSource into locals, return MSP_RESULT_ERROR for an unsupported input, and only then write the rule. This stops out-of-range inputs being stored and leaves the rule unchanged on error.

src/main/fc/fc_msp.c

config.cBlock arming when a saved servo rule is unsupported +1/-1

Block arming when a saved servo rule is unsupported

• validateAndFixConfig() sets ARMING_DISABLED_INVALID_SETTING unless servoMixerRulesValid() also passes, so arming is blocked while an unsupported saved rule exists.

src/main/fc/config.c

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 🔗 Cross-repo conflicts (1) 📜 Skill insights (0)

Grey Divider


Action required

1. Rejected mixer rules appear saved 🔗 Cross-repo conflict ≡ Correctness
Description
On boards without USE_34CHANNELS, MSP2_INAV_SET_SERVO_MIXER now rejects RC19–RC34 inputs, but
inav-configurator still offers those inputs and sends them unchanged. When the firmware returns an
error, the configurator completes its save chain anyway, writes EEPROM, and tells the user the
configuration was saved although the rule was not applied.
Code

src/main/fc/fc_msp.c[R2392-2394]

+            if (!servoMixerInputSupported(inputSource)) {
+                return MSP_RESULT_ERROR;
+            }
Evidence
The firmware rejects these inputs on affected boards. The configurator presents and transmits them,
while its response handling invokes the save callback even for an MSP error; that callback advances
a chain which reports success.

inav -> inav-configurator
src/main/flight/servos.c[207-216]
src/main/fc/fc_msp.c[2387-2394]
External repo: iNavFlight/inav-configurator, js/fc.js [962-978]
External repo: iNavFlight/inav-configurator, tabs/mixer.js [369-375]
External repo: iNavFlight/inav-configurator, js/msp/MSPHelper.js [2433-2466]
External repo: iNavFlight/inav-configurator, js/msp.js [226-240]
External repo: iNavFlight/inav-configurator, js/msp/MSPHelper.js [1755-1790]
External repo: iNavFlight/inav-configurator, tabs/mixer.js [48-73]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The firmware rejects unsupported servo mixer inputs, but inav-configurator offers them and treats a rejected MSP write as a successful save.

## Fix Focus Areas
- src/main/fc/fc_msp.c[2390-2394]
- src/main/flight/servos.c[207-216]
- /cross_repos/inav-configurator/tabs/mixer.js[369-375]
- /cross_repos/inav-configurator/js/msp/MSPHelper.js[2433-2466]
- /cross_repos/inav-configurator/js/msp/MSPHelper.js[1755-1790]

## Recommended Fix
Coordinate with inav-configurator to make the available servo inputs depend on a capability reported by the connected firmware. Also propagate MSP error responses to the mixer save chain, stop that chain on a rejected write, and show the user a save failure instead of proceeding to EEPROM and reboot.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Fixed mixer rules still block arming 🐞 Bug ≡ Correctness
Description
validateAndFixConfig() now sets the invalid-setting arming flag for unsupported servo inputs, but
the flag is recalculated only when EEPROM is loaded. If an MSP setter replaces an invalid saved rule
with a supported one, the live mixer updates while arming remains blocked and status no longer
gives a reason until the configuration is saved and reloaded.
Code

src/main/fc/config.c[267]

+    if (settingsValidate(NULL) && servoMixerRulesValid()) {
Evidence
The new condition can set the flag for an unsupported rule, but its only update path is EEPROM
loading. Both MSP handlers can subsequently replace that rule and reload the active mixer without
updating the flag; CLI status checks the stored flag before printing its diagnostics.

src/main/fc/config.c[267-271]
src/main/fc/config.c[338-356]
src/main/fc/fc_msp.c[2368-2405]
src/main/fc/cli.c[4225-4238]
src/main/fc/fc_msp.c[2886-2893]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
An unsupported saved servo rule sets the invalid-setting arming flag at load time, but repairing that rule through MSP updates the live mixer without clearing the flag.

## Fix Focus Areas
- src/main/fc/config.c[267-271]
- src/main/fc/fc_msp.c[2373-2382]
- src/main/fc/fc_msp.c[2392-2404]

## Recommended Fix
Provide a way to recompute the invalid-setting flag from both settings validation and all servo mixer profiles, and invoke it after successful live rule edits as well as during EEPROM loading. Preserve the flag when another setting or another profile remains invalid.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Cross-repo context — repo relationships
  Explored: repo: iNavFlight/inav-configurator (sha: 95504dce) — View relationship
Review mode: Auto: ⚖️ Balanced: Behavioral firmware validation spans CLI, MSP, loading, and arming paths.

Grey Divider

Tip of the day
💡 Did you know, you can start a comment with 'qodo' or '@qodo' to chat about any finding

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown

RAM / Flash usage vs. base commit 305d304 — commit c599aee

Target Flash Δ RAM Δ
MATEKF405 +248 B (+0.04%) CCM: ±0 B (±0.00%)
RAM: ±0 B (±0.00%)
MATEKF722 +232 B (+0.05%) ITCM_RAM: ±0 B (±0.00%)
RAM: ±0 B (±0.00%)
TCM: ±0 B (±0.00%)
MATEKF765 +264 B (+0.04%) DTCM_RAM: ±0 B (±0.00%)
SRAM1: ±0 B (±0.00%)
MATEKH743 +248 B (+0.04%) D2_RAM: ±0 B (±0.00%)
DTCM_RAM: ±0 B (±0.00%)
ITCM_RAM: ±0 B (±0.00%)
RAM: ±0 B (±0.00%)

See RAM/flash optimization guide for techniques to reduce usage.

@sensei-hacker

Copy link
Copy Markdown
Member Author

Replies to the Qodo findings:

Rejected rules appear saved: fixed on the configurator side in iNavFlight/inav-configurator#2871. The Mixer tab now sees the FC's MSP error reply. It names each refused rule in the log and a dialog, and stops the save before the EEPROM write and the reboot. The defaults dialog handles a refusal the same way.

The configurator offers inputs the board can't use: the configurator doesn't know whether a target was built with USE_34CHANNELS. Hiding those inputs would need the firmware to report that, which is a separate change. Until then, the firmware refuses the rule and #2871 tells the user which one.

A corrected rule still blocks arming: this is intended. validateAndFixConfig() recomputes the flag when the EEPROM loads, which is how invalid settings already work. Every save path reloads it: the configurator's save, MSP_EEPROM_WRITE, and CLI save. A rule changed in RAM but not saved stays flagged until it is saved, so this fails safe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant