From 784202383e91fa7fd1b92d79251cf936c0945eb6 Mon Sep 17 00:00:00 2001 From: Tim Crawford Date: Mon, 2 Aug 2021 11:56:47 -0600 Subject: [PATCH] fan: Use u8 for array access The index will never be negative and will never exceed 255. Change them from i16 to u8 so SDCC will generate more efficient code. Signed-off-by: Tim Crawford --- src/board/system76/common/fan.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/board/system76/common/fan.c b/src/board/system76/common/fan.c index 48a065f..e797557 100644 --- a/src/board/system76/common/fan.c +++ b/src/board/system76/common/fan.c @@ -26,7 +26,7 @@ void fan_reset(void) { // Get duty cycle based on temperature, adapted from // https://github.com/pop-os/system76-power/blob/master/src/fan.rs uint8_t fan_duty(const struct Fan * fan, int16_t temp) __reentrant { - for (int16_t i = 0; i < fan->points_size; i++) { + for (uint8_t i = 0; i < fan->points_size; i++) { const struct FanPoint * cur = &fan->points[i]; // If exactly the current temp, return the current duty @@ -86,7 +86,7 @@ void fan_duty_set(uint8_t peci_fan_duty, uint8_t dgpu_fan_duty) __reentrant { uint8_t fan_heatup(const struct Fan * fan, uint8_t duty) __reentrant { uint8_t lowest = duty; - int16_t i; + uint8_t i; for (i = 0; (i + 1) < fan->heatup_size; i++) { uint8_t value = fan->heatup[i + 1]; if (value < lowest) { @@ -102,7 +102,7 @@ uint8_t fan_heatup(const struct Fan * fan, uint8_t duty) __reentrant { uint8_t fan_cooldown(const struct Fan * fan, uint8_t duty) __reentrant { uint8_t highest = duty; - int16_t i; + uint8_t i; for (i = 0; (i + 1) < fan->cooldown_size; i++) { uint8_t value = fan->cooldown[i + 1]; if (value > highest) {