[PATCH] power: supply: rt5033_battery: Fix the usage of potential uninitialized variable
From: Yizhuo
Date: Tue Oct 15 2019 - 12:57:29 EST
In function rt5033_battery_get_present(), variable "val" could be
uninitialized if regmap_read() returns -EINVAL. However, "val" is
used to decide the return value, which is potentially unsafe.
Signed-off-by: Yizhuo <yzhai003@xxxxxxx>
---
drivers/power/supply/rt5033_battery.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/rt5033_battery.c b/drivers/power/supply/rt5033_battery.c
index d8667a9fc49b..6a617531698c 100644
--- a/drivers/power/supply/rt5033_battery.c
+++ b/drivers/power/supply/rt5033_battery.c
@@ -26,8 +26,14 @@ static int rt5033_battery_get_present(struct i2c_client *client)
{
struct rt5033_battery *battery = i2c_get_clientdata(client);
u32 val;
+ int ret;
- regmap_read(battery->regmap, RT5033_FUEL_REG_CONFIG_L, &val);
+ ret = regmap_read(battery->regmap, RT5033_FUEL_REG_CONFIG_L, &val);
+ if (ret) {
+ dev_err(&client->dev,
+ "Failed to read RT5033_FUEL_REG_CONFIG_L.\n");
+ return false;
+ }
return (val & RT5033_FUEL_BAT_PRESENT) ? true : false;
}
--
2.17.1