mirror of
https://github.com/torvalds/linux.git
synced 2026-09-23 05:04:02 +02:00
backlight: aw99706: Validate all DT property values consistently
The lookup helpers for dim-mode and ramp-ctl take a shortcut when
lookup_tbl is NULL: they accept any u32 value without range-checking
and return success unconditionally. Out-of-range values get silently
truncated by regmap_update_bits instead of triggering the dev_warn +
default-fallback path that the other properties use.
Add a field-width check for the NULL-table case so that values
exceeding the register field maximum are rejected the same way a
table-lookup miss is.
The switching frequency table has a second hole: reserved slots use 0
as their marker, so "awinic,sw-freq-hz = <0>" matches slot 0 and
programs a reserved encoding. Make the reserved marker U32_MAX and
skip such slots during lookup.
While here, also switch the error returns to -EINVAL for consistency.
Fixes: 147b38a5ad ("backlight: aw99706: Add support for Awinic AW99706 backlight")
Signed-off-by: Junjie Cao <junjie.cao@linux.dev>
Reviewed-by: Daniel Thompson (RISCstar) <danielt@kernel.org>
Link: https://patch.msgid.link/20260804030255.1934470-3-junjie.cao@intel.com
Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
parent
daf120e464
commit
3d142b19b0
|
|
@ -60,7 +60,7 @@
|
|||
#define AW99706_MTPLDOSEL_REG 0x1E
|
||||
#define AW99706_MTPRUN_REG 0x1F
|
||||
|
||||
#define RESV 0
|
||||
#define RESV U32_MAX
|
||||
|
||||
/* Boost switching frequency table, in Hz */
|
||||
static const u32 aw99706_sw_freq_tbl[] = {
|
||||
|
|
@ -94,17 +94,19 @@ static int aw99706_dt_property_lookup(const struct aw99706_dt_prop *prop,
|
|||
int i;
|
||||
|
||||
if (!prop->lookup_tbl) {
|
||||
if (dt_val > (prop->mask >> __ffs(prop->mask)))
|
||||
return -EINVAL;
|
||||
*val = dt_val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < prop->tbl_size; i++)
|
||||
if (prop->lookup_tbl[i] == dt_val)
|
||||
if (prop->lookup_tbl[i] != RESV && prop->lookup_tbl[i] == dt_val)
|
||||
break;
|
||||
|
||||
*val = i;
|
||||
|
||||
return i == prop->tbl_size ? -1 : 0;
|
||||
return i == prop->tbl_size ? -EINVAL : 0;
|
||||
}
|
||||
|
||||
#define MIN_ILED_MAX 5000
|
||||
|
|
@ -116,11 +118,14 @@ aw99706_dt_property_iled_max_convert(const struct aw99706_dt_prop *prop,
|
|||
u32 dt_val, u8 *val)
|
||||
{
|
||||
if (dt_val > MAX_ILED_MAX || dt_val < MIN_ILED_MAX)
|
||||
return -1;
|
||||
return -EINVAL;
|
||||
|
||||
if ((dt_val - MIN_ILED_MAX) % STEP_ILED_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
*val = (dt_val - MIN_ILED_MAX) / STEP_ILED_MAX;
|
||||
|
||||
return (dt_val - MIN_ILED_MAX) % STEP_ILED_MAX;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct aw99706_dt_prop aw99706_dt_props[] = {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user