From 33e374b8e696c6d465a8243838f5ff0aca54ec4b Mon Sep 17 00:00:00 2001 From: Rabin Vincent Date: Fri, 6 May 2011 16:13:46 +0530 Subject: regulator/ab5500: correctly handle holes in voltage list The handling of get_voltage() for regulators where there are holes in the voltage list is buggy. Fix it. ST-Ericsson Linux next: - ST-Ericsson ID: WP257121 ST-Ericsson FOSS-OUT ID: Trivial Change-Id: I1b0db7943ccc057a0ea13208b934e54f1fc392cd Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/22506 Tested-by: Rabin VINCENT Reviewed-by: QATEST Reviewed-by: Srinidhi KASAGAR --- drivers/regulator/ab5500.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/regulator/ab5500.c b/drivers/regulator/ab5500.c index af182f0c980..e8128e4caf8 100644 --- a/drivers/regulator/ab5500.c +++ b/drivers/regulator/ab5500.c @@ -58,6 +58,7 @@ struct ab5500_regulator { struct regulator_desc desc; const int *voltages; + int num_holes; bool pwrctrl; int enable_time; u8 bank; @@ -167,7 +168,10 @@ static int ab5500_regulator_get_voltage(struct regulator_dev *rdev) } regval &= AB5500_LDO_VOLT_MASK; - if (regval >= r->desc.n_voltages || !r->voltages[regval]) + if (regval >= r->desc.n_voltages + r->num_holes) + return -EINVAL; + + if (!r->voltages[regval]) return -EINVAL; return r->voltages[regval]; @@ -339,6 +343,7 @@ static struct ab5500_regulator ab5500_regulators[] = { .bank = AB5500_BANK_STARTUP, .reg = AB5500_LDO_L_ST, .voltages = ab5500_ldo_lg_voltages, + .num_holes = 2, /* 2 register values unused */ .enable_time = 400, }, [AB5500_LDO_G] = { @@ -353,6 +358,7 @@ static struct ab5500_regulator ab5500_regulators[] = { .bank = AB5500_BANK_STARTUP, .reg = AB5500_LDO_G_ST, .voltages = ab5500_ldo_lg_voltages, + .num_holes = 2, /* 2 register values unused */ .enable_time = 400, }, [AB5500_LDO_K] = { -- cgit v1.2.3