mirror of
https://github.com/micropython/micropython.git
synced 2025-07-21 21:11:12 +02:00
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 #5910. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit is contained in:
committed by
Damien George
parent
9ea8d2a031
commit
86c71a0307
@@ -196,6 +196,10 @@ static void machine_hw_spi_init_internal(machine_hw_spi_obj_t *self, mp_arg_val_
|
|||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args[ARG_bits].u_int != -1 && args[ARG_bits].u_int <= 0) {
|
||||||
|
mp_raise_ValueError(MP_ERROR_TEXT("invalid bits"));
|
||||||
|
}
|
||||||
|
|
||||||
if (args[ARG_bits].u_int != -1 && args[ARG_bits].u_int != self->bits) {
|
if (args[ARG_bits].u_int != -1 && args[ARG_bits].u_int != self->bits) {
|
||||||
self->bits = args[ARG_bits].u_int;
|
self->bits = args[ARG_bits].u_int;
|
||||||
changed = true;
|
changed = true;
|
||||||
|
Reference in New Issue
Block a user