Skip to content

Commit 86c71a0

Browse files
agattidpgeorge
authored andcommitted
esp32/machine_hw_spi: Reject invalid number of bits in constructor.
This commit adds an extra bit of parameters validation to the SPI bus constructor on ESP32. Passing 0 as the number of bits would trigger a division by zero error when performing read/write operations on an SPI bus created in such a fashion. Fixes issue micropython#5910. Signed-off-by: Alessandro Gatti <[email protected]>
1 parent 9ea8d2a commit 86c71a0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

ports/esp32/machine_hw_spi.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,10 @@ static void machine_hw_spi_init_internal(machine_hw_spi_obj_t *self, mp_arg_val_
196196
changed = true;
197197
}
198198

199+
if (args[ARG_bits].u_int != -1 && args[ARG_bits].u_int <= 0) {
200+
mp_raise_ValueError(MP_ERROR_TEXT("invalid bits"));
201+
}
202+
199203
if (args[ARG_bits].u_int != -1 && args[ARG_bits].u_int != self->bits) {
200204
self->bits = args[ARG_bits].u_int;
201205
changed = true;

0 commit comments

Comments
 (0)