backlight: aw99706: Clamp negative max brightness values
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")
Signed-off-by Thorsten Blum <[email protected]>
--- drivers/video/backlight/aw99706.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/video/backlight/aw99706.c +2 -1
@@ -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)
Junjie Cao
maintainerHi 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