esp32/machine_hw_spi: Reject invalid number of bits in constructor. #15950
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
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.
This fixes #5910.
Testing
This was tested locally on an ESP32-D0WD:
Trade-offs and Alternatives
This PR fixes the issue on ESP32, but maybe this is still a problems on other ports. I do not have many non-ESP32 boards that are currently supported around here so I can only claim this fixes the ESP32 version of the bug. Given that the bus instances are constructed in platform-specific code then I'd have to fix all of them if they have this specific issue. I've got no problem in doing the fix on other platforms but I may not be able to perform code validation.