Skip to content

fix(gps): guard against NULL serial port when GPS provider changed without reboot#11634

Open
daijoubu wants to merge 1 commit into
iNavFlight:release/9.1from
daijoubu:fix/gps-provider-null-guard
Open

fix(gps): guard against NULL serial port when GPS provider changed without reboot#11634
daijoubu wants to merge 1 commit into
iNavFlight:release/9.1from
daijoubu:fix/gps-provider-null-guard

Conversation

@daijoubu

@daijoubu daijoubu commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a hard fault that occurs when gps_provider is changed via CLI to a serial-based provider (e.g. UBLOX) after booting with a driver-based provider (MSP or FAKE) without rebooting.

Driver-based providers skip serial port opening in gpsInit(), leaving gpsState.gpsPort = NULL. On the next scheduler tick, gpsUpdate() dispatches into the serial protocol handler which calls serialRxBytesWaiting(NULL) → hard fault.

Changes

  • src/main/io/gps.c: Added guard in gpsUpdate() — returns false early when a serial-based provider is configured but gpsPort is NULL. Also added a NULL check in gpsEnablePassthrough() which had the same latent dereference.
  • src/test/unit/gps_null_port_unittest.cc: Unit test reproducing the bug (4 cases: RUNNING state crash, INITIALIZING state, positive non-NULL path, feature-disabled path).

Testing

  • Unit test confirms the bug: NullPortInRunningState_ShouldNotCrash fails before the fix (serialRxBytesWaiting called with NULL), passes after.
  • All 4 unit tests pass after the fix.
  • Full build matrix clean: SITL, MATEKF405 (F4), MATEKF765 (F7), KAKUTEH7WING (H7), IFLIGHT_BLITZ_ATF435 (AT32) — zero warnings.
  • Hardware tested on KAKUTEH7WING: set gps_provider = MSP on boot, then set gps_provider = UBLOX via CLI without reboot — board remained responsive, no hard fault.

…thout reboot

Driver-based providers (MSP, FAKE) leave gpsState.gpsPort NULL because
gpsInit() skips serial port opening for them. If gps_provider is then
changed via CLI to a serial-based provider without rebooting, the next
gpsUpdate() tick dispatches into the serial protocol handler with a NULL
port, causing a hard fault.

Add a guard in gpsUpdate() that returns false early when a serial-based
provider is configured but no port is open. Also guard gpsEnablePassthrough()
which had the same latent NULL dereference.
@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Test firmware build ready — commit d6db20e

Download firmware for PR #11634

238 targets built. Find your board's .hex file by name on that page (e.g. MATEKF405SE.hex). Files are individually downloadable — no GitHub login required.

Development build for testing only. Use Full Chip Erase when flashing.

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