]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
regulator: max8907: Fix the usage of uninitialized variable in max8907_regulator_probe()
authorYizhuo <yzhai003@ucr.edu>
Thu, 3 Oct 2019 17:58:13 +0000 (10:58 -0700)
committerKhalid Elmously <khalid.elmously@canonical.com>
Wed, 29 Jan 2020 04:58:30 +0000 (23:58 -0500)
BugLink: https://bugs.launchpad.net/bugs/1860490
[ Upstream commit 472b39c3d1bba0616eb0e9a8fa3ad0f56927c7d7 ]

Inside function max8907_regulator_probe(), variable val could
be uninitialized if regmap_read() fails. However, val is used
later in the if statement to decide the content written to
"pmic", which is potentially unsafe.

Signed-off-by: Yizhuo <yzhai003@ucr.edu>
Link: https://lore.kernel.org/r/20191003175813.16415-1-yzhai003@ucr.edu
Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Khalid Elmously <khalid.elmously@canonical.com>
drivers/regulator/max8907-regulator.c

index 76152aaa330bd143fb733b7fcdf3b400190f35a6..96dc0eea7659659e3b865b2b30a62bfdeb00fa04 100644 (file)
@@ -296,7 +296,10 @@ static int max8907_regulator_probe(struct platform_device *pdev)
        memcpy(pmic->desc, max8907_regulators, sizeof(pmic->desc));
 
        /* Backwards compatibility with MAX8907B; SD1 uses different voltages */
-       regmap_read(max8907->regmap_gen, MAX8907_REG_II2RR, &val);
+       ret = regmap_read(max8907->regmap_gen, MAX8907_REG_II2RR, &val);
+       if (ret)
+               return ret;
+
        if ((val & MAX8907_II2RR_VERSION_MASK) ==
            MAX8907_II2RR_VERSION_REV_B) {
                pmic->desc[MAX8907_SD1].min_uV = 637500;
@@ -333,14 +336,20 @@ static int max8907_regulator_probe(struct platform_device *pdev)
                }
 
                if (pmic->desc[i].ops == &max8907_ldo_ops) {
-                       regmap_read(config.regmap, pmic->desc[i].enable_reg,
+                       ret = regmap_read(config.regmap, pmic->desc[i].enable_reg,
                                    &val);
+                       if (ret)
+                               return ret;
+
                        if ((val & MAX8907_MASK_LDO_SEQ) !=
                            MAX8907_MASK_LDO_SEQ)
                                pmic->desc[i].ops = &max8907_ldo_hwctl_ops;
                } else if (pmic->desc[i].ops == &max8907_out5v_ops) {
-                       regmap_read(config.regmap, pmic->desc[i].enable_reg,
+                       ret = regmap_read(config.regmap, pmic->desc[i].enable_reg,
                                    &val);
+                       if (ret)
+                               return ret;
+
                        if ((val & (MAX8907_MASK_OUT5V_VINEN |
                                                MAX8907_MASK_OUT5V_ENSRC)) !=
                            MAX8907_MASK_OUT5V_ENSRC)