mirror of
https://github.com/linux-msm/laptops-kernel.git
synced 2026-08-13 14:19:53 -07:00
leds: st1202: Validate LED reg property against channel count
The reg property from the device tree is used directly as an array index
into chip->leds[] without bounds checking. A value >= ST1202_MAX_LEDS
would cause an out-of-bounds write during probe.
Fixes: 259230378c ("leds: Add LED1202 I2C driver")
Signed-off-by: Manuel Fombuena <fombuena@outlook.com>
Assisted-by: Claude:claude-sonnet-4-6
Link: https://patch.msgid.link/GV1PR08MB849718B43321DB7E5A05D17BC5F52@GV1PR08MB8497.eurprd08.prod.outlook.com
Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
committed by
Lee Jones
parent
0767335233
commit
cf197514bd
@@ -279,13 +279,19 @@ static int st1202_dt_init(struct st1202_chip *chip)
|
||||
{
|
||||
struct device *dev = &chip->client->dev;
|
||||
struct st1202_led *led;
|
||||
int err, reg;
|
||||
int err;
|
||||
u32 reg;
|
||||
|
||||
for_each_available_child_of_node_scoped(dev_of_node(dev), child) {
|
||||
err = of_property_read_u32(child, "reg", ®);
|
||||
if (err)
|
||||
return dev_err_probe(dev, err, "Invalid register\n");
|
||||
|
||||
if (reg >= ST1202_MAX_LEDS)
|
||||
return dev_err_probe(dev, -EINVAL,
|
||||
"LED reg %u out of range [0, %d]\n",
|
||||
reg, ST1202_MAX_LEDS - 1);
|
||||
|
||||
led = &chip->leds[reg];
|
||||
led->is_active = true;
|
||||
led->fwnode = of_fwnode_handle(child);
|
||||
|
||||
Reference in New Issue
Block a user