Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds-pca963x: Fix device tree parsing

A malformed device tree could lead into a segmentation fault if the reg
value of a led is bigger than the number of leds.

A valid device tree could have only information about the last led of the
chip. Fix the device tree parsing to handle those cases.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
Signed-off-by: Bryan Wu <cooloney@gmail.com>

authored by

Ricardo Ribalda Delgado and committed by
Bryan Wu
8a6acd64 56a1740c

+4 -4
+4 -4
drivers/leds/leds-pca963x.c
··· 285 285 u32 reg; 286 286 int res; 287 287 288 + res = of_property_read_u32(child, "reg", &reg); 289 + if ((res != 0) || (reg >= chip->n_leds)) 290 + continue; 288 291 led.name = 289 292 of_get_property(child, "label", NULL) ? : child->name; 290 293 led.default_trigger = 291 294 of_get_property(child, "linux,default-trigger", NULL); 292 - res = of_property_read_u32(child, "reg", &reg); 293 - if (res != 0) 294 - continue; 295 295 pca963x_leds[reg] = led; 296 296 } 297 297 pdata = devm_kzalloc(&client->dev, ··· 300 300 return ERR_PTR(-ENOMEM); 301 301 302 302 pdata->leds.leds = pca963x_leds; 303 - pdata->leds.num_leds = count; 303 + pdata->leds.num_leds = chip->n_leds; 304 304 305 305 /* default to open-drain unless totem pole (push-pull) is specified */ 306 306 if (of_property_read_bool(np, "nxp,totem-pole"))