aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/leds
diff options
context:
space:
mode:
authorRicardo Ribalda Delgado <ricardo.ribalda@gmail.com>2013-08-14 17:23:51 -0400
committerBryan Wu <cooloney@gmail.com>2013-08-26 20:22:14 -0400
commit8a6acd648c1dfdc82f1bbcd15f7777962054c268 (patch)
tree6fede8ad80ec6b4c0a33c5db6e77f45af5d8702d /drivers/leds
parent56a1740c21e4396164265c3ec80e29990ddcdc36 (diff)
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>
Diffstat (limited to 'drivers/leds')
-rw-r--r--drivers/leds/leds-pca963x.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/leds/leds-pca963x.c b/drivers/leds/leds-pca963x.c
index 35d56a62f92f..82589c0a5689 100644
--- a/drivers/leds/leds-pca963x.c
+++ b/drivers/leds/leds-pca963x.c
@@ -285,13 +285,13 @@ pca963x_dt_init(struct i2c_client *client, struct pca963x_chipdef *chip)
285 u32 reg; 285 u32 reg;
286 int res; 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 led.name = 291 led.name =
289 of_get_property(child, "label", NULL) ? : child->name; 292 of_get_property(child, "label", NULL) ? : child->name;
290 led.default_trigger = 293 led.default_trigger =
291 of_get_property(child, "linux,default-trigger", NULL); 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 pca963x_leds[reg] = led; 295 pca963x_leds[reg] = led;
296 } 296 }
297 pdata = devm_kzalloc(&client->dev, 297 pdata = devm_kzalloc(&client->dev,
@@ -300,7 +300,7 @@ pca963x_dt_init(struct i2c_client *client, struct pca963x_chipdef *chip)
300 return ERR_PTR(-ENOMEM); 300 return ERR_PTR(-ENOMEM);
301 301
302 pdata->leds.leds = pca963x_leds; 302 pdata->leds.leds = pca963x_leds;
303 pdata->leds.num_leds = count; 303 pdata->leds.num_leds = chip->n_leds;
304 304
305 /* default to open-drain unless totem pole (push-pull) is specified */ 305 /* default to open-drain unless totem pole (push-pull) is specified */
306 if (of_property_read_bool(np, "nxp,totem-pole")) 306 if (of_property_read_bool(np, "nxp,totem-pole"))