From: Axel Lin <axel.lin@ingics.com>
To: Mark Brown <broonie@kernel.org>
Cc: Matthias Kaehlcke <mka@chromium.org>,
Rob Herring <robh@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>,
linux-kernel@vger.kernel.org, Axel Lin <axel.lin@ingics.com>
Subject: [PATCH] regulator: vctrl: Fix out of bounds array access for vctrl->vtable
Date: Fri, 14 Apr 2017 10:50:43 +0800 [thread overview]
Message-ID: <20170414025043.13680-1-axel.lin@ingics.com> (raw)
Current code only allocates rdesc->n_voltages entries for vctrl->vtable.
Thus use rdesc->n_voltages instead of n_voltages in the for loop.
While at it, also switch to use devm_kcalloc instead of devm_kmalloc_array
+ __GFP_ZERO flag and fix the argument order.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
drivers/regulator/vctrl-regulator.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/vctrl-regulator.c b/drivers/regulator/vctrl-regulator.c
index 6baadef..78de002 100644
--- a/drivers/regulator/vctrl-regulator.c
+++ b/drivers/regulator/vctrl-regulator.c
@@ -345,9 +345,9 @@ static int vctrl_init_vtable(struct platform_device *pdev)
return -EINVAL;
}
- vctrl->vtable = devm_kmalloc_array(
- &pdev->dev, sizeof(struct vctrl_voltage_table),
- rdesc->n_voltages, GFP_KERNEL | __GFP_ZERO);
+ vctrl->vtable = devm_kcalloc(&pdev->dev, rdesc->n_voltages,
+ sizeof(struct vctrl_voltage_table),
+ GFP_KERNEL);
if (!vctrl->vtable)
return -ENOMEM;
@@ -371,7 +371,7 @@ static int vctrl_init_vtable(struct platform_device *pdev)
NULL);
/* pre-calculate OVP-safe downward transitions */
- for (i = n_voltages - 1; i > 0; i--) {
+ for (i = rdesc->n_voltages - 1; i > 0; i--) {
int j;
int ovp_min_uV = (vctrl->vtable[i].out *
(100 - vctrl->ovp_threshold)) / 100;
--
2.9.3
next reply other threads:[~2017-04-14 2:50 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-14 2:50 Axel Lin [this message]
2017-04-14 17:11 ` Matthias Kaehlcke
2017-04-14 19:01 ` Matthias Kaehlcke
2017-04-14 17:12 ` Applied "regulator: vctrl: Fix out of bounds array access for vctrl->vtable" to the regulator tree Mark Brown
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=20170414025043.13680-1-axel.lin@ingics.com \
--to=axel.lin@ingics.com \
--cc=broonie@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mka@chromium.org \
--cc=robh@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®