* [PATCH] power: supply: rt5033_battery: Fix the usage of potential uninitialized variable
@ 2019-10-15 16:57 Yizhuo
2019-10-19 10:25 ` Sebastian Reichel
0 siblings, 1 reply; 2+ messages in thread
From: Yizhuo @ 2019-10-15 16:57 UTC (permalink / raw)
Cc: zhiyunq, csong, Yizhuo, Sebastian Reichel, linux-pm, linux-kernel
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@ucr.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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] power: supply: rt5033_battery: Fix the usage of potential uninitialized variable
2019-10-15 16:57 [PATCH] power: supply: rt5033_battery: Fix the usage of potential uninitialized variable Yizhuo
@ 2019-10-19 10:25 ` Sebastian Reichel
0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2019-10-19 10:25 UTC (permalink / raw)
To: Yizhuo; +Cc: zhiyunq, csong, linux-pm, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1412 bytes --]
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 <yzhai003@ucr.edu>
> ---
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
>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-10-19 10:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-15 16:57 [PATCH] power: supply: rt5033_battery: Fix the usage of potential uninitialized variable Yizhuo
2019-10-19 10:25 ` Sebastian Reichel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).