All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sebastian Reichel <sre@kernel.org>
To: Li Tuo <islituo@gmail.com>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	baijiaju1990@gmail.com, "Jett.Zhou" <jtzhou@marvell.com>
Subject: Re: [BUG] power: supply: 88pm860x_battery: possible uninitialized-variable access in measure_vbatt()
Date: Thu, 5 Aug 2021 19:49:08 +0200	[thread overview]
Message-ID: <20210805174908.ctg6n5iwmg5izap3@earth.universe> (raw)
In-Reply-To: <e2080eb9-bbe2-5077-761d-b5594edb6006@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1411 bytes --]

[adding Jett Zhou to Cc who introduced the driver]

Hi,

On Wed, Jul 28, 2021 at 06:24:12PM +0800, Li Tuo wrote:
> Our static analysis tool finds a possible uninitialized-variable access in
> the 88pm860x_battery driver in Linux 5.14.0-rc3:
> 
> In calc_soc():
> 369:    int ocv;
> 376:    switch (state) {
> 380:    case OCV_MODE_SLEEP:
> 381:        ret = measure_vbatt(info, OCV_MODE_SLEEP, &ocv);
> 
> In measure_vbatt(struct pm860x_battery_info *info, int state, int *data)
> 176:    switch (state) {
> 184:    case OCV_MODE_SLEEP:
> 201:        *data = ((*data & 0xff) * 27 * 25) >> 9;
> 
> If the variable state is OCV_MODE_SLEEP, the function measure_vbatt() is
> called with the argument &ocv, and the corresponding parameter is data.
> Thus *data is uninitialized but it is used at line 201.
> 
> I am not quite sure whether this possible uninitialized-variable access is
> real and how to fix it if it is real.
> Any feedback would be appreciated, thanks!
> 
> Reported-by: TOTE Robot <oslab@tsinghua.edu.cn>

I suppose the code is suppose to look like this:

201:        *data = ((ret & 0xff) * 27 * 25) >> 9;

Considering quite some code is spent before to setup ret, which is
never used. I don't have the device (nor datasheets) though. Considering
the driver has only seen trivial cleanups over the last 9 years, maybe
it can just be removed?

-- Sebastian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2021-08-05 17:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-28 10:24 [BUG] power: supply: 88pm860x_battery: possible uninitialized-variable access in measure_vbatt() Li Tuo
2021-08-05 17:49 ` Sebastian Reichel [this message]
2021-08-06  3:29   ` Tuo Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210805174908.ctg6n5iwmg5izap3@earth.universe \
    --to=sre@kernel.org \
    --cc=baijiaju1990@gmail.com \
    --cc=islituo@gmail.com \
    --cc=jtzhou@marvell.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.