mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
leds: lm3697: Fix out-of-bound access
If both LED banks aren't used in device tree, an out-of-bounds condition in lm3697_init occurs because of the for loop assuming that all the banks are used. Fix it by adding a variable that contains the number of used banks. Signed-off-by: Gabriel David <ultracoolguy@tutanota.com> [removed extra rename, minor tweaks] Signed-off-by: Pavel Machek <pavel@ucw.cz> Cc: stable@kernel.org
This commit is contained in:
committed by
Pavel Machek
parent
8fd8f94235
commit
98d278ca00
@@ -78,6 +78,7 @@ struct lm3697 {
|
|||||||
struct mutex lock;
|
struct mutex lock;
|
||||||
|
|
||||||
int bank_cfg;
|
int bank_cfg;
|
||||||
|
int num_banks;
|
||||||
|
|
||||||
struct lm3697_led leds[];
|
struct lm3697_led leds[];
|
||||||
};
|
};
|
||||||
@@ -180,7 +181,7 @@ static int lm3697_init(struct lm3697 *priv)
|
|||||||
if (ret)
|
if (ret)
|
||||||
dev_err(dev, "Cannot write OUTPUT config\n");
|
dev_err(dev, "Cannot write OUTPUT config\n");
|
||||||
|
|
||||||
for (i = 0; i < LM3697_MAX_CONTROL_BANKS; i++) {
|
for (i = 0; i < priv->num_banks; i++) {
|
||||||
led = &priv->leds[i];
|
led = &priv->leds[i];
|
||||||
ret = ti_lmu_common_set_ramp(&led->lmu_data);
|
ret = ti_lmu_common_set_ramp(&led->lmu_data);
|
||||||
if (ret)
|
if (ret)
|
||||||
@@ -301,8 +302,8 @@ static int lm3697_probe(struct i2c_client *client,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
count = device_get_child_node_count(dev);
|
count = device_get_child_node_count(dev);
|
||||||
if (!count) {
|
if (!count || count > LM3697_MAX_CONTROL_BANKS) {
|
||||||
dev_err(dev, "LEDs are not defined in device tree!");
|
dev_err(dev, "Strange device tree!");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,6 +316,7 @@ static int lm3697_probe(struct i2c_client *client,
|
|||||||
|
|
||||||
led->client = client;
|
led->client = client;
|
||||||
led->dev = dev;
|
led->dev = dev;
|
||||||
|
led->num_banks = count;
|
||||||
led->regmap = devm_regmap_init_i2c(client, &lm3697_regmap_config);
|
led->regmap = devm_regmap_init_i2c(client, &lm3697_regmap_config);
|
||||||
if (IS_ERR(led->regmap)) {
|
if (IS_ERR(led->regmap)) {
|
||||||
ret = PTR_ERR(led->regmap);
|
ret = PTR_ERR(led->regmap);
|
||||||
|
Reference in New Issue
Block a user