aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2013-10-31 22:33:45 -0400
committerBryan Wu <cooloney@gmail.com>2014-01-27 20:28:42 -0500
commit9334129e8e956edfd51da37d5e5278478235c7b2 (patch)
tree2fb3451c09c97fde621ab6af0b7654502edfc973
parent802eee95bde72fd0cd0f3a5b2098375a487d1eda (diff)
LEDS: tca6507 - fix bugs in parsing of device-tree configuration.
1/ The led_info array must be allocated to allow the full number of LEDs even if not all are present. The array maybe be sparsely filled but it is indexed by device address so we must at least allocate as many slots as the highest address used. It is easiest just to allocate all 7. 2/ range check the 'reg' value properly. 3/ led.flags must be initialised to zero, else all leds could be treated as GPIOs (depending on what happens to be on the stack). Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Bryan Wu <cooloney@gmail.com>
-rw-r--r--drivers/leds/leds-tca6507.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/drivers/leds/leds-tca6507.c b/drivers/leds/leds-tca6507.c
index 8cc304f36728..f5063f447463 100644
--- a/drivers/leds/leds-tca6507.c
+++ b/drivers/leds/leds-tca6507.c
@@ -682,7 +682,7 @@ tca6507_led_dt_init(struct i2c_client *client)
682 return ERR_PTR(-ENODEV); 682 return ERR_PTR(-ENODEV);
683 683
684 tca_leds = devm_kzalloc(&client->dev, 684 tca_leds = devm_kzalloc(&client->dev,
685 sizeof(struct led_info) * count, GFP_KERNEL); 685 sizeof(struct led_info) * NUM_LEDS, GFP_KERNEL);
686 if (!tca_leds) 686 if (!tca_leds)
687 return ERR_PTR(-ENOMEM); 687 return ERR_PTR(-ENOMEM);
688 688
@@ -695,9 +695,9 @@ tca6507_led_dt_init(struct i2c_client *client)
695 of_get_property(child, "label", NULL) ? : child->name; 695 of_get_property(child, "label", NULL) ? : child->name;
696 led.default_trigger = 696 led.default_trigger =
697 of_get_property(child, "linux,default-trigger", NULL); 697 of_get_property(child, "linux,default-trigger", NULL);
698 698 led.flags = 0;
699 ret = of_property_read_u32(child, "reg", &reg); 699 ret = of_property_read_u32(child, "reg", &reg);
700 if (ret != 0) 700 if (ret != 0 || reg < 0 || reg >= NUM_LEDS)
701 continue; 701 continue;
702 702
703 tca_leds[reg] = led; 703 tca_leds[reg] = led;
@@ -708,7 +708,7 @@ tca6507_led_dt_init(struct i2c_client *client)
708 return ERR_PTR(-ENOMEM); 708 return ERR_PTR(-ENOMEM);
709 709
710 pdata->leds.leds = tca_leds; 710 pdata->leds.leds = tca_leds;
711 pdata->leds.num_leds = count; 711 pdata->leds.num_leds = NUM_LEDS;
712 712
713 return pdata; 713 return pdata;
714} 714}