Skip to content

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

Open
sensei-hacker wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
sensei-hacker:servo-mixer-reject-high-channels-10x
Open

sensei-hacker wants to merge 1 commit into
iNavFlight:maintenance-10.xfrom
sensei-hacker:servo-mixer-reject-high-channels-10x

Conversation

@sensei-hacker

Copy link
Copy Markdown
Member

This is the maintenance-10.x version of #12284.

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), on release/9.1 and maintenance-10.x 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; the 10.x version is #12282) Input 45 accepted
  • MATEKF411 and MATEKF722 build.
  • The unit tests pass: 635 of 635 on maintenance-10.x.

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.
@sensei-hacker sensei-hacker added this to the 10.0 milestone Dec 6, 2026
@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 🕐 10-20 Minutes

Grey Divider

AI Description

• Rejects servo mixer inputs RC channels 19-34 on boards without USE_34CHANNELS, where they were
 read from uninitialized stack memory.
• Rejects out-of-range inputs in MSP_SET_SERVO_MIX_RULE and MSP2_INAV_SET_SERVO_MIXER, which
 previously read past the input array.
• Skips rules already saved with such inputs at load time, blocks arming with SETTINGFAIL, and
 reports the reason in 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 writers, persisted-rule validation, runtime loader, and servoMixer consumer all implement one bounded end-to-end behavior: configuring servo rules and applying them to servo outputs.
  • The input array is populated only for RC channels 19-34 when USE_34CHANNELS is enabled, so target-aware validation directly determines this same control capability.
  • Arming validation is part of the same servo-mixer control integration: it evaluates the persisted servo rules before permitting the vehicle to use the configured control setup.
  • It does not establish an independent functional scope from servo mixer configuration and output.
Sources

src/main/flight/servos.c[223-245]

bool servoMixerInputSupported(int inputSource)
{
#ifndef USE_34CHANNELS
    // servoMixer() fills these inputs only on 34-channel targets
    if (inputSource >= INPUT_RC_CH19 && inputSource <= INPUT_RC_CH34) {
        return false;
    }
#endif
    return inputSource >= 0 && inputSource < INPUT_SOURCE_COUNT;
}

bool servoMixerRulesValid(void)
{
    for (int profile = 0; profile < MAX_MIXER_PROFILE_COUNT; profile++) {
        const servoMixer_t *rules = mixerServoMixersByIndex(profile);
        for (int i = 0; i < MAX_SERVO_RULES && rules[i].rate != 0; i++) {
            if (!servoMixerInputSupported(rules[i].inputSource)) {
                return false;
            }
        }
    }
    return true;
}

src/main/fc/fc_msp.c[2615-2621]

            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;
Behavioral complexity 🟡 Medium 🧩 Compatibility cases, Coordinated invariants

  • Before: any input value in the enum range was accepted by CLI/MSP and could reach servo mixing.
  • After: validity depends on the target build, configuration writes reject unsupported inputs, runtime loading skips persisted unsupported rules, and arming validation checks all mixer profiles.
  • New correctness condition: the target-specific producer/consumer contract and the persisted-rule, runtime-loader, and arming states must remain consistent; supported 34-channel targets must retain channels 19-34 while other targets must not use them.
  • The changed loops and guards are straightforward individually, but their interaction across configuration, startup/reload, and arming creates compatibility and coordinated-state conditions.
Sources

src/main/flight/servos.c[223-245]

bool servoMixerInputSupported(int inputSource)
{
#ifndef USE_34CHANNELS
    // servoMixer() fills these inputs only on 34-channel targets
    if (inputSource >= INPUT_RC_CH19 && inputSource <= INPUT_RC_CH34) {
        return false;
    }
#endif
    return inputSource >= 0 && inputSource < INPUT_SOURCE_COUNT;
}

bool servoMixerRulesValid(void)
{
    for (int profile = 0; profile < MAX_MIXER_PROFILE_COUNT; profile++) {
        const servoMixer_t *rules = mixerServoMixersByIndex(profile);
        for (int i = 0; i < MAX_SERVO_RULES && rules[i].rate != 0; i++) {
            if (!servoMixerInputSupported(rules[i].inputSource)) {
                return false;
            }
        }
    }
    return true;
}

src/main/fc/fc_msp.c[2615-2621]

            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;
Potential damage 🟡 Medium 🩹 Incorrect results

  • If the changed validity decision regresses, a supported rule could be omitted or an unsupported source could be used, producing incorrect control-surface output.
  • The source supports containment to servo mixing rather than unrelated capabilities.
  • Reverting the code stops new misclassification, but a saved rule rejected or omitted during configuration may require restoring the intended mixer configuration; no external compensation is evidenced.
Sources

src/main/flight/servos.c[223-245]

