[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191015165737.658-1-yzhai003@ucr.edu>
Date: Tue, 15 Oct 2019 09:57:37 -0700
From: Yizhuo <yzhai003@....edu>
To: unlisted-recipients:; (no To-header on input)
Cc: zhiyunq@...ucr.edu, csong@...ucr.edu, Yizhuo <yzhai003@....edu>,
Sebastian Reichel <sre@...nel.org>, linux-pm@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH] power: supply: rt5033_battery: Fix the usage of potential uninitialized variable
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@....edu>
---
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
Powered by blists - more mailing lists