2019-10-04 08:09:30

by Yizhuo Zhai

[permalink] [raw]
Subject: Potential uninitialized variables in power: supply: rt5033_battery:

Hi:

drivers/power/supply/rt5033_battery.c:

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.

Also, we cannot simply return -EINVAL in rt5033_battery_get_present()
because it's not an acceptable return value.

Thanks for your time to check this case.

--
Kind Regards,

Yizhuo Zhai

Computer Science, Graduate Student
University of California, Riverside


2019-10-14 03:16:46

by Sebastian Reichel

[permalink] [raw]
Subject: Re: Potential uninitialized variables in power: supply: rt5033_battery:

Hi,

On Thu, Oct 03, 2019 at 09:21:44PM -0700, Yizhuo Zhai wrote:
> drivers/power/supply/rt5033_battery.c:
>
> 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.
>
> Also, we cannot simply return -EINVAL in rt5033_battery_get_present()
> because it's not an acceptable return value.
>
> Thanks for your time to check this case.

Should be fine to just return false when regmap_read() fails.
Will you prepare a patch for that?

Thanks,

-- Sebastian


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

2019-10-14 03:57:26

by Yizhuo Zhai

[permalink] [raw]
Subject: Re: Potential uninitialized variables in power: supply: rt5033_battery:

Hi Sebastian:

Thanks for your explanation and I will send the patch accordingly.

On Sun, Oct 13, 2019 at 8:12 PM Sebastian Reichel <[email protected]> wrote:
>
> Hi,
>
> On Thu, Oct 03, 2019 at 09:21:44PM -0700, Yizhuo Zhai wrote:
> > drivers/power/supply/rt5033_battery.c:
> >
> > 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.
> >
> > Also, we cannot simply return -EINVAL in rt5033_battery_get_present()
> > because it's not an acceptable return value.
> >
> > Thanks for your time to check this case.
>
> Should be fine to just return false when regmap_read() fails.
> Will you prepare a patch for that?
>
> Thanks,
>
> -- Sebastian



--
Kind Regards,

Yizhuo Zhai

Computer Science, Graduate Student
University of California, Riverside