From: Dan Carpenter <dan.carpenter@oracle.com>
To: Stefan Popa <stefan.popa@analog.com>
Cc: Sebastian Reichel <sre@kernel.org>,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-janitors@vger.kernel.org
Subject: [PATCH] power: supply: adp5061: Fix a couple off by ones
Date: Wed, 11 Jul 2018 10:58:13 +0300 [thread overview]
Message-ID: <20180711075808.gpa3362vbins7crx@kili.mountain> (raw)
We end up reading one element beyond the end of the adp5061_vmax[] array
here.
Fixes: fe8e81b7e899 ("adp5061: New driver for ADP5061 I2C battery charger")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
diff --git a/drivers/power/supply/adp5061.c b/drivers/power/supply/adp5061.c
index c00a02ef7424..939fd3d8fb1a 100644
--- a/drivers/power/supply/adp5061.c
+++ b/drivers/power/supply/adp5061.c
@@ -266,8 +266,8 @@ static int adp5061_get_max_voltage(struct adp5061_state *st,
return ret;
regval = ((regval & ADP5061_TERM_SET_VTRM_MSK) >> 2) - 0x0F;
- if (regval > ARRAY_SIZE(adp5061_vmax))
- regval = ARRAY_SIZE(adp5061_vmax);
+ if (regval >= ARRAY_SIZE(adp5061_vmax))
+ regval = ARRAY_SIZE(adp5061_vmax) - 1;
val->intval = adp5061_vmax[regval] * 1000;
@@ -344,8 +344,8 @@ static int adp5061_get_const_chg_current(struct adp5061_state *st,
return ret;
regval = ((regval & ADP5061_CHG_CURR_ICHG_MSK) >> 2);
- if (regval > ARRAY_SIZE(adp5061_const_ichg))
- regval = ARRAY_SIZE(adp5061_const_ichg);
+ if (regval >= ARRAY_SIZE(adp5061_const_ichg))
+ regval = ARRAY_SIZE(adp5061_const_ichg) - 1;
val->intval = adp5061_const_ichg[regval] * 1000;
next reply other threads:[~2018-07-11 7:58 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-11 7:58 Dan Carpenter [this message]
2018-07-11 10:04 ` [PATCH] power: supply: adp5061: Fix a couple off by ones Sebastian Reichel
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=20180711075808.gpa3362vbins7crx@kili.mountain \
--to=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=sre@kernel.org \
--cc=stefan.popa@analog.com \
/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 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).