Commit 3f7b679d authored by Arnd Bergmann's avatar Arnd Bergmann Committed by Ben Hutchings

regulator: s5m8767: fix get_register() error handling

commit e07ff943 upstream.

The s5m8767_pmic_probe() function calls s5m8767_get_register() to
read data without checking the return code, which produces a compile-time
warning when that data is accessed:

drivers/regulator/s5m8767.c: In function 's5m8767_pmic_probe':
drivers/regulator/s5m8767.c:924:7: error: 'enable_reg' may be used uninitialized in this function [-Werror=maybe-uninitialized]
drivers/regulator/s5m8767.c:944:30: error: 'enable_val' may be used uninitialized in this function [-Werror=maybe-uninitialized]

This changes the s5m8767_get_register() function to return a -EINVAL
not just for an invalid register number but also for an invalid
regulator number, as both would result in returning uninitialized
data. The s5m8767_pmic_probe() function is then changed accordingly
to fail on a read error, as all the other callers of s5m8767_get_register()
already do.

In practice this probably cannot happen, as we don't call
s5m8767_get_register() with invalid arguments, but the gcc
warning seems valid in principle, in terms writing safe
error checking.
Signed-off-by: default avatarArnd Bergmann <arnd@arndb.de>
Fixes: 9c4c6055 ("regulator: s5m8767: Convert to use regulator_[enable|disable|is_enabled]_regmap")
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 778c3762
...@@ -202,9 +202,10 @@ static int s5m8767_get_register(struct s5m8767_info *s5m8767, int reg_id, ...@@ -202,9 +202,10 @@ static int s5m8767_get_register(struct s5m8767_info *s5m8767, int reg_id,
} }
} }
if (i < s5m8767->num_regulators) if (i >= s5m8767->num_regulators)
*enable_ctrl = return -EINVAL;
s5m8767_opmode_reg[reg_id][mode] << S5M8767_ENCTRL_SHIFT;
*enable_ctrl = s5m8767_opmode_reg[reg_id][mode] << S5M8767_ENCTRL_SHIFT;
return 0; return 0;
} }
...@@ -938,8 +939,12 @@ static int s5m8767_pmic_probe(struct platform_device *pdev) ...@@ -938,8 +939,12 @@ static int s5m8767_pmic_probe(struct platform_device *pdev)
else else
regulators[id].vsel_mask = 0xff; regulators[id].vsel_mask = 0xff;
s5m8767_get_register(s5m8767, id, &enable_reg, ret = s5m8767_get_register(s5m8767, id, &enable_reg,
&enable_val); &enable_val);
if (ret) {
dev_err(s5m8767->dev, "error reading registers\n");
return ret;
}
regulators[id].enable_reg = enable_reg; regulators[id].enable_reg = enable_reg;
regulators[id].enable_mask = S5M8767_ENCTRL_MASK; regulators[id].enable_mask = S5M8767_ENCTRL_MASK;
regulators[id].enable_val = enable_val; regulators[id].enable_val = enable_val;
......
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