fix(core): always zero-initialize structures in trezorhal

[no changelog]
Pavol Rusnak 1 month ago committed by tychovrahe
parent cea992fead
commit d3810f9282

@ -29,7 +29,7 @@ void backlight_pwm_init(void) {
BACKLIGHT_PWM_PORT_CLK_EN();
BACKLIGHT_PWM_TIM_CLK_EN();
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// LCD_PWM (backlight control)
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;

@ -8,7 +8,7 @@ void button_init(void) {
BTN_LEFT_CLK_ENA();
BTN_RIGHT_CLK_ENA();
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.Mode = GPIO_MODE_INPUT;
GPIO_InitStructure.Pull = GPIO_PULLUP;

@ -42,7 +42,7 @@ void consumption_mask_init(void) {
consumption_mask_randomize();
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
@ -51,7 +51,7 @@ void consumption_mask_init(void) {
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
__HAL_RCC_TIM8_CLK_ENABLE();
TIM_HandleTypeDef TIM8_Handle;
TIM_HandleTypeDef TIM8_Handle = {0};
TIM8_Handle.State = HAL_TIM_STATE_RESET;
TIM8_Handle.Instance = TIM8;
TIM8_Handle.Init.Period = TIMER_PERIOD;
@ -61,7 +61,7 @@ void consumption_mask_init(void) {
TIM8_Handle.Init.RepetitionCounter = 0;
HAL_TIM_PWM_Init(&TIM8_Handle);
TIM_OC_InitTypeDef TIM_OC_InitStructure;
TIM_OC_InitTypeDef TIM_OC_InitStructure = {0};
TIM_OC_InitStructure.Pulse = 0;
TIM_OC_InitStructure.OCMode = TIM_OCMODE_PWM1;
TIM_OC_InitStructure.OCPolarity = TIM_OCPOLARITY_LOW;

@ -279,7 +279,7 @@ static void ili9341_Write(uint16_t Value) {
}
void ili9341_spi_init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
/* Configure NCS in Output Push-Pull mode */
LCD_WRX_GPIO_CLK_ENABLE();

@ -79,7 +79,7 @@ static void display_unsleep(void) {}
* @param FB_Address: the layer frame buffer.
*/
void BSP_LCD_LayerDefaultInit(uint16_t LayerIndex, uint32_t FB_Address) {
LTDC_LayerCfgTypeDef Layercfg;
LTDC_LayerCfgTypeDef Layercfg = {0};
/* Layer Init */
Layercfg.WindowX0 = 0;
@ -222,7 +222,7 @@ int display_backlight(int val) {
void display_init_seq(void) { display_unsleep(); }
void display_init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
/* Enable the LTDC and DMA2D Clock */
__HAL_RCC_LTDC_CLK_ENABLE();

@ -368,7 +368,7 @@ void display_init(void) {
backlight_pwm_init();
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// LCD_RST/PC14
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;

@ -277,7 +277,7 @@ void display_init(void) {
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_FMC_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// LCD_RST/PC14
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;

@ -161,7 +161,7 @@ void display_init(void) {
OLED_SPI_MOSI_CLK_ENA();
OLED_SPI_CLK_ENA();
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// set GPIO for OLED display
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;

@ -54,7 +54,7 @@ static void dma2d_init_clut(uint16_t fg, uint16_t bg, dma2d_layer_t layer) {
table[i] = interpolate_rgb888_color(fg32, bg32, i);
}
DMA2D_CLUTCfgTypeDef clut;
DMA2D_CLUTCfgTypeDef clut = {0};
clut.CLUTColorMode = DMA2D_CCM_ARGB8888;
clut.Size = 0xf;
clut.pCLUT = 0; // loading directly

@ -46,7 +46,7 @@ void i2c_init_instance(uint16_t idx, i2c_instance_t *instance) {
return;
}
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// configure CTP I2C SCL and SDA GPIO lines
GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
@ -120,7 +120,7 @@ void i2c_cycle(uint16_t idx) {
i2c_deinit(idx);
// 2. Configure SCL/SDA as GPIO OUTPUT Open Drain
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;

@ -160,7 +160,7 @@ void periph_init(void) {
// this detector will be active regardless of the
// flash option byte BOR setting.
__HAL_RCC_PWR_CLK_ENABLE();
PWR_PVDTypeDef pvd_config;
PWR_PVDTypeDef pvd_config = {0};
pvd_config.PVDLevel = PWR_PVDLEVEL_5;
pvd_config.Mode = PWR_PVD_MODE_IT_RISING_FALLING;
HAL_PWR_ConfigPVD(&pvd_config);

@ -5,7 +5,7 @@
void optiga_hal_init(void) {
OPTIGA_RST_CLK_EN();
// init reset pin
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;

@ -90,7 +90,7 @@ void rgb_led_set_color(uint32_t color) {
void rgb_led_init(void) {
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_HIGH;
@ -99,7 +99,7 @@ void rgb_led_init(void) {
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
__HAL_RCC_TIM4_CLK_ENABLE();
TIM_HandleTypeDef TIM4_Handle;
TIM_HandleTypeDef TIM4_Handle = {0};
TIM4_Handle.State = HAL_TIM_STATE_RESET;
TIM4_Handle.Instance = TIM4;
TIM4_Handle.Init.Period = TIMER_PERIOD;
@ -110,7 +110,7 @@ void rgb_led_init(void) {
HAL_TIM_PWM_Init(&TIM4_Handle);
__HAL_RCC_TIM8_CLK_ENABLE();
TIM_HandleTypeDef TIM8_Handle;
TIM_HandleTypeDef TIM8_Handle = {0};
TIM8_Handle.State = HAL_TIM_STATE_RESET;
TIM8_Handle.Instance = TIM8;
TIM8_Handle.Init.Period = TIMER_PERIOD;
@ -120,7 +120,7 @@ void rgb_led_init(void) {
TIM8_Handle.Init.RepetitionCounter = 0;
HAL_TIM_PWM_Init(&TIM8_Handle);
TIM_OC_InitTypeDef TIM_OC_InitStructure;
TIM_OC_InitTypeDef TIM_OC_InitStructure = {0};
TIM_OC_InitStructure.Pulse = 0;
TIM_OC_InitStructure.OCMode = TIM_OCMODE_PWM1;
TIM_OC_InitStructure.OCPolarity = TIM_OCPOLARITY_LOW;

@ -22,7 +22,7 @@
#include "sbu.h"
void sbu_init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// SBU1/PA2 SBU2/PA3
GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_3;

@ -44,7 +44,7 @@ static uint32_t SDMMC_GetCmdResp1(SDIO_TypeDef *SDIOx, uint8_t SD_CMD,
// this function is inspired by functions in stm32f4xx_ll_sdmmc.c
uint32_t SDMMC_CmdSetClrCardDetect(SDIO_TypeDef *SDIOx, uint32_t Argument) {
SDIO_CmdInitTypeDef sdmmc_cmdinit;
SDIO_CmdInitTypeDef sdmmc_cmdinit = {0};
uint32_t errorstate = SDMMC_ERROR_NONE;
sdmmc_cmdinit.Argument = (uint32_t)Argument;

@ -77,7 +77,7 @@ static inline void sdcard_default_pin_state(void) {
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_RESET); // SD_CLK/PC12
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET); // SD_CMD/PD2
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// configure the SD card circuitry on/off pin
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
@ -109,7 +109,7 @@ static inline void sdcard_active_pin_state(void) {
GPIO_PIN_RESET); // SD_ON/PC0
HAL_Delay(10); // we need to wait until the circuit fully kicks-in
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// configure SD GPIO
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
@ -220,7 +220,7 @@ uint64_t sdcard_get_capacity_in_bytes(void) {
if (sd_handle.Instance == NULL) {
return 0;
}
HAL_SD_CardInfoTypeDef cardinfo;
HAL_SD_CardInfoTypeDef cardinfo = {0};
HAL_SD_GetCardInfo(&sd_handle, &cardinfo);
return (uint64_t)cardinfo.LogBlockNbr * (uint64_t)cardinfo.LogBlockSize;
}
@ -319,8 +319,7 @@ secbool sdcard_read_blocks(uint32_t *dest, uint32_t block_num,
// because STMHAL tries to access its error code in SD_DMAError()
// even though it shouldn't :-/
// this will get removed eventually when we update to new STMHAL
DMA_HandleTypeDef dummy_dma;
memset(&dummy_dma, 0, sizeof(dummy_dma));
DMA_HandleTypeDef dummy_dma = {0};
sd_handle.hdmatx = &dummy_dma;
svc_enableIRQ(DMA2_Stream3_IRQn);
@ -381,8 +380,7 @@ secbool sdcard_write_blocks(const uint32_t *src, uint32_t block_num,
// because HAL tries to access its error code in SD_DMAError()
// even though it shouldn't :-/
// this will get removed eventually when we update to new STMHAL
DMA_HandleTypeDef dummy_dma;
memset(&dummy_dma, 0, sizeof(dummy_dma));
DMA_HandleTypeDef dummy_dma = {0};
sd_handle.hdmarx = &dummy_dma;
svc_enableIRQ(DMA2_Stream3_IRQn);

@ -290,7 +290,7 @@ void BSP_SDRAM_DMA_IRQHandler(void) { HAL_DMA_IRQHandler(SdramHandle.hdma); }
*/
void BSP_SDRAM_MspInit(SDRAM_HandleTypeDef *hsdram, void *Params) {
static DMA_HandleTypeDef dmaHandle;
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
if (hsdram != (SDRAM_HandleTypeDef *)NULL) {
/* Enable FMC clock */

@ -62,7 +62,7 @@ static void touch_default_pin_state(void) {
// held in reset until released
// set above pins to OUTPUT / NOPULL
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
@ -89,7 +89,7 @@ static void touch_active_pin_state(void) {
HAL_GPIO_WritePin(TOUCH_ON_PORT, TOUCH_ON_PIN, GPIO_PIN_RESET); // CTP_ON
HAL_Delay(10); // we need to wait until the circuit fully kicks-in
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// capacitive touch panel module (CTPM) interrupt (INT) input
GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;
@ -137,7 +137,7 @@ void touch_power_off(void) {
}
secbool touch_init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// PC4 capacitive touch panel module (CTPM) interrupt (INT) input
GPIO_InitStructure.Mode = GPIO_MODE_IT_RISING;

@ -324,7 +324,7 @@ static void touch_active_pin_state(void) {
// HAL_GPIO_WritePin(GPIOB, GPIO_PIN_10, GPIO_PIN_RESET); // CTP_ON/PB10
// HAL_Delay(10); // we need to wait until the circuit fully kicks-in
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// PC4 capacitive touch panel module (CTPM) interrupt (INT) input
GPIO_InitStructure.Mode = GPIO_MODE_IT_FALLING;
@ -471,7 +471,7 @@ void stmpe811_Reset() {
}
secbool touch_init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
__HAL_RCC_GPIOA_CLK_ENABLE();

@ -68,7 +68,7 @@ void i2c_init_instance(uint16_t idx, i2c_instance_t *instance) {
return;
}
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// configure CTP I2C SCL and SDA GPIO lines
GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;

@ -273,7 +273,7 @@ void periph_init(void) {
// this detector will be active regardless of the
// flash option byte BOR setting.
__HAL_RCC_PWR_CLK_ENABLE();
PWR_PVDTypeDef pvd_config;
PWR_PVDTypeDef pvd_config = {0};
pvd_config.PVDLevel = PWR_PVDLEVEL_5;
pvd_config.Mode = PWR_PVD_MODE_IT_RISING_FALLING;
HAL_PWR_ConfigPVD(&pvd_config);

@ -60,7 +60,7 @@ static SD_HandleTypeDef sd_handle = {0};
// this function is inspired by functions in stm32f4xx_ll_sdmmc.c
uint32_t SDMMC_CmdSetClrCardDetect(SDMMC_TypeDef *SDMMCx, uint32_t Argument) {
SDMMC_CmdInitTypeDef sdmmc_cmdinit;
SDMMC_CmdInitTypeDef sdmmc_cmdinit = {0};
uint32_t errorstate = SDMMC_ERROR_NONE;
sdmmc_cmdinit.Argument = (uint32_t)Argument;
@ -85,7 +85,7 @@ static inline void sdcard_default_pin_state(void) {
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_12, GPIO_PIN_RESET); // SD_CLK/PC12
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_2, GPIO_PIN_RESET); // SD_CMD/PD2
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// configure the SD card circuitry on/off pin
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
@ -116,7 +116,7 @@ static inline void sdcard_active_pin_state(void) {
HAL_GPIO_WritePin(SD_ENABLE_PORT, SD_ENABLE_PIN, GPIO_PIN_RESET);
HAL_Delay(10); // we need to wait until the circuit fully kicks-in
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// configure SD GPIO
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
@ -223,7 +223,7 @@ uint64_t sdcard_get_capacity_in_bytes(void) {
if (sd_handle.Instance == NULL) {
return 0;
}
HAL_SD_CardInfoTypeDef cardinfo;
HAL_SD_CardInfoTypeDef cardinfo = {0};
HAL_SD_GetCardInfo(&sd_handle, &cardinfo);
return (uint64_t)cardinfo.LogBlockNbr * (uint64_t)cardinfo.LogBlockSize;
}

@ -812,7 +812,7 @@ int32_t BSP_TS_EnableIT(uint32_t Instance) {
/* Prevent unused argument(s) compilation warning */
UNUSED(Instance);
GPIO_InitTypeDef gpio_init_structure;
GPIO_InitTypeDef gpio_init_structure = {0};
__HAL_RCC_GPIOE_CLK_ENABLE();

Loading…
Cancel
Save