Skip to content

Commit ab0d1cb

Browse files
AxelLinbroonie
authored andcommitted
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>
1 parent d01c3a1 commit ab0d1cb

1 file changed

Lines changed: 19 additions & 24 deletions

File tree

‎drivers/regulator/max77686.c‎

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ enum max77686_ramp_rate {
6565
struct max77686_data {
6666
struct device *dev;
6767
struct max77686_dev *iodev;
68-
int num_regulators;
6968
struct regulator_dev **rdev;
7069
int ramp_delay; /* in mV/us */
7170
};
@@ -235,6 +234,12 @@ static __devinit int max77686_pmic_probe(struct platform_device *pdev)
235234

236235
dev_dbg(&pdev->dev, "%s\n", __func__);
237236

237+
if (!pdata || pdata->num_regulators != MAX77686_REGULATORS) {
238+
dev_err(&pdev->dev,
239+
"Invalid initial data for regulator's initialiation\n");
240+
return -EINVAL;
241+
}
242+
238243
max77686 = devm_kzalloc(&pdev->dev, sizeof(struct max77686_data),
239244
GFP_KERNEL);
240245
if (!max77686)
@@ -248,8 +253,6 @@ static __devinit int max77686_pmic_probe(struct platform_device *pdev)
248253
rdev = max77686->rdev;
249254
max77686->dev = &pdev->dev;
250255
max77686->iodev = iodev;
251-
if (pdata)
252-
max77686->num_regulators = pdata->num_regulators;
253256
platform_set_drvdata(pdev, max77686);
254257

255258
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)
263266
MAX77686_REG_BUCK4CTRL1, MAX77686_RAMP_RATE_MASK,
264267
max77686->ramp_delay << 6);
265268

266-
if (pdata->num_regulators == MAX77686_REGULATORS) {
267-
for (i = 0; i < MAX77686_REGULATORS; i++) {
268-
config.dev = max77686->dev;
269-
config.regmap = iodev->regmap;
270-
config.driver_data = max77686;
271-
config.init_data = pdata->regulators[i].initdata;
272-
273-
rdev[i] = regulator_register(&regulators[i], &config);
274-
275-
if (IS_ERR(rdev[i])) {
276-
ret = PTR_ERR(rdev[i]);
277-
dev_err(max77686->dev,
269+
for (i = 0; i < MAX77686_REGULATORS; i++) {
270+
config.dev = max77686->dev;
271+
config.regmap = iodev->regmap;
272+
config.driver_data = max77686;
273+
config.init_data = pdata->regulators[i].initdata;
274+
275+
rdev[i] = regulator_register(&regulators[i], &config);
276+
if (IS_ERR(rdev[i])) {
277+
ret = PTR_ERR(rdev[i]);
278+
dev_err(max77686->dev,
278279
"regulator init failed for %d\n", i);
279280
rdev[i] = NULL;
280281
goto err;
281-
}
282282
}
283-
} else {
284-
dev_err(max77686->dev,
285-
"Lack of initial data for regulator's initialiation\n");
286-
return -EINVAL;
287283
}
284+
288285
return 0;
289286
err:
290-
for (i = 0; i < MAX77686_REGULATORS; i++) {
291-
if (rdev[i])
292-
regulator_unregister(rdev[i]);
293-
}
287+
while (--i >= 0)
288+
regulator_unregister(rdev[i]);
294289
return ret;
295290
}
296291

0 commit comments

Comments
 (0)