* [PATCH v2] backlight: aw99706: Clamp negative brightness values
@ 2026-11-27 10:33 Thorsten Blum
0 siblings, 0 replies; only message in thread
From: Thorsten Blum @ 2026-11-27 10:33 UTC (permalink / raw)
To: Junjie Cao, Lee Jones, Daniel Thompson, Jingoo Han, Helge Deller,
Pengyu Luo
Cc: Thorsten Blum, Junjie Cao, dri-devel, linux-fbdev
device_property_read_u32() reads both the "default-brightness" and the
"max-brightness" properties directly into signed int fields. Therefore,
values larger than INT_MAX are interpreted as negative and pass the
upper-bound checks.
Read both properties into a temporary u32 and clamp the values before
assigning them to the signed backlight properties.
Fixes: 147b38a5ad06 ("backlight: aw99706: Add support for Awinic AW99706 backlight")
Signed-off-by: Thorsten Blum <blum@kernel.org>
---
Changes in v2:
- Also clamp the default brightness (Junjie)
- Clamp both values before assigning them to bl_props (Junjie)
- Update patch subject and description
- v1: https://lore.kernel.org/r/20261127021423.656745-2-blum@kernel.org/
drivers/video/backlight/aw99706.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/drivers/video/backlight/aw99706.c b/drivers/video/backlight/aw99706.c
index 43f82c83f91a..1ea5d0d2146d 100644
--- a/drivers/video/backlight/aw99706.c
+++ b/drivers/video/backlight/aw99706.c
@@ -265,18 +265,13 @@ static void aw99706_dt_parse(struct aw99706_device *aw,
aw->init_tbl[i].val = val << __ffs(prop->mask);
}
- bl_props->brightness = AW99706_MAX_BRT_LVL >> 1;
- bl_props->max_brightness = AW99706_MAX_BRT_LVL;
- device_property_read_u32(aw->dev, "default-brightness",
- &bl_props->brightness);
- device_property_read_u32(aw->dev, "max-brightness",
- &bl_props->max_brightness);
-
- if (bl_props->max_brightness > AW99706_MAX_BRT_LVL)
- bl_props->max_brightness = AW99706_MAX_BRT_LVL;
-
- if (bl_props->brightness > bl_props->max_brightness)
- bl_props->brightness = bl_props->max_brightness;
+ dt_val = AW99706_MAX_BRT_LVL;
+ device_property_read_u32(aw->dev, "max-brightness", &dt_val);
+ bl_props->max_brightness = min(dt_val, AW99706_MAX_BRT_LVL);
+
+ dt_val = AW99706_MAX_BRT_LVL >> 1;
+ device_property_read_u32(aw->dev, "default-brightness", &dt_val);
+ bl_props->brightness = min_t(u32, dt_val, bl_props->max_brightness);
}
static int aw99706_hw_init(struct aw99706_device *aw)
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-27 10:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 10:33 [PATCH v2] backlight: aw99706: Clamp negative brightness values Thorsten Blum
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox