regulator: max77686: Check pdata->num_regulators earlier
If this driver only works when pdata->num_regulators == MAX77686_REGULATORS, let's check it earlier. Also remove unused num_regulators from struct max77686_data. Signed-off-by: Axel Lin <axel.lin@gmail.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
parent
d01c3a1e1b
commit
ab0d1cbe55
1 changed files with 18 additions and 23 deletions
|
@ -65,7 +65,6 @@ enum max77686_ramp_rate {
|
||||||
struct max77686_data {
|
struct max77686_data {
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
struct max77686_dev *iodev;
|
struct max77686_dev *iodev;
|
||||||
int num_regulators;
|
|
||||||
struct regulator_dev **rdev;
|
struct regulator_dev **rdev;
|
||||||
int ramp_delay; /* in mV/us */
|
int ramp_delay; /* in mV/us */
|
||||||
};
|
};
|
||||||
|
@ -235,6 +234,12 @@ static __devinit int max77686_pmic_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
dev_dbg(&pdev->dev, "%s\n", __func__);
|
dev_dbg(&pdev->dev, "%s\n", __func__);
|
||||||
|
|
||||||
|
if (!pdata || pdata->num_regulators != MAX77686_REGULATORS) {
|
||||||
|
dev_err(&pdev->dev,
|
||||||
|
"Invalid initial data for regulator's initialiation\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
|
max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!max77686)
|
if (!max77686)
|
||||||
|
@ -248,8 +253,6 @@ static __devinit int max77686_pmic_probe(struct platform_device *pdev)
|
||||||
rdev = max77686->rdev;
|
rdev = max77686->rdev;
|
||||||
max77686->dev = &pdev->dev;
|
max77686->dev = &pdev->dev;
|
||||||
max77686->iodev = iodev;
|
max77686->iodev = iodev;
|
||||||
if (pdata)
|
|
||||||
max77686->num_regulators = pdata->num_regulators;
|
|
||||||
platform_set_drvdata(pdev, max77686);
|
platform_set_drvdata(pdev, max77686);
|
||||||
|
|
||||||
max77686->ramp_delay = RAMP_RATE_NO_CTRL; /* Set 0x3 for RAMP */
|
max77686->ramp_delay = RAMP_RATE_NO_CTRL; /* Set 0x3 for RAMP */
|
||||||
|
@ -263,34 +266,26 @@ static __devinit int max77686_pmic_probe(struct platform_device *pdev)
|
||||||
MAX77686_REG_BUCK4CTRL1, MAX77686_RAMP_RATE_MASK,
|
MAX77686_REG_BUCK4CTRL1, MAX77686_RAMP_RATE_MASK,
|
||||||
max77686->ramp_delay << 6);
|
max77686->ramp_delay << 6);
|
||||||
|
|
||||||
if (pdata->num_regulators == MAX77686_REGULATORS) {
|
for (i = 0; i < MAX77686_REGULATORS; i++) {
|
||||||
for (i = 0; i < MAX77686_REGULATORS; i++) {
|
config.dev = max77686->dev;
|
||||||
config.dev = max77686->dev;
|
config.regmap = iodev->regmap;
|
||||||
config.regmap = iodev->regmap;
|
config.driver_data = max77686;
|
||||||
config.driver_data = max77686;
|
config.init_data = pdata->regulators[i].initdata;
|
||||||
config.init_data = pdata->regulators[i].initdata;
|
|
||||||
|
|
||||||
rdev[i] = regulator_register(®ulators[i], &config);
|
rdev[i] = regulator_register(®ulators[i], &config);
|
||||||
|
if (IS_ERR(rdev[i])) {
|
||||||
if (IS_ERR(rdev[i])) {
|
ret = PTR_ERR(rdev[i]);
|
||||||
ret = PTR_ERR(rdev[i]);
|
dev_err(max77686->dev,
|
||||||
dev_err(max77686->dev,
|
|
||||||
"regulator init failed for %d\n", i);
|
"regulator init failed for %d\n", i);
|
||||||
rdev[i] = NULL;
|
rdev[i] = NULL;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
dev_err(max77686->dev,
|
|
||||||
"Lack of initial data for regulator's initialiation\n");
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
err:
|
err:
|
||||||
for (i = 0; i < MAX77686_REGULATORS; i++) {
|
while (--i >= 0)
|
||||||
if (rdev[i])
|
regulator_unregister(rdev[i]);
|
||||||
regulator_unregister(rdev[i]);
|
|
||||||
}
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue