Linux MultiMedia Card development
 help / color / mirror / Atom feed
From: Maxime Ripard <maxime.ripard@free-electrons.com>
To: Ulf Hansson <ulf.hansson@linaro.org>
Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
	Maxime Ripard <maxime.ripard@free-electrons.com>
Subject: [PATCH] mmc: core: Check regulator pointer
Date: Tue, 18 Oct 2016 10:43:43 +0200	[thread overview]
Message-ID: <20161018084343.680-1-maxime.ripard@free-electrons.com> (raw)

mmc_regulator_get_supply might silently fail if the regulators are not
found, which is the right thing to do since both these regulators are
optional.

However, the drivers then have no way to know whether or not they should
proceed and call mmc_regulator_set_ocr. And since this function doesn't
check for the validity of the regulator pointer, it leads to a null pointer
dereference. Add such a check to make sure everything works fine.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 drivers/mmc/core/core.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 2553d903a82b..1d3ea5e1aa37 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -1474,6 +1474,12 @@ int mmc_regulator_set_ocr(struct mmc_host *mmc,
 	int			result = 0;
 	int			min_uV, max_uV;
 
+	if (!supply)
+		return -EINVAL;
+
+	if (IS_ERR(supply))
+		return PTR_ERR(supply);
+
 	if (vdd_bit) {
 		mmc_ocrbitnum_to_vdd(vdd_bit, &min_uV, &max_uV);
 
-- 
2.9.3


             reply	other threads:[~2016-10-18  8:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-18  8:43 Maxime Ripard [this message]
2016-10-18  8:55 ` [PATCH] mmc: core: Check regulator pointer Baolin Wang
2016-10-18  9:03 ` Ulf Hansson
2016-10-18  9:47   ` Maxime Ripard
2016-10-18 10:28     ` Ulf Hansson
2016-10-18 12:29     ` Shawn Lin

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=20161018084343.680-1-maxime.ripard@free-electrons.com \
    --to=maxime.ripard@free-electrons.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.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