mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Axel Lin <axel.lin@ingics.com>
To: Lee Jones <lee.jones@linaro.org>
Cc: Stefan Agner <stefan@agner.ch>,
	Marcel Ziswiler <marcel.ziswiler@toradex.com>,
	Mark Brown <broonie@kernel.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	linux-kernel@vger.kernel.org, Axel Lin <axel.lin@ingics.com>
Subject: [PATCH RESEND] regulator: rn5t618: Fix out of bounds array access
Date: Sat, 15 Apr 2017 22:52:39 +0800	[thread overview]
Message-ID: <20170415145239.28880-1-axel.lin@ingics.com> (raw)

The commit "regulator: rn5t618: Add RN5T567 PMIC support" added
RN5T618_DCDC4 to the enum, then RN5T618_REG_NUM is also changed.
So for rn5t618, there is out of bounds array access when checking
regulators[i].name in the for loop.

The number of regulators is different for rn5t567 and rn5t618, so we had
better remove RN5T618_REG_NUM and get the correct num_regulators during
probe instead.

Fixes: ed6d362d8dbc ("regulator: rn5t618: Add RN5T567 PMIC support")
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
RESEND: Correct subject line (remove double Fix)

 drivers/regulator/rn5t618-regulator.c | 8 ++++----
 include/linux/mfd/rn5t618.h           | 1 -
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/regulator/rn5t618-regulator.c b/drivers/regulator/rn5t618-regulator.c
index 8d2819e..0c09143 100644
--- a/drivers/regulator/rn5t618-regulator.c
+++ b/drivers/regulator/rn5t618-regulator.c
@@ -85,14 +85,17 @@ static int rn5t618_regulator_probe(struct platform_device *pdev)
 	struct regulator_config config = { };
 	struct regulator_dev *rdev;
 	struct regulator_desc *regulators;
+	int num_regulators;
 	int i;
 
 	switch (rn5t618->variant) {
 	case RN5T567:
 		regulators = rn5t567_regulators;
+		num_regulators = ARRAY_SIZE(rn5t567_regulators);
 		break;
 	case RN5T618:
 		regulators = rn5t618_regulators;
+		num_regulators = ARRAY_SIZE(rn5t618_regulators);
 		break;
 	default:
 		return -EINVAL;
@@ -101,10 +104,7 @@ static int rn5t618_regulator_probe(struct platform_device *pdev)
 	config.dev = pdev->dev.parent;
 	config.regmap = rn5t618->regmap;
 
-	for (i = 0; i < RN5T618_REG_NUM; i++) {
-		if (!regulators[i].name)
-			continue;
-
+	for (i = 0; i < num_regulators; i++) {
 		rdev = devm_regulator_register(&pdev->dev,
 					       &regulators[i],
 					       &config);
diff --git a/include/linux/mfd/rn5t618.h b/include/linux/mfd/rn5t618.h
index e5a6cde..d7b3155 100644
--- a/include/linux/mfd/rn5t618.h
+++ b/include/linux/mfd/rn5t618.h
@@ -233,7 +233,6 @@ enum {
 	RN5T618_LDO5,
 	RN5T618_LDORTC1,
 	RN5T618_LDORTC2,
-	RN5T618_REG_NUM,
 };
 
 enum {
-- 
2.9.3

             reply	other threads:[~2017-04-15 14:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-15 14:52 Axel Lin [this message]
2017-04-15 16:53 ` Stefan Agner
2017-04-16  1:12   ` Axel Lin
2017-04-16  3:30     ` Axel Lin
2017-04-16  5:30     ` Stefan Agner

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=20170415145239.28880-1-axel.lin@ingics.com \
    --to=axel.lin@ingics.com \
    --cc=broonie@kernel.org \
    --cc=lee.jones@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcel.ziswiler@toradex.com \
    --cc=stefan@agner.ch \
    /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®