The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Shailendra Verma <shailendra.v@samsung.com>
To: Lee Jones <lee.jones@linaro.org>,
	linux-kernel@vger.kernel.org, p.shailesh@samsung.com,
	ashish.kalra@samsung.com,
	Shailendra Verma <shailendra.v@samsung.com>,
	Shailendra Verma <shailendra.capricorn@gmail.com>
Subject: [PATCH] Mfd - Fix possible NULL derefrence.
Date: Fri, 27 Jan 2017 16:46:45 +0530	[thread overview]
Message-ID: <1485515805-3598-1-git-send-email-shailendra.v@samsung.com> (raw)
In-Reply-To: CGME20170127111654epcas1p34aa51a351ad04a35b68a1fc88438fc27@epcas1p3.samsung.com

of_match_device could return NULL, and so can cause a NULL
pointer dereference later.

Signed-off-by: Shailendra Verma <shailendra.v@samsung.com>
---
 drivers/mfd/mc13xxx-i2c.c |    4 ++++
 drivers/mfd/mc13xxx-spi.c |    5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/mfd/mc13xxx-i2c.c b/drivers/mfd/mc13xxx-i2c.c
index 67e4c9a..e03f454 100644
--- a/drivers/mfd/mc13xxx-i2c.c
+++ b/drivers/mfd/mc13xxx-i2c.c
@@ -80,6 +80,10 @@ static int mc13xxx_i2c_probe(struct i2c_client *client,
 	if (client->dev.of_node) {
 		const struct of_device_id *of_id =
 			of_match_device(mc13xxx_dt_ids, &client->dev);
+		if (!of_id) {
+			dev_err(&client->dev, "Error: No device match found\n");
+			return -ENODEV;
+		}
 		mc13xxx->variant = of_id->data;
 	} else {
 		mc13xxx->variant = (void *)id->driver_data;
diff --git a/drivers/mfd/mc13xxx-spi.c b/drivers/mfd/mc13xxx-spi.c
index cbc1e5e..97ab19c 100644
--- a/drivers/mfd/mc13xxx-spi.c
+++ b/drivers/mfd/mc13xxx-spi.c
@@ -157,7 +157,10 @@ static int mc13xxx_spi_probe(struct spi_device *spi)
 	if (spi->dev.of_node) {
 		const struct of_device_id *of_id =
 			of_match_device(mc13xxx_dt_ids, &spi->dev);
+		if (!of_id) {
+			dev_err(&spi->dev, "Error: No device match found\n");
+			return -ENODEV;
+		}
 		mc13xxx->variant = of_id->data;
 	} else {
 		const struct spi_device_id *id_entry = spi_get_device_id(spi);
-- 
1.7.9.5

       reply	other threads:[~2017-01-27 11:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20170127111654epcas1p34aa51a351ad04a35b68a1fc88438fc27@epcas1p3.samsung.com>
2017-01-27 11:16 ` Shailendra Verma [this message]
2017-02-07 11:51   ` [PATCH] Mfd - Fix possible NULL derefrence Andy Shevchenko
2017-02-07 16:32   ` Lee Jones

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=1485515805-3598-1-git-send-email-shailendra.v@samsung.com \
    --to=shailendra.v@samsung.com \
    --cc=ashish.kalra@samsung.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=p.shailesh@samsung.com \
    --cc=shailendra.capricorn@gmail.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