Skip to contentSkip to conversation

backlight: aw99706: Clamp negative max brightness values

PATCH Superseded Thorsten Blum 2 participants 2 messages Nov 27

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 backlight: aw99706: Clamp negative max brightness values

device_property_read_u32() reads the "max-brightness" property directly into the signed int max_brightness field. Values larger than INT_MAX are interpreted as negative and pass the upper-bound check.

Also clamp negative values to AW99706_MAX_BRT_LVL to prevent this.

Fixes 147b38a5ad06 ("backlight: aw99706: Add support for Awinic AW99706 backlight")
---
 drivers/video/backlight/aw99706.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/video/backlight/aw99706.c +2 -1
index 43f82c83f91a..c8168a36284d 100644
@@ -272,7 +272,8 @@ static void aw99706_dt_parse(struct aw99706_device *aw,
 	device_property_read_u32(aw->dev, "max-brightness",
 				 &bl_props->max_brightness);
 
-	if (bl_props->max_brightness > AW99706_MAX_BRT_LVL)
+	if (bl_props->max_brightness < 0 ||
+	    bl_props->max_brightness > AW99706_MAX_BRT_LVL)
 		bl_props->max_brightness = AW99706_MAX_BRT_LVL;
 
 	if (bl_props->brightness > bl_props->max_brightness)
maintainer
#1 lore raw

Hi Thorsten,

default-brightness is also read into a signed int. With max-brightness = <100> and default-brightness = <0xffffffff>, brightness ends up as -1, so the upper-bound check misses it.

Could you clamp both values as u32 before assigning them to bl_props?

Thanks,
Junjie