aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/regulator
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/regulator')
-rw-r--r--drivers/regulator/lp3971.c58
1 files changed, 29 insertions, 29 deletions
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c
index 3ea639f29e95..f5532ed79272 100644
--- a/drivers/regulator/lp3971.c
+++ b/drivers/regulator/lp3971.c
@@ -431,20 +431,20 @@ static int lp3971_set_bits(struct lp3971 *lp3971, u8 reg, u16 mask, u16 val)
431 return ret; 431 return ret;
432} 432}
433 433
434static int setup_regulators(struct lp3971 *lp3971, 434static int __devinit setup_regulators(struct lp3971 *lp3971,
435 struct lp3971_platform_data *pdata) 435 struct lp3971_platform_data *pdata)
436{ 436{
437 int i, err; 437 int i, err;
438 int num_regulators = pdata->num_regulators; 438
439 lp3971->num_regulators = num_regulators; 439 lp3971->num_regulators = pdata->num_regulators;
440 lp3971->rdev = kzalloc(sizeof(struct regulator_dev *) * num_regulators, 440 lp3971->rdev = kcalloc(pdata->num_regulators,
441 GFP_KERNEL); 441 sizeof(struct regulator_dev *), GFP_KERNEL);
442 442
443 /* Instantiate the regulators */ 443 /* Instantiate the regulators */
444 for (i = 0; i < num_regulators; i++) { 444 for (i = 0; i < pdata->num_regulators; i++) {
445 int id = pdata->regulators[i].id; 445 struct lp3971_regulator_subdev *reg = &pdata->regulators[i];
446 lp3971->rdev[i] = regulator_register(&regulators[id], 446 lp3971->rdev[i] = regulator_register(&regulators[reg->id],
447 lp3971->dev, pdata->regulators[i].initdata, lp3971); 447 lp3971->dev, reg->initdata, lp3971);
448 448
449 if (IS_ERR(lp3971->rdev[i])) { 449 if (IS_ERR(lp3971->rdev[i])) {
450 err = PTR_ERR(lp3971->rdev[i]); 450 err = PTR_ERR(lp3971->rdev[i]);
@@ -455,10 +455,10 @@ static int setup_regulators(struct lp3971 *lp3971,
455 } 455 }
456 456
457 return 0; 457 return 0;
458
458error: 459error:
459 for (i = 0; i < num_regulators; i++) 460 while (--i >= 0)
460 if (lp3971->rdev[i]) 461 regulator_unregister(lp3971->rdev[i]);
461 regulator_unregister(lp3971->rdev[i]);
462 kfree(lp3971->rdev); 462 kfree(lp3971->rdev);
463 lp3971->rdev = NULL; 463 lp3971->rdev = NULL;
464 return err; 464 return err;
@@ -472,15 +472,17 @@ static int __devinit lp3971_i2c_probe(struct i2c_client *i2c,
472 int ret; 472 int ret;
473 u16 val; 473 u16 val;
474 474
475 lp3971 = kzalloc(sizeof(struct lp3971), GFP_KERNEL); 475 if (!pdata) {
476 if (lp3971 == NULL) { 476 dev_dbg(&i2c->dev, "No platform init data supplied\n");
477 ret = -ENOMEM; 477 return -ENODEV;
478 goto err;
479 } 478 }
480 479
480 lp3971 = kzalloc(sizeof(struct lp3971), GFP_KERNEL);
481 if (lp3971 == NULL)
482 return -ENOMEM;
483
481 lp3971->i2c = i2c; 484 lp3971->i2c = i2c;
482 lp3971->dev = &i2c->dev; 485 lp3971->dev = &i2c->dev;
483 i2c_set_clientdata(i2c, lp3971);
484 486
485 mutex_init(&lp3971->io_lock); 487 mutex_init(&lp3971->io_lock);
486 488
@@ -493,19 +495,15 @@ static int __devinit lp3971_i2c_probe(struct i2c_client *i2c,
493 goto err_detect; 495 goto err_detect;
494 } 496 }
495 497
496 if (pdata) { 498 ret = setup_regulators(lp3971, pdata);
497 ret = setup_regulators(lp3971, pdata); 499 if (ret < 0)
498 if (ret < 0) 500 goto err_detect;
499 goto err_detect;
500 } else
501 dev_warn(lp3971->dev, "No platform init data supplied\n");
502 501
502 i2c_set_clientdata(i2c, lp3971);
503 return 0; 503 return 0;
504 504
505err_detect: 505err_detect:
506 i2c_set_clientdata(i2c, NULL);
507 kfree(lp3971); 506 kfree(lp3971);
508err:
509 return ret; 507 return ret;
510} 508}
511 509
@@ -513,11 +511,13 @@ static int __devexit lp3971_i2c_remove(struct i2c_client *i2c)
513{ 511{
514 struct lp3971 *lp3971 = i2c_get_clientdata(i2c); 512 struct lp3971 *lp3971 = i2c_get_clientdata(i2c);
515 int i; 513 int i;
514
515 i2c_set_clientdata(i2c, NULL);
516
516 for (i = 0; i < lp3971->num_regulators; i++) 517 for (i = 0; i < lp3971->num_regulators; i++)
517 if (lp3971->rdev[i]) 518 regulator_unregister(lp3971->rdev[i]);
518 regulator_unregister(lp3971->rdev[i]); 519
519 kfree(lp3971->rdev); 520 kfree(lp3971->rdev);
520 i2c_set_clientdata(i2c, NULL);
521 kfree(lp3971); 521 kfree(lp3971);
522 522
523 return 0; 523 return 0;