Commit cb44cdeacd693ca964deab9d9f698920bb73529d

Authored by Axel Lin
Committed by Mark Brown
1 parent 2c58e2669f

regulator: max77686: Use array to save pointer to rdev

MAX77686_REGULATORS is known in compile time.
Use array to save pointer to rdev makes the code simpler.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

Showing 1 changed file with 9 additions and 19 deletions Side-by-side Diff

drivers/regulator/max77686.c
... ... @@ -66,7 +66,7 @@
66 66 };
67 67  
68 68 struct max77686_data {
69   - struct regulator_dev **rdev;
  69 + struct regulator_dev *rdev[MAX77686_REGULATORS];
70 70 };
71 71  
72 72 static int max77686_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay)
73 73  
... ... @@ -284,10 +284,8 @@
284 284 {
285 285 struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent);
286 286 struct max77686_platform_data *pdata = dev_get_platdata(iodev->dev);
287   - struct regulator_dev **rdev;
288 287 struct max77686_data *max77686;
289   - int i, size;
290   - int ret = 0;
  288 + int i, ret = 0;
291 289 struct regulator_config config = { };
292 290  
293 291 dev_dbg(&pdev->dev, "%s\n", __func__);
... ... @@ -314,12 +312,6 @@
314 312 if (!max77686)
315 313 return -ENOMEM;
316 314  
317   - size = sizeof(struct regulator_dev *) * MAX77686_REGULATORS;
318   - max77686->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
319   - if (!max77686->rdev)
320   - return -ENOMEM;
321   -
322   - rdev = max77686->rdev;
323 315 config.dev = &pdev->dev;
324 316 config.regmap = iodev->regmap;
325 317 platform_set_drvdata(pdev, max77686);
326 318  
327 319  
328 320  
329 321  
... ... @@ -328,32 +320,30 @@
328 320 config.init_data = pdata->regulators[i].initdata;
329 321 config.of_node = pdata->regulators[i].of_node;
330 322  
331   - rdev[i] = regulator_register(&regulators[i], &config);
332   - if (IS_ERR(rdev[i])) {
333   - ret = PTR_ERR(rdev[i]);
  323 + max77686->rdev[i] = regulator_register(&regulators[i], &config);
  324 + if (IS_ERR(max77686->rdev[i])) {
  325 + ret = PTR_ERR(max77686->rdev[i]);
334 326 dev_err(&pdev->dev,
335 327 "regulator init failed for %d\n", i);
336   - rdev[i] = NULL;
337   - goto err;
  328 + max77686->rdev[i] = NULL;
  329 + goto err;
338 330 }
339 331 }
340 332  
341 333 return 0;
342 334 err:
343 335 while (--i >= 0)
344   - regulator_unregister(rdev[i]);
  336 + regulator_unregister(max77686->rdev[i]);
345 337 return ret;
346 338 }
347 339  
348 340 static int __devexit max77686_pmic_remove(struct platform_device *pdev)
349 341 {
350 342 struct max77686_data *max77686 = platform_get_drvdata(pdev);
351   - struct regulator_dev **rdev = max77686->rdev;
352 343 int i;
353 344  
354 345 for (i = 0; i < MAX77686_REGULATORS; i++)
355   - if (rdev[i])
356   - regulator_unregister(rdev[i]);
  346 + regulator_unregister(max77686->rdev[i]);
357 347  
358 348 return 0;
359 349 }