Cypress: Fix unitialized memory in spi_master_write

'received' was declared as an int but populated by cyhal_spi_transfer
after being cast to to (uint8_t *), which left the upper 3 bytes
uninitialized. Instead, declare as uint8_t and let the compiler upcast
the value when it is returned.
pull/12819/head
Kyle Kearney 2020-04-15 11:13:43 -07:00
parent 7b0c38aabb
commit 76a14f2ff4
1 changed files with 2 additions and 2 deletions

View File

@ -140,9 +140,9 @@ void spi_frequency(spi_t *obj, int hz)
int spi_master_write(spi_t *obj, int value)
{
struct spi_s *spi = cy_get_spi(obj);
int received;
uint8_t received;
if (CY_RSLT_SUCCESS != cyhal_spi_transfer(&(spi->hal_spi), (const uint8_t *)&value, 1, (uint8_t *)&received, 1, 0xff)) {
if (CY_RSLT_SUCCESS != cyhal_spi_transfer(&(spi->hal_spi), (const uint8_t *)&value, 1, &received, 1, 0xff)) {
MBED_ERROR(MBED_MAKE_ERROR(MBED_MODULE_DRIVER_SPI, MBED_ERROR_CODE_FAILED_OPERATION), "cyhal_spi_transfer");
}
return received;