2019-10-15 20:44:35

by Yizhuo Zhai

[permalink] [raw]
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 <[email protected]>
---
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


2019-10-19 10:25:46

by Sebastian Reichel

[permalink] [raw]
Subject: Re: [PATCH] power: supply: rt5033_battery: Fix the usage of potential uninitialized variable

Hi,

On Tue, Oct 15, 2019 at 09:57:37AM -0700, Yizhuo wrote:
> 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 <[email protected]>
> ---

The patch looks good, but your name in author and Signed-off-by line
look incomplete (only one name). Please resend with full name as
patch author and Signed-off-by.

Thanks,

-- Sebastian

> 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
>


Attachments:
(No filename) (1.38 kB)
signature.asc (849.00 B)
Download all attachments