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(-)

diff --git a/drivers/video/backlight/aw99706.c 
b/drivers/video/backlight/aw99706.c
index 43f82c83f91a..c8168a36284d 100644
--- a/drivers/video/backlight/aw99706.c
+++ b/drivers/video/backlight/aw99706.c
@@ -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)

Reply via email to