Skip to content

Commit 9605902

Browse files
jplexergmarull
authored andcommitted
fw/services/common/light: fix dynamic backlight integer underflow
When user max intensity is set below 10% (the hardcoded low_intensity threshold), the dynamic backlight calculation would cause an integer underflow. The subtraction (user_max_intensity - low_intensity) wraps around in unsigned arithmetic, producing a very large value that results in brightness exceeding BACKLIGHT_BRIGHTNESS_MAX (appearing as >100%). Fix by clamping user_max_intensity to low_intensity minimum before performing the calculation. Fixes backlight showing 187% when max intensity set to LOW (5%) on Obelix PVT 4.9.110. Signed-off-by: Joshua Jun <joshuajun@proton.me>
1 parent 4402b11 commit 9605902

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/fw/services/common/light.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ static uint16_t prv_backlight_get_intensity(void) {
115115
const uint32_t min_light_threshold = backlight_get_dynamic_min_threshold();
116116
const uint32_t max_light_threshold = backlight_get_dynamic_max_threshold();
117117

118+
// If user max intensity is below low intensity, clamp to low intensity
119+
// to prevent underflow in the calculation below
120+
if (user_max_intensity < low_intensity) {
121+
user_max_intensity = low_intensity;
122+
}
123+
118124
// If below minimum threshold, return low intensity
119125
if (light_level < min_light_threshold) {
120126
return low_intensity;

0 commit comments

Comments
 (0)