diff options
author | Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com> | 2013-08-14 14:23:51 -0700 |
---|---|---|
committer | Bryan Wu <cooloney@gmail.com> | 2013-08-26 17:22:14 -0700 |
commit | 8a6acd648c1dfdc82f1bbcd15f7777962054c268 (patch) | |
tree | 6fede8ad80ec6b4c0a33c5db6e77f45af5d8702d /drivers/leds/leds-pca963x.c | |
parent | 56a1740c21e4396164265c3ec80e29990ddcdc36 (diff) | |
download | blackbird-op-linux-8a6acd648c1dfdc82f1bbcd15f7777962054c268.tar.gz blackbird-op-linux-8a6acd648c1dfdc82f1bbcd15f7777962054c268.zip |
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/leds-pca963x.c')
-rw-r--r-- | drivers/leds/leds-pca963x.c | 8 |
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) u32 reg; int res; + res = of_property_read_u32(child, "reg", ®); + if ((res != 0) || (reg >= chip->n_leds)) + continue; led.name = of_get_property(child, "label", NULL) ? : child->name; led.default_trigger = of_get_property(child, "linux,default-trigger", NULL); - res = of_property_read_u32(child, "reg", ®); - if (res != 0) - continue; pca963x_leds[reg] = led; } pdata = devm_kzalloc(&client->dev, @@ -300,7 +300,7 @@ pca963x_dt_init(struct i2c_client *client, struct pca963x_chipdef *chip) return ERR_PTR(-ENOMEM); pdata->leds.leds = pca963x_leds; - pdata->leds.num_leds = count; + pdata->leds.num_leds = chip->n_leds; /* default to open-drain unless totem pole (push-pull) is specified */ if (of_property_read_bool(np, "nxp,totem-pole")) |