From d99ea41259ac48613b130609f4a3dde47d5c77a5 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Mon, 2 Aug 2021 11:56:47 -0600 Subject: [PATCH] power: Use u8/u16 for loop index Use u8/u16 instead of i16 as the value will never be negative and the bounds are known at compile time. Use a decrementing loop as SDCC generates more efficient code. Signed-off-by: Tim Crawford --- src/board/system76/common/power.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/board/system76/common/power.c b/src/board/system76/common/power.c index 594ec53..4b0a33e 100644 --- a/src/board/system76/common/power.c +++ b/src/board/system76/common/power.c @@ -294,7 +294,7 @@ void power_on_s5(void) { // Wait for SUSPWRDNACK validity tPLT01; - for (int16_t i = 0; i < 5000; i++) { + for (uint16_t i = 5000; i != 0; i--) { // If we reached S0, exit this loop update_power_state(); if (power_state == POWER_STATE_S0) { @@ -361,7 +361,7 @@ void power_off_s5(void) { static void power_peci_limit(bool ac) { uint8_t watts = ac ? POWER_LIMIT_AC : POWER_LIMIT_DC; // Retry, timeout errors happen occasionally - for (int16_t i = 0; i < 16; i++) { + for (uint8_t i = 16; i != 0; i--) { // Set PL4 using PECI int16_t res = peci_wr_pkg_config(60, 0, ((uint32_t)watts) * 8); DEBUG("power_peci_limit %d = %d\n", watts, res); @@ -466,7 +466,7 @@ void power_event(void) { bool ps_new = gpio_get(&PWR_SW_N); if (!ps_new && ps_last) { // Ensure press is not spurious - for (int16_t i = 0; i < 100; i++) { + for (uint8_t i = 100; i != 0; i--) { delay_ms(1); if (gpio_get(&PWR_SW_N) != ps_new) { DEBUG("%02X: Spurious press\n", main_cycle);