bool servoMixerInputSupported(int inputSource)
{
#ifndef USE_34CHANNELS
    // servoMixer() fills these inputs only on 34-channel targets
    if (inputSource >= INPUT_RC_CH19 && inputSource <= INPUT_RC_CH34) {
        return false;
    }
#endif
    return inputSource >= 0 && inputSource < INPUT_SOURCE_COUNT;
}

bool servoMixerRulesValid(void)
{
    for (int profile = 0; profile < MAX_MIXER_PROFILE_COUNT; profile++) {
        const servoMixer_t *rules = mixerServoMixersByIndex(profile);
        for (int i = 0; i < MAX_SERVO_RULES && rules[i].rate != 0; i++) {
            if (!servoMixerInputSupported(rules[i].inputSource)) {
                return false;
            }
        }
    }
    return true;
}

src/main/fc/fc_msp.c[2615-2621]

            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;
Assessed commit 59c899b
Diagram

graph TD
A["CLI smix / MSP setters"] --> B["servoMixerInputSupported()"] --> D[("Saved mixer profiles")] --> E["loadCustomServoMixer()"] --> F["servoMixer() runtime"]
B --> C["Reject: error reply, no change"]
D --> G["servoMixerRulesValid()"] --> H["Arming blocked / CLI status"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Always fill RC channels 19-34 in servoMixer()
  • ➕ Makes every input number valid on every board
  • ➕ No validation needed at the write paths
  • ➖ Costs extra stack and CPU on 512 KB boards that have no use for those channels
  • ➖ Changes runtime behaviour for existing configs instead of rejecting them
2. Zero-initialise the input array in servoMixer()
  • ➕ Small, local change that removes the uninitialised read
  • ➕ No change to saved configs or MSP behaviour
  • ➖ Silently drives the servo from zero instead of telling the user the rule is unsupported
  • ➖ Leaves the out-of-range MSP write past the end of input[] unfixed

Recommendation: The PR's approach is the best of the options considered. It rejects unsupported inputs at every entry point (CLI, both MSP setters), so an invalid rule cannot be created. It also handles rules already saved to EEPROM by skipping them at load, blocking arming and reporting the reason. Zeroing the array would hide the misconfiguration, and filling channels 19-34 on small boards would add cost where the channels are unused. Bounds-checking the MSP input fixes the out-of-range read as well.

Files changed (5) +49 / -6

Enhancement (1) +2 / -0
servos.hDeclare servo mixer validation helpers +2/-0

Declare servo mixer validation helpers

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

src/main/flight/servos.h

Bug fix (4) +47 / -6
servos.cAdd input support check and rule validation helpers +28/-0

Add input support check and rule validation helpers

• Adds servoMixerInputSupported(), which rejects RC channel 19-34 inputs when USE_34CHANNELS is not defined, and servoMixerRulesValid(), which scans every mixer profile for unsupported rules. loadCustomServoMixer() now skips unsupported rules so they never reach the runtime mixer.

src/main/flight/servos.c

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

Validate smix input and report unsupported rules in status

• The smix command now uses servoMixerInputSupported() in place of the raw INPUT_SOURCE_COUNT bound, so unsupported inputs are refused. The status command prints 'Servo mixer rule uses an input this board does not support' when a saved rule is invalid.

src/main/fc/cli.c

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

Reject unsupported inputs in both servo mixer MSP setters

• MSP_SET_SERVO_MIX_RULE and MSP2_INAV_SET_SERVO_MIXER read the target and input bytes into locals first. They return an error without writing the rule when the input is unsupported, which also prevents out-of-range reads past input[].

src/main/fc/fc_msp.c

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

Block arming when a saved servo mixer rule is invalid

• validateAndFixConfig() now sets ARMING_DISABLED_INVALID_SETTING when servoMixerRulesValid() fails, so a rule saved before this change blocks arming until it is removed or corrected.

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 (2) 📜 Skill insights (0)

Grey Divider


Action required

1. Rejected mixer rules appear saved 🔗 Cross-repo conflict ≡ Correctness
Description
MSP2_INAV_SET_SERVO_MIXER now returns an error for unsupported inputs, but inav-configurator
completes the write callback without checking that error. When a user saves such a rule, the
configurator continues through EEPROM save and reboot while the firmware leaves that rule unchanged.
Code

src/main/fc/fc_msp.c[R2636-2637]

+            if (!servoMixerInputSupported(inputSource)) {
+                return MSP_RESULT_ERROR;
Evidence
The new firmware branch rejects the write before changing the rule. The configurator sends that
command, invokes its callback without an error status, and continues its save chain through EEPROM
write and reboot.

inav -> inav-configurator
src/main/fc/fc_msp.c[2631-2644]
External repo: iNavFlight/inav-configurator, js/msp/MSPHelper.js [2433-2465]
External repo: iNavFlight/inav-configurator, js/msp/MSPHelper.js [1756-1786]
External repo: iNavFlight/inav-configurator, tabs/mixer.js [45-74]

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 treats the error response as completion and proceeds with the save.
## Fix Focus Areas
- src/main/fc/fc_msp.c[2634-2638]
- /cross_repos/inav-configurator/js/msp/MSPHelper.js[1756-1786]
- /cross_repos/inav-configurator/tabs/mixer.js[45-74]
## Recommended Fix
Update inav-configurator to propagate MSP error responses to the mixer save chain, stop the save and reboot on a rejected rule, and tell the user which rule failed. Keep the firmware rejection in place.

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



Remediation recommended

2. Corrected rules still block arming 🐞 Bug ≡ Correctness
Description
validateAndFixConfig() updates the invalid-setting arming flag for servo rules only during
readEEPROM(), not when a rule is changed. If the sole invalid rule is corrected or removed through
smix or an MSP setter, arming remains blocked until a save-and-reload or reboot, while CLI
status no longer identifies an invalid rule.
Code

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

+    if (settingsValidate(NULL) && servoMixerRulesValid()) {
Evidence
The new check sets or clears the flag only inside validateAndFixConfig(), whose invocation is in
readEEPROM(). The CLI and MSP editing paths mutate rules without calling that validation, while
status reports a rule error only if the flag is set and the current rule validation fails.

src/main/fc/config.c[312-315]
src/main/fc/config.c[388-402]
src/main/fc/cli.c[2415-2452]
src/main/fc/fc_msp.c[2612-2649]
src/main/fc/cli.c[4298-4309]

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

## Issue description
Correcting an unsupported servo rule in memory leaves the invalid-setting arming flag set until EEPROM is reloaded, even though the rule is now valid.

## Fix Focus Areas
- src/main/fc/config.c[312-315]
- src/main/fc/cli.c[2441-2450]
- src/main/fc/fc_msp.c[2615-2649]

## Recommended Fix
Extract a way to refresh the invalid-setting flag using both settings validation and servo-rule validation, and call it after CLI and MSP servo-rule mutations, including rule reset. Preserve the flag when another setting or rule remains invalid.

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


3. Small boards offer unusable channels 🔗 Cross-repo conflict ≡ Correctness
Description
servoMixerInputSupported() now rejects RC channels 19–34 without USE_34CHANNELS, while
inav-configurator unconditionally offers those channels in its servo-mixer selector. On affected
boards, users can still choose inputs 44–59 even though the firmware refuses the resulting MSP
write; the configurator needs a way to identify supported inputs and filter those choices.
Code

src/main/flight/servos.c[R225-229]

+#ifndef USE_34CHANNELS
+    // servoMixer() fills these inputs only on 34-channel targets
+    if (inputSource >= INPUT_RC_CH19 && inputSource <= INPUT_RC_CH34) {
+        return false;
+    }
Evidence
The firmware rejects inputs 44–59 on targets without the compile-time capability, but the
configurator lists all those inputs and fills its selector from that list without a capability
check.

inav -> inav-configurator
src/main/flight/servos.c[223-231]
src/main/flight/servos.h[70-88]
External repo: iNavFlight/inav-configurator, js/fc.js [962-977]
External repo: iNavFlight/inav-configurator, tabs/mixer.js [369-375]

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 configurator offers RC channels 19–34 on boards whose firmware now rejects them as servo-mixer inputs.
## Fix Focus Areas
- src/main/flight/servos.c[223-231]
- /cross_repos/inav-configurator/js/fc.js[962-977]
- /cross_repos/inav-configurator/tabs/mixer.js[369-375]
## Recommended Fix
Expose target-specific servo-mixer input support from the firmware if the configurator cannot already determine it, then update inav-configurator to omit or disable unsupported choices when adding or editing rules. Preserve a way to inspect and repair previously saved invalid rules.

ⓘ 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: Downgraded extended -> standard: change is below the extended eligibility bar (hunks 8/18, lines 55/200; both must reach the floor). Router rationale: Multiple validation paths and board-specific edge cases create independent defect opportunities.

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 c032abc — commit 59c899b

Target Flash Δ RAM Δ
MATEKF405 +220 B (+0.03%) CCM: ±0 B (±0.00%)
RAM: ±0 B (±0.00%)
MATEKF722 +428 B (+0.09%) ITCM_RAM: ±0 B (±0.00%)
RAM: -8 B (-0.01%)
TCM: ±0 B (±0.00%)
MATEKF765 +220 B (+0.03%) DTCM_RAM: ±0 B (±0.00%)
SRAM1: ±0 B (±0.00%)
MATEKH743 -116 B (-0.01%) 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.

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