lkml.org 
[lkml]   [2019]   [Mar]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] mfd: mc13xxx: i2c/spi Fix to avoid NULL pointer dereference
Date
of_match_device can return NULL if no matching device is found. The patches
avoids a scenario causing null pointer dereference.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
drivers/mfd/mc13xxx-i2c.c | 2 ++
drivers/mfd/mc13xxx-spi.c | 2 ++
2 files changed, 4 insertions(+)

diff --git a/drivers/mfd/mc13xxx-i2c.c b/drivers/mfd/mc13xxx-i2c.c
index 67e4c9aa7d18..1fbc9713bb9a 100644
--- a/drivers/mfd/mc13xxx-i2c.c
+++ b/drivers/mfd/mc13xxx-i2c.c
@@ -80,6 +80,8 @@ 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)
+ 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 ee3411cc5ce4..c044a02bdb64 100644
--- a/drivers/mfd/mc13xxx-spi.c
+++ b/drivers/mfd/mc13xxx-spi.c
@@ -158,6 +158,8 @@ 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)
+ return -ENODEV;

mc13xxx->variant = of_id->data;
} else {
--
2.17.1
\
 
 \ /
  Last update: 2019-03-19 00:16    [W:0.038 / U:0.172 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site