Skip to content

Fix NULL pointer dereference in STM32 SPI construct#10924

Closed
ChrisNourse wants to merge 1 commit intoadafruit:mainfrom
ChrisNourse:fix-stm32-spi-null-deref
Closed

Fix NULL pointer dereference in STM32 SPI construct#10924
ChrisNourse wants to merge 1 commit intoadafruit:mainfrom
ChrisNourse:fix-stm32-spi-null-deref

Conversation

@ChrisNourse
Copy link
Copy Markdown

Summary

  • Fixes a NULL pointer dereference in common_hal_busio_spi_construct() on the STM32 port that crashed all STM32 boards using SPI (including STM32F405 boards whose CIRCUITPY filesystem lives on external SPI flash).
  • The common_hal_busio_spi_mark_deinit(self) call (added in 6b458a9) was placed after check_pins(), which sets self->sck. mark_deinit then NULLed self->sck, and the immediately following self->sck->altfn_index dereference caused a crash.
  • The fix moves mark_deinit() before check_pins(), aligning the STM port with every other port (espressif, nordic, raspberrypi, atmel-samd, mimxrt10xx, etc.) which all call mark_deinit first.

Fixes #10866

Test plan

  • Built firmware for feather_stm32f405_express — compiles cleanly
  • Flashed to hardware — board boots, CIRCUITPY drive mounts (previously failed with "CIRCUITPY drive could not be found or created")
  • Verified filesystem access via storage.getmount('/'), os.listdir('/'), os.statvfs('/')
  • Verified busio.SPI(board.SCK, board.MOSI, board.MISO) construct/deinit works

🤖 Generated with Claude Code

Move mark_deinit() before check_pins() so that self->sck is not
NULLed after check_pins sets it. The previous ordering caused a
NULL dereference of self->sck->altfn_index, crashing all STM32
boards that use SPI (including STM32F405 boards whose CIRCUITPY
filesystem lives on external SPI flash).

Fixes adafruit#10866

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding this!!

I would have asked you to submit this against 10.1.x instead of main, but we are planning to release 10.2.0 within a week or two. If you would like to see this in a numbered release really really soon, you can resubmit against 10.1.x and I'll make a release within a couple of days.

@ChrisNourse ChrisNourse marked this pull request as draft April 7, 2026 17:42
@ChrisNourse
Copy link
Copy Markdown
Author

Amazing! I Created a new PR
#10926

Closing this one

@ChrisNourse ChrisNourse closed this Apr 7, 2026
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.

CP 10.1.3 bin file for Sparkfun MicroMod STM32F405 appears to be broken

2 participants