Skip to content

Commit

Permalink
leds-pca963x: Fix device tree parsing
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ricardo Ribalda Delgado authored and Bryan Wu committed Aug 27, 2013
1 parent 56a1740 commit 8a6acd6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions drivers/leds/leds-pca963x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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", &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", &reg);
if (res != 0)
continue;
pca963x_leds[reg] = led;
}
pdata = devm_kzalloc(&client->dev,
Expand All @@ -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"))
Expand Down

0 comments on commit 8a6acd6

Please sign in to comment.