Skip to content

Commit 974cc2c

Browse files
authored
Merge pull request #10926 from ChrisNourse/fix-stm32-spi-null-deref-10.1.x
Fix NULL pointer dereference in STM32 SPI construct
2 parents 4a10c22 + 0d968ae commit 974cc2c

File tree

1 file changed

+4
-3
lines changed
  • ports/stm/common-hal/busio

1 file changed

+4
-3
lines changed

ports/stm/common-hal/busio/SPI.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,13 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self,
136136
const mcu_pin_obj_t *sck, const mcu_pin_obj_t *mosi,
137137
const mcu_pin_obj_t *miso, bool half_duplex) {
138138

139+
// Ensure the object starts in its deinit state before check_pins sets
140+
// self->sck, self->mosi, and self->miso.
141+
common_hal_busio_spi_mark_deinit(self);
142+
139143
int periph_index = check_pins(self, sck, mosi, miso);
140144
SPI_TypeDef *SPIx = mcu_spi_banks[periph_index - 1];
141145

142-
// Ensure the object starts in its deinit state.
143-
common_hal_busio_spi_mark_deinit(self);
144-
145146
// Start GPIO for each pin
146147
GPIO_InitTypeDef GPIO_InitStruct = {0};
147148
GPIO_InitStruct.Pin = pin_mask(sck->number);

0 commit comments

Comments
 (0)