diff options
author | Beniamino Galvani <b.galvani@gmail.com> | 2014-06-22 11:31:41 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-08-05 13:02:51 -0400 |
commit | 48a1e1b50d9e848fea9708795bd5d9aa97aa9c2a (patch) | |
tree | 1e7f865b19606feb362990b27414506bca58ca14 /drivers/regulator | |
parent | 7171511eaec5bf23fb06078f59784a3a0626b38f (diff) |
regulator: act8865: fix parsing of platform data
The driver loops through all available regulators (ACT8865_REG_NUM)
and accesses pdata->regulators[i].platform_data without checking the
actual value of num_regulators in platform data, potentially causing a
invalid memory access.
Fix this and look up the regulator init_data by id in platform data.
Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
Tested-by Wenyou.Yang <wenyou.yang@atmel.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/act8865-regulator.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/drivers/regulator/act8865-regulator.c b/drivers/regulator/act8865-regulator.c index b92d7dd01a18..fe2c038f8cbc 100644 --- a/drivers/regulator/act8865-regulator.c +++ b/drivers/regulator/act8865-regulator.c | |||
@@ -252,6 +252,22 @@ static inline int act8865_pdata_from_dt(struct device *dev, | |||
252 | } | 252 | } |
253 | #endif | 253 | #endif |
254 | 254 | ||
255 | static struct regulator_init_data | ||
256 | *act8865_get_init_data(int id, struct act8865_platform_data *pdata) | ||
257 | { | ||
258 | int i; | ||
259 | |||
260 | if (!pdata) | ||
261 | return NULL; | ||
262 | |||
263 | for (i = 0; i < pdata->num_regulators; i++) { | ||
264 | if (pdata->regulators[i].id == id) | ||
265 | return pdata->regulators[i].platform_data; | ||
266 | } | ||
267 | |||
268 | return NULL; | ||
269 | } | ||
270 | |||
255 | static int act8865_pmic_probe(struct i2c_client *client, | 271 | static int act8865_pmic_probe(struct i2c_client *client, |
256 | const struct i2c_device_id *i2c_id) | 272 | const struct i2c_device_id *i2c_id) |
257 | { | 273 | { |
@@ -261,7 +277,7 @@ static int act8865_pmic_probe(struct i2c_client *client, | |||
261 | struct regulator_config config = { }; | 277 | struct regulator_config config = { }; |
262 | struct act8865 *act8865; | 278 | struct act8865 *act8865; |
263 | struct device_node *of_node[ACT8865_REG_NUM]; | 279 | struct device_node *of_node[ACT8865_REG_NUM]; |
264 | int i, id; | 280 | int i; |
265 | int ret = -EINVAL; | 281 | int ret = -EINVAL; |
266 | int error; | 282 | int error; |
267 | 283 | ||
@@ -299,20 +315,17 @@ static int act8865_pmic_probe(struct i2c_client *client, | |||
299 | 315 | ||
300 | /* Finally register devices */ | 316 | /* Finally register devices */ |
301 | for (i = 0; i < ACT8865_REG_NUM; i++) { | 317 | for (i = 0; i < ACT8865_REG_NUM; i++) { |
302 | 318 | const struct regulator_desc *desc = &act8865_reg[i]; | |
303 | id = pdata->regulators[i].id; | ||
304 | 319 | ||
305 | config.dev = dev; | 320 | config.dev = dev; |
306 | config.init_data = pdata->regulators[i].platform_data; | 321 | config.init_data = act8865_get_init_data(desc->id, pdata); |
307 | config.of_node = of_node[i]; | 322 | config.of_node = of_node[i]; |
308 | config.driver_data = act8865; | 323 | config.driver_data = act8865; |
309 | config.regmap = act8865->regmap; | 324 | config.regmap = act8865->regmap; |
310 | 325 | ||
311 | rdev = devm_regulator_register(&client->dev, &act8865_reg[i], | 326 | rdev = devm_regulator_register(&client->dev, desc, &config); |
312 | &config); | ||
313 | if (IS_ERR(rdev)) { | 327 | if (IS_ERR(rdev)) { |
314 | dev_err(dev, "failed to register %s\n", | 328 | dev_err(dev, "failed to register %s\n", desc->name); |
315 | act8865_reg[id].name); | ||
316 | return PTR_ERR(rdev); | 329 | return PTR_ERR(rdev); |
317 | } | 330 | } |
318 | } | 331 | } |