Commit fc24b426 authored by Bengt Jonsson's avatar Bengt Jonsson Committed by Liam Girdwood

regulators: Modified ab8500 error handling

Error handling is updated to catch NULL pointer errors.
Signed-off-by: default avatarBengt Jonsson <bengt.g.jonsson@stericsson.com>
Acked-by: default avatarLinus Walleij <linus.walleij@stericsson.com>
Acked-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: default avatarLiam Girdwood <lrg@slimlogic.co.uk>
parent e1159e6d
...@@ -100,12 +100,13 @@ static const int ldo_vintcore_voltages[] = { ...@@ -100,12 +100,13 @@ static const int ldo_vintcore_voltages[] = {
static int ab8500_regulator_enable(struct regulator_dev *rdev) static int ab8500_regulator_enable(struct regulator_dev *rdev)
{ {
int regulator_id, ret; int ret;
struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
regulator_id = rdev_get_id(rdev); if (info == NULL) {
if (regulator_id >= AB8500_NUM_REGULATORS) dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
return -EINVAL; return -EINVAL;
}
ret = abx500_mask_and_set_register_interruptible(info->dev, ret = abx500_mask_and_set_register_interruptible(info->dev,
info->update_bank, info->update_reg, info->update_bank, info->update_reg,
...@@ -118,12 +119,13 @@ static int ab8500_regulator_enable(struct regulator_dev *rdev) ...@@ -118,12 +119,13 @@ static int ab8500_regulator_enable(struct regulator_dev *rdev)
static int ab8500_regulator_disable(struct regulator_dev *rdev) static int ab8500_regulator_disable(struct regulator_dev *rdev)
{ {
int regulator_id, ret; int ret;
struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
regulator_id = rdev_get_id(rdev); if (info == NULL) {
if (regulator_id >= AB8500_NUM_REGULATORS) dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
return -EINVAL; return -EINVAL;
}
ret = abx500_mask_and_set_register_interruptible(info->dev, ret = abx500_mask_and_set_register_interruptible(info->dev,
info->update_bank, info->update_reg, info->update_bank, info->update_reg,
...@@ -136,13 +138,14 @@ static int ab8500_regulator_disable(struct regulator_dev *rdev) ...@@ -136,13 +138,14 @@ static int ab8500_regulator_disable(struct regulator_dev *rdev)
static int ab8500_regulator_is_enabled(struct regulator_dev *rdev) static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
{ {
int regulator_id, ret; int ret;
struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
u8 value; u8 value;
regulator_id = rdev_get_id(rdev); if (info == NULL) {
if (regulator_id >= AB8500_NUM_REGULATORS) dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
return -EINVAL; return -EINVAL;
}
ret = abx500_get_register_interruptible(info->dev, ret = abx500_get_register_interruptible(info->dev,
info->update_bank, info->update_reg, &value); info->update_bank, info->update_reg, &value);
...@@ -160,12 +163,12 @@ static int ab8500_regulator_is_enabled(struct regulator_dev *rdev) ...@@ -160,12 +163,12 @@ static int ab8500_regulator_is_enabled(struct regulator_dev *rdev)
static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector) static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
{ {
int regulator_id;
struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
regulator_id = rdev_get_id(rdev); if (info == NULL) {
if (regulator_id >= AB8500_NUM_REGULATORS) dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
return -EINVAL; return -EINVAL;
}
/* return the uV for the fixed regulators */ /* return the uV for the fixed regulators */
if (info->fixed_uV) if (info->fixed_uV)
...@@ -179,13 +182,14 @@ static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector) ...@@ -179,13 +182,14 @@ static int ab8500_list_voltage(struct regulator_dev *rdev, unsigned selector)
static int ab8500_regulator_get_voltage(struct regulator_dev *rdev) static int ab8500_regulator_get_voltage(struct regulator_dev *rdev)
{ {
int regulator_id, ret; int ret;
struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
u8 value; u8 value;
regulator_id = rdev_get_id(rdev); if (info == NULL) {
if (regulator_id >= AB8500_NUM_REGULATORS) dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
return -EINVAL; return -EINVAL;
}
ret = abx500_get_register_interruptible(info->dev, info->voltage_bank, ret = abx500_get_register_interruptible(info->dev, info->voltage_bank,
info->voltage_reg, &value); info->voltage_reg, &value);
...@@ -197,7 +201,7 @@ static int ab8500_regulator_get_voltage(struct regulator_dev *rdev) ...@@ -197,7 +201,7 @@ static int ab8500_regulator_get_voltage(struct regulator_dev *rdev)
/* vintcore has a different layout */ /* vintcore has a different layout */
value &= info->voltage_mask; value &= info->voltage_mask;
if (regulator_id == AB8500_LDO_INTCORE) if (info->desc.id == AB8500_LDO_INTCORE)
ret = info->voltages[value >> 0x3]; ret = info->voltages[value >> 0x3];
else else
ret = info->voltages[value]; ret = info->voltages[value];
...@@ -225,12 +229,13 @@ static int ab8500_regulator_set_voltage(struct regulator_dev *rdev, ...@@ -225,12 +229,13 @@ static int ab8500_regulator_set_voltage(struct regulator_dev *rdev,
int min_uV, int max_uV, int min_uV, int max_uV,
unsigned *selector) unsigned *selector)
{ {
int regulator_id, ret; int ret;
struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
regulator_id = rdev_get_id(rdev); if (info == NULL) {
if (regulator_id >= AB8500_NUM_REGULATORS) dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
return -EINVAL; return -EINVAL;
}
/* get the appropriate voltages within the range */ /* get the appropriate voltages within the range */
ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV); ret = ab8500_get_best_voltage_index(rdev, min_uV, max_uV);
...@@ -264,12 +269,12 @@ static struct regulator_ops ab8500_regulator_ops = { ...@@ -264,12 +269,12 @@ static struct regulator_ops ab8500_regulator_ops = {
static int ab8500_fixed_get_voltage(struct regulator_dev *rdev) static int ab8500_fixed_get_voltage(struct regulator_dev *rdev)
{ {
int regulator_id;
struct ab8500_regulator_info *info = rdev_get_drvdata(rdev); struct ab8500_regulator_info *info = rdev_get_drvdata(rdev);
regulator_id = rdev_get_id(rdev); if (info == NULL) {
if (regulator_id >= AB8500_NUM_REGULATORS) dev_err(rdev_get_dev(rdev), "regulator info null pointer\n");
return -EINVAL; return -EINVAL;
}
return info->fixed_uV; return info->fixed_uV;
} }
...@@ -368,6 +373,10 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev) ...@@ -368,6 +373,10 @@ static __devinit int ab8500_regulator_probe(struct platform_device *pdev)
return -EINVAL; return -EINVAL;
} }
pdata = dev_get_platdata(ab8500->dev); pdata = dev_get_platdata(ab8500->dev);
if (!pdata) {
dev_err(&pdev->dev, "null pdata\n");
return -EINVAL;
}
/* make sure the platform data has the correct size */ /* make sure the platform data has the correct size */
if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) { if (pdata->num_regulator != ARRAY_SIZE(ab8500_regulator_info)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment