In function pfuze100_regulator_probe(), variable "val" could be
initialized if regmap_read() fails. However, "val" is used to
decide the control flow later in the if statement, which is
potentially unsafe.
Signed-off-by: Yizhuo <[email protected]>
---
drivers/regulator/pfuze100-regulator.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c
index df5df1c495ad..649e2bfcdffd 100644
--- a/drivers/regulator/pfuze100-regulator.c
+++ b/drivers/regulator/pfuze100-regulator.c
@@ -777,7 +777,7 @@ static int pfuze100_regulator_probe(struct i2c_client *client,
for (i = 0; i < regulator_num; i++) {
struct regulator_init_data *init_data;
struct regulator_desc *desc;
- int val;
+ int val = 0;
desc = &pfuze_chip->regulator_descs[i].desc;
--
2.17.1
On Mon, Sep 02, 2019 at 03:10:47PM -0700, Yizhuo wrote:
> In function pfuze100_regulator_probe(), variable "val" could be
> initialized if regmap_read() fails. However, "val" is used to
> decide the control flow later in the if statement, which is
> potentially unsafe.
> struct regulator_desc *desc;
> - int val;
> + int val = 0;
This just unconditionally assings a value to this variable which will
stop any warnings but there's no analysis explaining why this is a good
fix - are we actually forgetting to check something we should be
checking, are we sure that this is the correct value to use?
Thanks Mark, I will send a new patch and check the return value instead.
On Tue, Sep 3, 2019 at 4:26 AM Mark Brown <[email protected]> wrote:
>
> On Mon, Sep 02, 2019 at 03:10:47PM -0700, Yizhuo wrote:
> > In function pfuze100_regulator_probe(), variable "val" could be
> > initialized if regmap_read() fails. However, "val" is used to
> > decide the control flow later in the if statement, which is
> > potentially unsafe.
>
> > struct regulator_desc *desc;
> > - int val;
> > + int val = 0;
>
> This just unconditionally assings a value to this variable which will
> stop any warnings but there's no analysis explaining why this is a good
> fix - are we actually forgetting to check something we should be
> checking, are we sure that this is the correct value to use?
--
Kind Regards,
Yizhuo Zhai
Computer Science, Graduate Student
University of California, Riverside