1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-21 13:58:08 +00:00

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

[no changelog]
This commit is contained in:
Pavol Rusnak 2024-03-25 16:06:15 +01:00 committed by TychoVrahe
parent 576ed7e04e
commit 4b189eb2cb
23 changed files with 40 additions and 42 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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();

View File

@ -403,7 +403,7 @@ void display_init(void) {
#define DISPLAY_GPIO_SPEED GPIO_SPEED_FREQ_LOW
#endif
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure = {0};
// LCD_RST/PC14
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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 */

View File

@ -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;

View File

@ -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();

View File

@ -72,7 +72,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;

View File

@ -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);

View File

@ -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;
}

View File

@ -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();