From: Thorsten Blum <blum@kernel.org>
To: Junjie Cao <junjie.cao@linux.dev>, Lee Jones <lee@kernel.org>,
Daniel Thompson <danielt@kernel.org>,
Jingoo Han <jingoohan1@gmail.com>, Helge Deller <deller@gmx.de>,
Pengyu Luo <mitltlatltl@gmail.com>
Cc: Thorsten Blum <blum@kernel.org>,
Junjie Cao <caojunjie650@gmail.com>,
dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org
Subject: [PATCH v2] backlight: aw99706: Clamp negative brightness values
Date: Fri, 27 Nov 2026 11:33:42 +0100 [thread overview]
Message-ID: <20261127103341.663905-3-blum@kernel.org> (raw)
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)
reply other threads:[~2026-11-27 10:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261127103341.663905-3-blum@kernel.org \
--to=blum@kernel.org \
--cc=caojunjie650@gmail.com \
--cc=danielt@kernel.org \
--cc=deller@gmx.de \
--cc=dri-devel@lists.freedesktop.org \
--cc=jingoohan1@gmail.com \
--cc=junjie.cao@linux.dev \
--cc=lee@kernel.org \
--cc=linux-fbdev@vger.kernel.org \
--cc=mitltlatltl@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox