From b23de0f8a1bbda8d96e607ecb7ee794cb5f6401a Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Wed, 29 Sep 2021 22:45:38 +0800 Subject: [PATCH] twdt: Fix timeout decimal literals to prevent uint32_t overflow This commit fixes the decimal literals used in calculating task watchdog timeouts to prevent them from causing a uint32_t oveflow. Closes https://github.com/espressif/esp-idf/issues/6648 --- components/esp_system/task_wdt.c | 26 +++++++++----------------- tools/ci/check_copyright_ignore.txt | 1 - 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/components/esp_system/task_wdt.c b/components/esp_system/task_wdt.c index 4a08d85d45..cde04ce719 100644 --- a/components/esp_system/task_wdt.c +++ b/components/esp_system/task_wdt.c @@ -1,16 +1,8 @@ -// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include @@ -226,9 +218,9 @@ esp_err_t esp_task_wdt_init(uint32_t timeout, bool panic) wdt_hal_init(&twdt_context, TWDT_INSTANCE, TWDT_PRESCALER, true); wdt_hal_write_protect_disable(&twdt_context); //Configure 1st stage timeout and behavior - wdt_hal_config_stage(&twdt_context, WDT_STAGE0, twdt_config->timeout * 1000000 / TWDT_TICKS_PER_US, WDT_STAGE_ACTION_INT); + wdt_hal_config_stage(&twdt_context, WDT_STAGE0, twdt_config->timeout * (1000000 / TWDT_TICKS_PER_US), WDT_STAGE_ACTION_INT); //Configure 2nd stage timeout and behavior - wdt_hal_config_stage(&twdt_context, WDT_STAGE1, 2*twdt_config->timeout * 1000000 / TWDT_TICKS_PER_US, WDT_STAGE_ACTION_RESET_SYSTEM); + wdt_hal_config_stage(&twdt_context, WDT_STAGE1, twdt_config->timeout * (2 * 1000000 / TWDT_TICKS_PER_US), WDT_STAGE_ACTION_RESET_SYSTEM); //Enable the WDT wdt_hal_enable(&twdt_context); wdt_hal_write_protect_enable(&twdt_context); @@ -240,8 +232,8 @@ esp_err_t esp_task_wdt_init(uint32_t timeout, bool panic) //Reconfigure hardware timer wdt_hal_write_protect_disable(&twdt_context); wdt_hal_disable(&twdt_context); - wdt_hal_config_stage(&twdt_context, WDT_STAGE0, twdt_config->timeout*1000*1000/TWDT_TICKS_PER_US, WDT_STAGE_ACTION_INT); - wdt_hal_config_stage(&twdt_context, WDT_STAGE1, 2*twdt_config->timeout*1000*1000/TWDT_TICKS_PER_US, WDT_STAGE_ACTION_RESET_SYSTEM); + wdt_hal_config_stage(&twdt_context, WDT_STAGE0, twdt_config->timeout * (1000 * 1000 / TWDT_TICKS_PER_US), WDT_STAGE_ACTION_INT); + wdt_hal_config_stage(&twdt_context, WDT_STAGE1, twdt_config->timeout * (2 * 1000 * 1000 / TWDT_TICKS_PER_US), WDT_STAGE_ACTION_RESET_SYSTEM); wdt_hal_enable(&twdt_context); wdt_hal_write_protect_enable(&twdt_context); } diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 8529b53eec..9842e231d3 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -1165,7 +1165,6 @@ components/esp_system/port/soc/esp32s3/system_internal.c components/esp_system/port/soc/esp32s3/usb_console.c components/esp_system/stack_check.c components/esp_system/system_time.c -components/esp_system/task_wdt.c components/esp_system/test/test_delay.c components/esp_system/test/test_reset_reason.c components/esp_system/test/test_sleep.c